Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-4280] MP reprompt not respected on passkey creation and retrieval #6550

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions apps/browser/src/vault/popup/components/fido2/fido2.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,35 +220,28 @@
async submit() {
const data = this.message$.value;
if (data?.type === "PickCredentialRequest") {
let userVerified = false;
if (data.userVerification) {
userVerified = await this.passwordRepromptService.showPasswordPrompt();
}
const userVerified = await this.handleUserVerification(data.userVerification, this.cipher);

this.send({
sessionId: this.sessionId,
cipherId: this.cipher.id,
type: "PickCredentialResponse",
userVerified,
});
} else if (data?.type === "ConfirmNewCredentialRequest") {
let userVerified = false;

if (this.cipher.login.hasFido2Credentials) {
const confirmed = await this.dialogService.openSimpleDialog({
title: { key: "overwritePasskey" },
content: { key: "overwritePasskeyAlert" },
type: "info",
});

if (!confirmed) {
return false;
}
}

if (data.userVerification) {
userVerified = await this.passwordRepromptService.showPasswordPrompt();
}
const userVerified = await this.handleUserVerification(data.userVerification, this.cipher);

Check notice on line 244 in apps/browser/src/vault/popup/components/fido2/fido2.component.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (EC-598-beeep-properly-store-passkeys-in-bitwarden)

✅ No longer an issue: Complex Method

Fido2Component.submit is no longer above the threshold for cyclomatic complexity. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check notice on line 244 in apps/browser/src/vault/popup/components/fido2/fido2.component.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (EC-598-beeep-properly-store-passkeys-in-bitwarden)

✅ No longer an issue: Bumpy Road Ahead

Fido2Component.submit is no longer above the threshold for logical blocks with deeply nested code

this.send({
sessionId: this.sessionId,
Expand Down Expand Up @@ -411,6 +404,20 @@
}
}

private async handleUserVerification(
userVerification: boolean,
cipher: CipherView
): Promise<boolean> {
const masterPasswordRepromptRequiered = cipher && cipher.reprompt !== 0;
const verificationRequired = userVerification || masterPasswordRepromptRequiered;

if (!verificationRequired) {
return false;
}

return await this.passwordRepromptService.showPasswordPrompt();
}

private send(msg: BrowserFido2Message) {
BrowserFido2UserInterfaceSession.sendMessage({
sessionId: this.sessionId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LogService } from "../../../platform/abstractions/log.service";

Check notice on line 1 in libs/common/src/vault/services/fido2/fido2-authenticator.service.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (EC-598-beeep-properly-store-passkeys-in-bitwarden)

ℹ Getting worse: Overall Code Complexity

The mean cyclomatic complexity increases from 7.09 to 7.82, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
import { Utils } from "../../../platform/misc/utils";
import { CipherService } from "../../abstractions/cipher.service";
import {
Expand Down Expand Up @@ -136,6 +136,14 @@
cipher = await encrypted.decrypt(
await this.cipherService.getKeyForCipherKeyDecryption(encrypted)
);

if (cipher.reprompt !== 0 && !userVerified) {
coroiu marked this conversation as resolved.
Show resolved Hide resolved
this.logService?.warning(
`[Fido2Authenticator] Aborting because user verification was unsuccessful.`
);
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.NotAllowed);
}

Check warning on line 146 in libs/common/src/vault/services/fido2/fido2-authenticator.service.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (EC-598-beeep-properly-store-passkeys-in-bitwarden)

❌ Getting worse: Complex Method

Fido2AuthenticatorService.makeCredential increases in cyclomatic complexity from 25 to 29, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
coroiu marked this conversation as resolved.
Show resolved Hide resolved
coroiu marked this conversation as resolved.
Show resolved Hide resolved
fido2Credential = await createKeyView(params, keyPair.privateKey);
cipher.login.fido2Credentials = [fido2Credential];
const reencrypted = await this.cipherService.encrypt(cipher);
Expand Down Expand Up @@ -242,6 +250,13 @@
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.NotAllowed);
}

if (selectedCipher.reprompt !== 0 && !userVerified) {
this.logService?.warning(
`[Fido2Authenticator] Aborting because user verification was unsuccessful.`
);
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.NotAllowed);
}

Check warning on line 259 in libs/common/src/vault/services/fido2/fido2-authenticator.service.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (EC-598-beeep-properly-store-passkeys-in-bitwarden)

❌ Getting worse: Complex Method

Fido2AuthenticatorService.getAssertion increases in cyclomatic complexity from 20 to 24, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
try {
const selectedFido2Credential = selectedCipher.login.fido2Credentials[0];
const selectedCredentialId = selectedFido2Credential.credentialId;
Expand Down
Loading