mirror of
https://github.com/bitwarden/browser
synced 2026-01-30 00:03:30 +00:00
Apply lints
This commit is contained in:
@@ -138,7 +138,10 @@ export class Fido2CreateComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
const username = await this.session.getUserName();
|
||||
const isConfirmed = await this.session.promptForUserVerification(username, "Verify it's you to create a new credential")
|
||||
const isConfirmed = await this.session.promptForUserVerification(
|
||||
username,
|
||||
"Verify it's you to create a new credential",
|
||||
);
|
||||
this.session.notifyConfirmCreateCredential(isConfirmed);
|
||||
} catch {
|
||||
await this.showErrorDialog(this.DIALOG_MESSAGES.unableToSavePasskey);
|
||||
@@ -213,8 +216,11 @@ export class Fido2CreateComponent implements OnInit, OnDestroy {
|
||||
return this.passwordRepromptService.showPasswordPrompt();
|
||||
}
|
||||
|
||||
const username = cipher.login.username ?? cipher.name
|
||||
return this.session.promptForUserVerification(username, "Verify it's you to overwrite a credential")
|
||||
const username = cipher.login.username ?? cipher.name;
|
||||
return this.session.promptForUserVerification(
|
||||
username,
|
||||
"Verify it's you to overwrite a credential",
|
||||
);
|
||||
}
|
||||
|
||||
private async showErrorDialog(config: SimpleDialogOptions): Promise<void> {
|
||||
|
||||
@@ -18,7 +18,10 @@ import { AccountService } from "@bitwarden/common/auth/abstractions/account.serv
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import { CipherRepromptType } from "@bitwarden/common/vault/enums";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
import {
|
||||
CipherViewLike,
|
||||
CipherViewLikeUtils,
|
||||
} from "@bitwarden/common/vault/utils/cipher-view-like-utils";
|
||||
import {
|
||||
BadgeModule,
|
||||
ButtonModule,
|
||||
@@ -38,7 +41,6 @@ import {
|
||||
DesktopFido2UserInterfaceService,
|
||||
DesktopFido2UserInterfaceSession,
|
||||
} from "../../services/desktop-fido2-user-interface.service";
|
||||
import { CipherViewLike, CipherViewLikeUtils } from "@bitwarden/common/vault/utils/cipher-view-like-utils";
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
@@ -153,7 +155,7 @@ export class Fido2VaultComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
getSubtitle(cipher: CipherViewLike): string | undefined {
|
||||
return CipherViewLikeUtils.subtitle(cipher)
|
||||
return CipherViewLikeUtils.subtitle(cipher);
|
||||
}
|
||||
|
||||
private async validateCipherAccess(cipher: CipherViewLike): Promise<boolean> {
|
||||
|
||||
@@ -228,7 +228,9 @@ export class DesktopAutofillService implements OnDestroy {
|
||||
this.inFlightRequests[request.context] = controller;
|
||||
}
|
||||
|
||||
const clientHandle = request.clientWindowHandle ? new Uint8Array(request.clientWindowHandle) : null;
|
||||
const clientHandle = request.clientWindowHandle
|
||||
? new Uint8Array(request.clientWindowHandle)
|
||||
: null;
|
||||
try {
|
||||
const response = await this.fido2AuthenticatorService.makeCredential(
|
||||
this.convertRegistrationRequest(request),
|
||||
@@ -270,7 +272,9 @@ export class DesktopAutofillService implements OnDestroy {
|
||||
this.inFlightRequests[request.context] = controller;
|
||||
}
|
||||
|
||||
const clientHandle = request.clientWindowHandle ? new Uint8Array(request.clientWindowHandle) : null;
|
||||
const clientHandle = request.clientWindowHandle
|
||||
? new Uint8Array(request.clientWindowHandle)
|
||||
: null;
|
||||
|
||||
try {
|
||||
// For some reason the credentialId is passed as an empty array in the request, so we need to
|
||||
@@ -342,7 +346,9 @@ export class DesktopAutofillService implements OnDestroy {
|
||||
this.inFlightRequests[request.context] = controller;
|
||||
}
|
||||
|
||||
const clientHandle = request.clientWindowHandle ? new Uint8Array(request.clientWindowHandle) : null;
|
||||
const clientHandle = request.clientWindowHandle
|
||||
? new Uint8Array(request.clientWindowHandle)
|
||||
: null;
|
||||
try {
|
||||
const response = await this.fido2AuthenticatorService.getAssertion(
|
||||
this.convertAssertionRequest(request),
|
||||
@@ -375,13 +381,12 @@ export class DesktopAutofillService implements OnDestroy {
|
||||
// perform ad-hoc sync
|
||||
await this.adHocSync();
|
||||
} else if (status.key === "cancel-operation" && status.value) {
|
||||
const requestId = status.value
|
||||
const controller = this.inFlightRequests[requestId]
|
||||
const requestId = status.value;
|
||||
const controller = this.inFlightRequests[requestId];
|
||||
if (controller) {
|
||||
this.logService.debug(`Cancelling request ${requestId}`);
|
||||
controller.abort("Operation cancelled")
|
||||
}
|
||||
else {
|
||||
controller.abort("Operation cancelled");
|
||||
} else {
|
||||
this.logService.debug(`Unknown request: ${requestId}`);
|
||||
}
|
||||
}
|
||||
@@ -400,8 +405,8 @@ export class DesktopAutofillService implements OnDestroy {
|
||||
const handle = Utils.fromBufferToB64(windowDetails.handle);
|
||||
const response = { ...windowDetails, handle };
|
||||
this.logService.debug("listenGetWindowHandle: sending", response);
|
||||
callback(null, response)
|
||||
})
|
||||
callback(null, response);
|
||||
});
|
||||
|
||||
ipc.autofill.listenerReady();
|
||||
}
|
||||
@@ -461,10 +466,9 @@ export class DesktopAutofillService implements OnDestroy {
|
||||
| autofill.PasskeyAssertionRequest
|
||||
| autofill.PasskeyAssertionWithoutUserInterfaceRequest,
|
||||
options?: {
|
||||
assumeUserPresence?: boolean,
|
||||
isSilent?: boolean,
|
||||
}
|
||||
|
||||
assumeUserPresence?: boolean;
|
||||
isSilent?: boolean;
|
||||
},
|
||||
): Fido2AuthenticatorGetAssertionParams {
|
||||
const { assumeUserPresence, isSilent } = options ?? {};
|
||||
let allowedCredentials;
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
Fido2UserInterfaceSession,
|
||||
NewCredentialParams,
|
||||
PickCredentialParams,
|
||||
UserInteractionRequired,
|
||||
UserInteractionRequired,
|
||||
} from "@bitwarden/common/platform/abstractions/fido2/fido2-user-interface.service.abstraction";
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||
@@ -32,10 +32,10 @@ import { IdentityView } from "@bitwarden/common/vault/models/view/identity.view"
|
||||
import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view";
|
||||
import { LoginView } from "@bitwarden/common/vault/models/view/login.view";
|
||||
import { SecureNoteView } from "@bitwarden/common/vault/models/view/secure-note.view";
|
||||
import { CipherViewLikeUtils } from "@bitwarden/common/vault/utils/cipher-view-like-utils";
|
||||
|
||||
import { NativeAutofillUserVerificationCommand } from "../../platform/main/autofill/user-verification.command";
|
||||
import { DesktopSettingsService } from "../../platform/services/desktop-settings.service";
|
||||
import { CipherViewLikeUtils } from "@bitwarden/common/vault/utils/cipher-view-like-utils";
|
||||
|
||||
/**
|
||||
* This type is used to pass the window position from the native UI
|
||||
@@ -155,21 +155,28 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi
|
||||
if (!activeUserId) {
|
||||
return;
|
||||
}
|
||||
const cipherView = await firstValueFrom(this.cipherService.cipherListViews$(activeUserId).pipe(map((ciphers) => {
|
||||
return ciphers.find((cipher) => cipher.id == selectedCipherId && !cipher.deletedDate);
|
||||
})));
|
||||
const cipherView = await firstValueFrom(
|
||||
this.cipherService.cipherListViews$(activeUserId).pipe(
|
||||
map((ciphers) => {
|
||||
return ciphers.find(
|
||||
(cipher) => cipher.id == selectedCipherId && !cipher.deletedDate,
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
const username = CipherViewLikeUtils.getLogin(cipherView).username ?? cipherView.name
|
||||
const username = CipherViewLikeUtils.getLogin(cipherView).username ?? cipherView.name;
|
||||
try {
|
||||
// TODO: internationalization
|
||||
const isConfirmed = await this.promptForUserVerification(username, "Verify it's you to log in with Bitwarden.");
|
||||
const isConfirmed = await this.promptForUserVerification(
|
||||
username,
|
||||
"Verify it's you to log in with Bitwarden.",
|
||||
);
|
||||
return { cipherId: cipherIds[0], userVerified: isConfirmed };
|
||||
} catch (e) {
|
||||
this.logService.debug("Failed to prompt for user verification without showing UI", e);
|
||||
}
|
||||
catch (e) {
|
||||
this.logService.debug("Failed to prompt for user verification without showing UI", e)
|
||||
}
|
||||
}
|
||||
else if (assumeUserPresence) {
|
||||
} else if (assumeUserPresence) {
|
||||
this.logService.warning(
|
||||
"shortcut - Assuming user presence and returning cipherId",
|
||||
cipherIds[0],
|
||||
@@ -180,9 +187,8 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi
|
||||
|
||||
if (isSilent) {
|
||||
this.logService.info("Could not fulfill request silently, aborting request");
|
||||
throw new UserInteractionRequired()
|
||||
}
|
||||
else {
|
||||
throw new UserInteractionRequired();
|
||||
} else {
|
||||
this.logService.debug("Could not shortcut, showing UI");
|
||||
}
|
||||
|
||||
@@ -231,8 +237,7 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi
|
||||
// If we hit a timeout or if the request is cancelled, return undefined instead of throwing
|
||||
if (e.name === "AbortError") {
|
||||
this.logService.warning("Request was cancelled before the user selected a cipher");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.logService.warning("Timeout: User did not select a cipher within the allowed time", {
|
||||
timeoutMs,
|
||||
});
|
||||
@@ -264,12 +269,11 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi
|
||||
this.abortController.signal.throwIfAborted();
|
||||
const confirmPromise = lastValueFrom(this.confirmCredentialSubject);
|
||||
return await Promise.race([confirmPromise, cancelPromise]);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// If the request is cancelled, return undefined instead of throwing
|
||||
this.logService.warning("Request was cancelled before the user confirmed the cipher");
|
||||
return undefined;
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
this.unsusbscribeCancellation(abortFn);
|
||||
}
|
||||
}
|
||||
@@ -405,23 +409,28 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi
|
||||
|
||||
/** Called by the UI to prompt the user for verification. May be fulfilled by the OS. */
|
||||
async promptForUserVerification(username: string, displayHint: string): Promise<boolean> {
|
||||
this.logService.info("DesktopFido2UserInterfaceSession] Prompting for user verification")
|
||||
this.logService.info("DesktopFido2UserInterfaceSession] Prompting for user verification");
|
||||
// If the UI was showing before (to unlock the vault), then use our
|
||||
// window for the handle; otherwise, use the WebAuthn client's
|
||||
// handle.
|
||||
//
|
||||
//
|
||||
// For Windows, if the selected window handle is not in the foreground, then the Windows
|
||||
// Hello dialog will also be in the background.
|
||||
const windowDetails = await ipc.platform.getNativeWindowDetails();
|
||||
this.logService.debug("Window details:", windowDetails);
|
||||
let windowHandle;
|
||||
if (windowDetails.isVisible && windowDetails.isFocused) {
|
||||
windowHandle = windowDetails.handle
|
||||
this.logService.debug("Window is visible, setting Electron window as parent of Windows Hello UV dialog", windowHandle.buffer)
|
||||
}
|
||||
else {
|
||||
windowHandle = windowDetails.handle;
|
||||
this.logService.debug(
|
||||
"Window is visible, setting Electron window as parent of Windows Hello UV dialog",
|
||||
windowHandle.buffer,
|
||||
);
|
||||
} else {
|
||||
windowHandle = this.windowObject.handle;
|
||||
this.logService.debug("Window is not visible: setting client window as parent of Windows Hello UV dialog", windowHandle.buffer)
|
||||
this.logService.debug(
|
||||
"Window is not visible: setting client window as parent of Windows Hello UV dialog",
|
||||
windowHandle.buffer,
|
||||
);
|
||||
}
|
||||
|
||||
this.logService.debug("Prompting for user verification");
|
||||
@@ -498,18 +507,18 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi
|
||||
|
||||
/** Returns a promise that will be rejected if the session's abort signal is fired. */
|
||||
subscribeToCancellation() {
|
||||
let cancelReject: (reason?: any) => void;
|
||||
const cancelPromise: Promise<never> = new Promise((_, reject) => {
|
||||
cancelReject = reject
|
||||
});
|
||||
const abortFn = (ev: Event) => {
|
||||
if (ev.target instanceof AbortSignal) {
|
||||
cancelReject(ev.target.reason)
|
||||
}
|
||||
};
|
||||
this.abortController.signal.addEventListener("abort", abortFn, { once: true });
|
||||
let cancelReject: (reason?: any) => void;
|
||||
const cancelPromise: Promise<never> = new Promise((_, reject) => {
|
||||
cancelReject = reject;
|
||||
});
|
||||
const abortFn = (ev: Event) => {
|
||||
if (ev.target instanceof AbortSignal) {
|
||||
cancelReject(ev.target.reason);
|
||||
}
|
||||
};
|
||||
this.abortController.signal.addEventListener("abort", abortFn, { once: true });
|
||||
|
||||
return { promise: cancelPromise, listener: abortFn };
|
||||
return { promise: cancelPromise, listener: abortFn };
|
||||
}
|
||||
|
||||
/** Cleans up event listeners for cancellation */
|
||||
|
||||
@@ -558,8 +558,8 @@ export class WindowMain {
|
||||
}
|
||||
|
||||
export type WindowDetails = {
|
||||
isVisible: boolean,
|
||||
isFocused: boolean,
|
||||
isVisible: boolean;
|
||||
isFocused: boolean;
|
||||
// Base64-encoded native handle
|
||||
handle: Buffer,
|
||||
}
|
||||
handle: Buffer;
|
||||
};
|
||||
|
||||
@@ -21,4 +21,7 @@ export type IpcCommandInvoker<C extends CommandDefinition> = (
|
||||
) => Promise<CommandOutput<C["output"]>>;
|
||||
|
||||
/** A list of all available commands */
|
||||
export type Command = NativeAutofillSyncCommand | NativeAutofillStatusCommand | NativeAutofillUserVerificationCommand;
|
||||
export type Command =
|
||||
| NativeAutofillSyncCommand
|
||||
| NativeAutofillStatusCommand
|
||||
| NativeAutofillUserVerificationCommand;
|
||||
|
||||
@@ -15,5 +15,4 @@ export type NativeAutofillUserVerificationParams = {
|
||||
username: string;
|
||||
};
|
||||
|
||||
|
||||
export type NativeAutofillUserVerificationResult = CommandOutput<{}>;
|
||||
export type NativeAutofillUserVerificationResult = CommandOutput<void>;
|
||||
|
||||
@@ -5,7 +5,6 @@ import { EncString } from "@bitwarden/common/key-management/crypto/models/enc-st
|
||||
import { ThemeType, LogLevelType } from "@bitwarden/common/platform/enums";
|
||||
|
||||
import { WindowDetails } from "../main/window.main";
|
||||
|
||||
import {
|
||||
EncryptedMessageResponse,
|
||||
LegacyMessageWrapper,
|
||||
@@ -147,9 +146,9 @@ export default {
|
||||
log: (level: LogLevelType, message?: any, ...optionalParams: any[]) =>
|
||||
ipcRenderer.invoke("ipc.log", { level, message, optionalParams }),
|
||||
getNativeWindowDetails: async (): Promise<WindowDetails> => {
|
||||
const windowDetails = await ipcRenderer.invoke("get-native-window-details")
|
||||
const handle = Buffer.from(windowDetails.handle, "base64")
|
||||
return { ...windowDetails, handle }
|
||||
const windowDetails = await ipcRenderer.invoke("get-native-window-details");
|
||||
const handle = Buffer.from(windowDetails.handle, "base64");
|
||||
return { ...windowDetails, handle };
|
||||
},
|
||||
|
||||
openContextMenu: (
|
||||
|
||||
@@ -159,7 +159,7 @@ export interface Fido2AuthenticatorGetAssertionParams {
|
||||
/** Signals whether an error should be thrown if an assertion cannot be obtained without showing Bitwarden UI.
|
||||
*
|
||||
* Note that OS user verification prompts are allowed in silent requests.
|
||||
*/
|
||||
*/
|
||||
isSilent?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ export interface PickCredentialParams {
|
||||
/** Signals whether an error should be thrown if an assertion cannot be obtained without showing Bitwarden UI.
|
||||
*
|
||||
* Note that OS user verification prompts are allowed in silent requests.
|
||||
*/
|
||||
*/
|
||||
isSilent?: boolean;
|
||||
}
|
||||
|
||||
@@ -129,4 +129,4 @@ export abstract class Fido2UserInterfaceSession {
|
||||
}
|
||||
|
||||
/** Thrown when user interaction is required during a request for a silent assertion. */
|
||||
export class UserInteractionRequired extends Error {}
|
||||
export class UserInteractionRequired extends Error {}
|
||||
|
||||
Reference in New Issue
Block a user