From bfdca55ae382fc5cea7e791e30ef75c61ea1ebb8 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Tue, 13 Jan 2026 12:52:30 -0600 Subject: [PATCH] Apply lints --- .../credentials/fido2-create.component.ts | 12 ++- .../credentials/fido2-vault.component.ts | 8 +- .../services/desktop-autofill.service.ts | 32 ++++--- .../desktop-fido2-user-interface.service.ts | 85 ++++++++++--------- apps/desktop/src/main/window.main.ts | 8 +- .../src/platform/main/autofill/command.ts | 5 +- .../autofill/user-verification.command.ts | 3 +- apps/desktop/src/platform/preload.ts | 7 +- ...fido2-authenticator.service.abstraction.ts | 2 +- ...ido2-user-interface.service.abstraction.ts | 4 +- 10 files changed, 94 insertions(+), 72 deletions(-) diff --git a/apps/desktop/src/autofill/modal/credentials/fido2-create.component.ts b/apps/desktop/src/autofill/modal/credentials/fido2-create.component.ts index c5217e783f1..3133d383507 100644 --- a/apps/desktop/src/autofill/modal/credentials/fido2-create.component.ts +++ b/apps/desktop/src/autofill/modal/credentials/fido2-create.component.ts @@ -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 { diff --git a/apps/desktop/src/autofill/modal/credentials/fido2-vault.component.ts b/apps/desktop/src/autofill/modal/credentials/fido2-vault.component.ts index 25a78b601c3..2e8992e6c9d 100644 --- a/apps/desktop/src/autofill/modal/credentials/fido2-vault.component.ts +++ b/apps/desktop/src/autofill/modal/credentials/fido2-vault.component.ts @@ -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 { diff --git a/apps/desktop/src/autofill/services/desktop-autofill.service.ts b/apps/desktop/src/autofill/services/desktop-autofill.service.ts index 2c1fdce1a09..ce4438fd2ca 100644 --- a/apps/desktop/src/autofill/services/desktop-autofill.service.ts +++ b/apps/desktop/src/autofill/services/desktop-autofill.service.ts @@ -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; diff --git a/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts b/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts index 9f7966f5f0d..140b78c0ad9 100644 --- a/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts +++ b/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts @@ -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 { - 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 = 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 = 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 */ diff --git a/apps/desktop/src/main/window.main.ts b/apps/desktop/src/main/window.main.ts index dd66a834558..6a3bd8afa64 100644 --- a/apps/desktop/src/main/window.main.ts +++ b/apps/desktop/src/main/window.main.ts @@ -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; +}; diff --git a/apps/desktop/src/platform/main/autofill/command.ts b/apps/desktop/src/platform/main/autofill/command.ts index 2549e617679..1c656062f38 100644 --- a/apps/desktop/src/platform/main/autofill/command.ts +++ b/apps/desktop/src/platform/main/autofill/command.ts @@ -21,4 +21,7 @@ export type IpcCommandInvoker = ( ) => Promise>; /** A list of all available commands */ -export type Command = NativeAutofillSyncCommand | NativeAutofillStatusCommand | NativeAutofillUserVerificationCommand; +export type Command = + | NativeAutofillSyncCommand + | NativeAutofillStatusCommand + | NativeAutofillUserVerificationCommand; diff --git a/apps/desktop/src/platform/main/autofill/user-verification.command.ts b/apps/desktop/src/platform/main/autofill/user-verification.command.ts index 688e39f3bb8..821fd1e5d16 100644 --- a/apps/desktop/src/platform/main/autofill/user-verification.command.ts +++ b/apps/desktop/src/platform/main/autofill/user-verification.command.ts @@ -15,5 +15,4 @@ export type NativeAutofillUserVerificationParams = { username: string; }; - -export type NativeAutofillUserVerificationResult = CommandOutput<{}>; \ No newline at end of file +export type NativeAutofillUserVerificationResult = CommandOutput; diff --git a/apps/desktop/src/platform/preload.ts b/apps/desktop/src/platform/preload.ts index 4bc9a511752..3f7e9c40b80 100644 --- a/apps/desktop/src/platform/preload.ts +++ b/apps/desktop/src/platform/preload.ts @@ -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 => { - 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: ( diff --git a/libs/common/src/platform/abstractions/fido2/fido2-authenticator.service.abstraction.ts b/libs/common/src/platform/abstractions/fido2/fido2-authenticator.service.abstraction.ts index fcef9bb2400..a8fbc27e935 100644 --- a/libs/common/src/platform/abstractions/fido2/fido2-authenticator.service.abstraction.ts +++ b/libs/common/src/platform/abstractions/fido2/fido2-authenticator.service.abstraction.ts @@ -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; } diff --git a/libs/common/src/platform/abstractions/fido2/fido2-user-interface.service.abstraction.ts b/libs/common/src/platform/abstractions/fido2/fido2-user-interface.service.abstraction.ts index f3e8d97fcfe..ebf9275c7b0 100644 --- a/libs/common/src/platform/abstractions/fido2/fido2-user-interface.service.abstraction.ts +++ b/libs/common/src/platform/abstractions/fido2/fido2-user-interface.service.abstraction.ts @@ -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 {} \ No newline at end of file +export class UserInteractionRequired extends Error {}