diff --git a/src/cli/commands/login.command.ts b/src/cli/commands/login.command.ts index 396e37d2f2..0f58cb361b 100644 --- a/src/cli/commands/login.command.ts +++ b/src/cli/commands/login.command.ts @@ -262,7 +262,7 @@ export class LoginCommand { const code = url.searchParams.get('code'); const receivedState = url.searchParams.get('state'); res.setHeader('Content-Type', 'text/html'); - if (code != null && receivedState != null && receivedState === state) { + if (code != null && receivedState != null && this.checkState(receivedState, state)) { res.writeHead(200); res.end('Success | Bitwarden CLI' + '

Successfully authenticated with the Bitwarden CLI

' + @@ -300,4 +300,17 @@ export class LoginCommand { } }); } + + private checkState(state: string, checkState: string): boolean { + if (state === null || state === undefined) { + return false; + } + if (checkState === null || checkState === undefined) { + return false; + } + + const stateSplit = state.split('_identifier='); + const checkStateSplit = checkState.split('_identifier='); + return stateSplit[0] === checkStateSplit[0]; + } }