1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

Auth/PM-10684 - Fix CLI asking for MP even if session key provided as command option (#10917)

* PM-10684 - ServiceContainer - Add better docs

* PM-10684 - UserAutoUnlockKeyService - setUserKeyInMemoryIfAutoUserKeySet - refactor method to return a bool instead of nothing so users can know if a user key was retrieved & set without another call.

* PM-10684 - Remove async code ( Program.ts) responsible for setting the auto user key from the session option handler (event emitter which fires when a user passes --session <sessionKey> to a command). Returning this to synchronous execution prevents a race condition between the setting of the user key and the command executing the exitIfLocked logic in the base-program which would check if the user key had been set to determine if the command should be allowed to execute or if the user was locked. When running a loop from a script, the command would often trigger the exitIfLocked before the auto user key could be set in state from the option:session session.

* PM-10684 - Clean up missed item per PR feedback
This commit is contained in:
Jared Snider
2024-09-09 10:03:30 -04:00
committed by GitHub
parent 60e9969017
commit e954621761
4 changed files with 58 additions and 44 deletions

View File

@@ -803,6 +803,10 @@ export class ServiceContainer {
await this.i18nService.init();
this.twoFactorService.init();
// If a user has a BW_SESSION key stored in their env (not process.env.BW_SESSION),
// this should set the user key to unlock the vault on init.
// TODO: ideally, we wouldn't want to do this here but instead only for commands that require the vault to be unlocked
// as this runs on every command and could be a performance hit
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
if (activeAccount?.id) {
await this.userAutoUnlockKeyService.setUserKeyInMemoryIfAutoUserKeySet(activeAccount.id);