bitwarden / clients

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

Problems with CLI during scripted bulk operations #2735

Open schretzi opened 3 years ago

schretzi commented 3 years ago

Describe the Bug

CLI operations fail if some are made one after the other. Suddenly an operation in a sequence fails with "Your are not logged in." and all subsequent operations will fail too, as the cache is file is corrupt and all login/session information is lost.

This happens against the Cloud Service as well against the on-premise installation.

Steps To Reproduce

A simple loop can reproduce this issue:

for NUM in $(seq 1 70); 
do 
    echo -n "${NUM} - "; date; 
    bw get template item | jq ".type = 2 | .name=\"TestBitwarden - 2109 - #${NUM}\" | .notes=\"${NUM}\" | .secureNote=$(bw get template item.securenote) " | bw encode | bw create item;
done

Expected Result

All 70 entries should be sucessfully written on the bitwarden server and session should be still active

Actual Result

After a random amount of entries I receive a "Your are not logged in" error and session is closed. 7 sucessfull entries was the result of this run, it changes with each try but out of ~15-20 tests I never got all 70 sucessfull.

Screenshots or Videos

1 - Tue Sep 21 16:17:22 CEST 2021
{"object":"item","id":"e259b2ed-f33f-4fac-a06f-adaa00eb7df5","organizationId":null,"folderId":null,"type":2,"reprompt":0,"name":"TestBitwarden - 2109 - bitwarden/cli#1","notes":"1","favorite":false,"secureNote":{"type":0},"revisionDate":"2021-09-21T14:17:24.012Z"}
2 - Tue Sep 21 16:17:28 CEST 2021
{"object":"item","id":"3b03f8e8-5824-4993-85a5-adaa00eb84f1","organizationId":null,"folderId":null,"type":2,"reprompt":0,"name":"TestBitwarden - 2109 - bitwarden/cli#2","notes":"2","favorite":false,"secureNote":{"type":0},"revisionDate":"2021-09-21T14:17:29.973Z"}
3 - Tue Sep 21 16:17:34 CEST 2021
{"object":"item","id":"372143ff-8bcf-41d6-bc91-adaa00eb8c23","organizationId":null,"folderId":null,"type":2,"reprompt":0,"name":"TestBitwarden - 2109 - bitwarden/cli#3","notes":"3","favorite":false,"secureNote":{"type":0},"revisionDate":"2021-09-21T14:17:36.111Z"}
4 - Tue Sep 21 16:17:40 CEST 2021
{"object":"item","id":"8a1c9e64-2ed6-4c01-a731-adaa00eb9309","organizationId":null,"folderId":null,"type":2,"reprompt":0,"name":"TestBitwarden - 2109 - bitwarden/cli#4","notes":"4","favorite":false,"secureNote":{"type":0},"revisionDate":"2021-09-21T14:17:41.998Z"}
5 - Tue Sep 21 16:17:46 CEST 2021
{"object":"item","id":"3f9920ec-d2f3-48d9-a370-adaa00eb99e4","organizationId":null,"folderId":null,"type":2,"reprompt":0,"name":"TestBitwarden - 2109 - bitwarden/cli#5","notes":"5","favorite":false,"secureNote":{"type":0},"revisionDate":"2021-09-21T14:17:47.848Z"}
6 - Tue Sep 21 16:17:52 CEST 2021
{"object":"item","id":"a6cf08b6-7886-4e87-9dd1-adaa00eba0b8","organizationId":null,"folderId":null,"type":2,"reprompt":0,"name":"TestBitwarden - 2109 - bitwarden/cli#6","notes":"6","favorite":false,"secureNote":{"type":0},"revisionDate":"2021-09-21T14:17:53.676Z"}
7 - Tue Sep 21 16:17:58 CEST 2021
{"object":"item","id":"32972684-55d6-4d22-a077-adaa00eba78f","organizationId":null,"folderId":null,"type":2,"reprompt":0,"name":"TestBitwarden - 2109 - bitwarden/cli#7","notes":"7","favorite":false,"secureNote":{"type":0},"revisionDate":"2021-09-21T14:17:59.512Z"}
8 - Tue Sep 21 16:18:04 CEST 2021
You are not logged in.
You are not logged in.
jq: error: syntax error, unexpected $end (Unix shell quoting issues?) at <top-level>, line 1:
.type = 2 | .name="TestBitwarden - 2109 - bitwarden/cli#8" | .notes="8" | .secureNote=
jq: 1 compile error
`requestJson` was not provided.
9 - Tue Sep 21 16:18:09 CEST 2021
You are not logged in.
You are not logged in.
You are not logged in.
jq: error: syntax error, unexpected $end (Unix shell quoting issues?) at <top-level>, line 1:
.type = 2 | .name="TestBitwarden - 2109 - bitwarden/cli#9" | .notes="9" | .secureNote=
jq: 1 compile error
10 - Tue Sep 21 16:18:15 CEST 2021
You are not logged in.
You are not logged in.
You are not logged in.

