bitwarden / clients

Bitwarden client apps (web, browser extension, desktop, and cli).
https://bitwarden.com
Other
9k stars 1.18k forks source link

data.json doesn't populate upon login #2733

Open anonymous1184 opened 2 years ago

anonymous1184 commented 2 years ago

Describe the Bug

Upon successful login data.json only holds 2 entries.

Steps To Reproduce

  1. Delete data.json
  2. Issue any command to create it
  3. Login

Expected Result

data.json with all the pertinent information.

Actual Result

A quasi-empty data.json file:

{
  "installedVersion": "1.18.1",
  "appId": "a97ae1ad-6f86-4f3d-ac8e-37a3db9ac3dc"
}

Screenshots or Videos

I only set my password in the BW_PASSWORD environment variable and issued a cls command to remove it from screen.

20211009135803

Environment

Additional Context

Of course that when passing the session in any way any command that requires it fails.

MGibson1 commented 2 years ago

I believe this to be related to https://github.com/bitwarden/directory-connector/issues/41.

The fix should be extracting that fix into jslib so we can use it in CLI as well.

anonymous1184 commented 2 years ago

Right now I don't recall what were the steps, but at some point I also had just the installedVersion property. I can try and find a way to replicate if that helps.

MGibson1 commented 2 years ago

That might help confirm my suspicions, yes. If I'm right the recreation should have to do with multiple simultaneous access to data.json. Perhaps multiple CLI instances running?

anonymous1184 commented 2 years ago

I'm 100% sure no multiple instances running, the issue is easily reproducible by doing what I did in the screenshot which is literally just a login.

And here's how to reproduce the single property output I had at some point:

d:
md test
cd .\test\
Invoke-WebRequest -Uri https://github.com/bitwarden/cli/releases/download/v1.18.1/bw-windows-1.18.1.zip -OutFile bw.zip
Expand-Archive -Path .\bw.zip -DestinationPath .\
$env:BITWARDENCLI_APPDATA_DIR=".\"
.\bw.exe status
Get-Content -Path .\data.json

20211013160736

Now that one I didn't see it as an issue, but I remembered that at some point I saw only a single property in the JSON, and that is because I first check the existence of data.json and if is not there I create it (to avoid the Could not find data file, "data.json"; creating it instead. output), then I issue a bw status to grab the status and continue from there...

Anyway, the login is always successful (if proper credentials) but the data.json only contains two properties:

{
  "installedVersion": "1.18.1",
  "appId": "a97ae1ad-6f86-4f3d-ac8e-37a3db9ac3dc"
}

This screenshot is complementary to the one above to showcase the actual issue:

20211013164003

anonymous1184 commented 2 years ago

Hi @MGibson1!

This issue is little over 5 months and is still present in the current version 1.21.0 which closed this ticket (can you re-open it?).

Versions 1.19.0, 1.19.1 and 1.21.0 behave similar as the data.json has only empty/null values (latest has more fields in the JSON). In other words it doesn't contain the encrypted data.

The version 1.20.0 is a bit different as it always returns Token not found which is a bit worse as it doesn't let me log in.

Prior versions have different issues, for example version 1.17.1, 1.16.0, 1.15.1, returns:

{"response":{"error":"invalid_grant","error_description":"Auth-Email header invalid."},"statusCode":400}

And versions 1.14.0 and prior:

[object Object]

Now I'm pretty sure I'm using the proper username, password and TOTP codes as I'm pasting. For TOTP I wait until between seconds 10 to 20 and 40 to 50; that is after clock was synchronized. Turning off TOTP is not an option, I also tried a couple of times the Email code and the result is the same.

If you need any specific testing let me know, I can do it manually or script it if needed.

anonymous1184 commented 2 years ago

Same story with v1.21.1

20220214162910

MGibson1 commented 2 years ago

Strange. Using a file lock has fixed this problem in the past.

I see in your latest screenshot, when you log in it says Could not find data file, "D:\test\data.json"; creating it instead did you delete that file intentionally prior to running your login command?

anonymous1184 commented 2 years ago

That was because I used an empty directory, but is the same if:

20220216102833

realslacker commented 2 years ago

I am having a very similar issue running 1.22.1. My data.json contains folders and organizations, but no ciphers, sends, or collections even though I have all of those in my vault. Also on the linked bug from the old CLI repo it seemed to be suggested that the problem was with using an api key, however I login with username and password.

I have tried removing the data.json to regenerate it, but the problem persists.

anonymous1184 commented 2 years ago

Like you can tell for the images I use user/password and 2FA... same story. I also tried using environment variables and the issue remains, I know is not just my PC as I've tested in 5 different installations (W7, W10, W11 PowerShell/cmd).

The issue remain, latest version always says incorrect user/password even if I have scripted the whole testing scenario. So pretty much sure I'm not making any mistakes.