Environment

Additional Context

sso-bitwarden commented 3 years ago

I'm unable to reproduce this using CLI v1.16.0 All 70 entries are created on cloud and self-hosted version.

camelstrike commented 3 years ago

Im having the same issue using bw login --apikey

After it fails the data.json file is resetted only showing:

{ "installedVersion": "1.18.0" }

camelstrike commented 3 years ago

@sso-bitwarden @schretzi confirmed working with 1.16.0

sudo npm install -g @bitwarden/cli@1.16.0

schretzi commented 3 years ago

Thx for your test and results, based on your results I did some more tests. First, until now I only tested the "binary" version, as I don't have nodejs on my servers. Now I did additionally also test the npm version.

1.16.0 - All good, multiple runs in both the npm and binary version are ok 1.17.0 - Fails as binary, I get an error during npm installation (which I have no experience how to fix) 1.17.1 - Fails as npm 1.18.0 - Fails both npm and binary

But I got more detailed errors :

1.17.0 - binary version: Error creating lowdb storage adapter, "Malformed JSON in file: /home/schretzi/.config/Bitwarden CLI/data.json Unexpected end of JSON input"; emptying data file. Writing backup of data file to /home/schretzi/.config/Bitwarden CLI/data.json.bak

1.18.0 - npm version: 19 - Wed Sep 22 19:27:35 CEST 2021 You are not logged in. (node:6906) UnhandledPromiseRejectionWarning: Error: write EPIPE at afterWriteDispatched (internal/stream_base_commons.js:78:25) at writeGeneric (internal/stream_base_commons.js:73:3) at Socket._writeGeneric (net.js:714:5) at Socket._write (net.js:726:8) at doWrite (_stream_writable.js:415:12) at writeOrBuffer (_stream_writable.js:399:5) at Socket.Writable.write (_stream_writable.js:299:11) at program_Program.writeLn (/usr/local/lib/node_modules/@bitwarden/cli/build/bw.js:26655:20) at program_Program.processResponse (/usr/local/lib/node_modules/@bitwarden/cli/build/bw.js:27905:22) at program_Program.processResponse (/usr/local/lib/node_modules/@bitwarden/cli/build/bw.js:28320:15) (node:6906) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:6906) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 20 - Wed Sep 22 19:27:37 CEST 2021 You are not logged in.

Azzi2k commented 3 years ago

We have exactly the same problem. It occurs when you were already logged in (unlock vault with password bw unlock $password --raw), log in again (bw login $user $password) or use an existing session (BW_SESSION). As with the others, the data.json is then reset in the event of an error.

bitwarden-bot commented 2 years ago

Hi schretzi, We're cleaning up our repositories in preparation for a major reorganization. Issues from last year will be marked as stale and closed after two weeks. If you still need help, comment to let us know and we'll look into it. Thanks!

markuslf commented 2 years ago

This is still an issue.

kschat commented 2 years ago

This is not stale, I'm still running into this issue on v1.22.1.

tstackhouse commented 2 years ago

I was running into this under linux with 1.18.0, upgrading to 2022.9.0 seemed to fix it, though I'm not sure what I think about the massive change in the versioning scheme, I have no clue how far behind I was, but that's a whole separate conversation :D