From fb17cb7b99cf06edf52e7d29119b76f025f1a950 Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Tue, 6 Feb 2024 16:24:14 -0600 Subject: [PATCH] [PM-5739] Remove Usage of Angular within Background Script (#7659) --- apps/browser/src/auth/popup/lock.component.ts | 2 +- apps/browser/src/manifest.v3.json | 7 +++++-- .../src/platform/popup/browser-popup-utils.ts | 2 +- .../browser-fido2-user-interface.service.ts | 21 ------------------- .../fido2/fido2-use-browser-link.component.ts | 6 ++---- .../components/vault/add-edit.component.ts | 6 ++---- .../popup/components/vault/view.component.ts | 6 ++---- .../popup/utils/fido2-popout-session-data.ts | 21 +++++++++++++++++++ 8 files changed, 34 insertions(+), 37 deletions(-) create mode 100644 apps/browser/src/vault/popup/utils/fido2-popout-session-data.ts diff --git a/apps/browser/src/auth/popup/lock.component.ts b/apps/browser/src/auth/popup/lock.component.ts index 7ba5c09845..42c2d44e31 100644 --- a/apps/browser/src/auth/popup/lock.component.ts +++ b/apps/browser/src/auth/popup/lock.component.ts @@ -24,7 +24,7 @@ import { DialogService } from "@bitwarden/components"; import { BiometricErrors, BiometricErrorTypes } from "../../models/biometricErrors"; import { BrowserRouterService } from "../../platform/popup/services/browser-router.service"; -import { fido2PopoutSessionData$ } from "../../vault/fido2/browser-fido2-user-interface.service"; +import { fido2PopoutSessionData$ } from "../../vault/popup/utils/fido2-popout-session-data"; @Component({ selector: "app-lock", diff --git a/apps/browser/src/manifest.v3.json b/apps/browser/src/manifest.v3.json index 5b557461ec..2a9be6afa8 100644 --- a/apps/browser/src/manifest.v3.json +++ b/apps/browser/src/manifest.v3.json @@ -24,7 +24,10 @@ }, { "all_frames": true, - "js": ["content/trigger-autofill-script-injection.js"], + "js": [ + "content/trigger-autofill-script-injection.js", + "content/fido2/trigger-fido2-content-script-injection.js" + ], "matches": ["http://*/*", "https://*/*", "file:///*"], "run_at": "document_start" }, @@ -108,7 +111,7 @@ "web_accessible_resources": [ { "resources": [ - "content/webauthn/page-script.js", + "content/fido2/page-script.js", "notification/bar.html", "images/icon38.png", "images/icon38_locked.png", diff --git a/apps/browser/src/platform/popup/browser-popup-utils.ts b/apps/browser/src/platform/popup/browser-popup-utils.ts index 8cc060969d..8adc6b67cb 100644 --- a/apps/browser/src/platform/popup/browser-popup-utils.ts +++ b/apps/browser/src/platform/popup/browser-popup-utils.ts @@ -86,7 +86,7 @@ class BrowserPopupUtils { * Identifies if the background page needs to be initialized. */ static backgroundInitializationRequired() { - return BrowserApi.getBackgroundPage() === null; + return !BrowserApi.getBackgroundPage(); } /** diff --git a/apps/browser/src/vault/fido2/browser-fido2-user-interface.service.ts b/apps/browser/src/vault/fido2/browser-fido2-user-interface.service.ts index 6109112b5f..35f97d514c 100644 --- a/apps/browser/src/vault/fido2/browser-fido2-user-interface.service.ts +++ b/apps/browser/src/vault/fido2/browser-fido2-user-interface.service.ts @@ -1,5 +1,3 @@ -import { inject } from "@angular/core"; -import { ActivatedRoute } from "@angular/router"; import { BehaviorSubject, EmptyError, @@ -7,7 +5,6 @@ import { firstValueFrom, fromEvent, fromEventPattern, - map, merge, Observable, Subject, @@ -33,24 +30,6 @@ import { closeFido2Popout, openFido2Popout } from "../popup/utils/vault-popout-w const BrowserFido2MessageName = "BrowserFido2UserInterfaceServiceMessage"; -/** - * Function to retrieve FIDO2 session data from query parameters. - * Expected to be used within components tied to routes with these query parameters. - */ -export function fido2PopoutSessionData$() { - const route = inject(ActivatedRoute); - - return route.queryParams.pipe( - map((queryParams) => ({ - isFido2Session: queryParams.sessionId != null, - sessionId: queryParams.sessionId as string, - fallbackSupported: queryParams.fallbackSupported === "true", - userVerification: queryParams.userVerification === "true", - senderUrl: queryParams.senderUrl as string, - })), - ); -} - export class SessionClosedError extends Error { constructor() { super("Fido2UserInterfaceSession was closed"); diff --git a/apps/browser/src/vault/popup/components/fido2/fido2-use-browser-link.component.ts b/apps/browser/src/vault/popup/components/fido2/fido2-use-browser-link.component.ts index bd619138e6..ce22787f09 100644 --- a/apps/browser/src/vault/popup/components/fido2/fido2-use-browser-link.component.ts +++ b/apps/browser/src/vault/popup/components/fido2/fido2-use-browser-link.component.ts @@ -8,10 +8,8 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; -import { - BrowserFido2UserInterfaceSession, - fido2PopoutSessionData$, -} from "../../../fido2/browser-fido2-user-interface.service"; +import { BrowserFido2UserInterfaceSession } from "../../../fido2/browser-fido2-user-interface.service"; +import { fido2PopoutSessionData$ } from "../../utils/fido2-popout-session-data"; @Component({ selector: "app-fido2-use-browser-link", diff --git a/apps/browser/src/vault/popup/components/vault/add-edit.component.ts b/apps/browser/src/vault/popup/components/vault/add-edit.component.ts index db785feb02..331d72ce73 100644 --- a/apps/browser/src/vault/popup/components/vault/add-edit.component.ts +++ b/apps/browser/src/vault/popup/components/vault/add-edit.component.ts @@ -27,10 +27,8 @@ import { PasswordRepromptService } from "@bitwarden/vault"; import { BrowserApi } from "../../../../platform/browser/browser-api"; import BrowserPopupUtils from "../../../../platform/popup/browser-popup-utils"; import { PopupCloseWarningService } from "../../../../popup/services/popup-close-warning.service"; -import { - BrowserFido2UserInterfaceSession, - fido2PopoutSessionData$, -} from "../../../fido2/browser-fido2-user-interface.service"; +import { BrowserFido2UserInterfaceSession } from "../../../fido2/browser-fido2-user-interface.service"; +import { fido2PopoutSessionData$ } from "../../utils/fido2-popout-session-data"; import { VaultPopoutType, closeAddEditVaultItemPopout } from "../../utils/vault-popout-window"; @Component({ diff --git a/apps/browser/src/vault/popup/components/vault/view.component.ts b/apps/browser/src/vault/popup/components/vault/view.component.ts index 5f8b9c8677..f89b4ba4cc 100644 --- a/apps/browser/src/vault/popup/components/vault/view.component.ts +++ b/apps/browser/src/vault/popup/components/vault/view.component.ts @@ -29,10 +29,8 @@ import { PasswordRepromptService } from "@bitwarden/vault"; import { AutofillService } from "../../../../autofill/services/abstractions/autofill.service"; import { BrowserApi } from "../../../../platform/browser/browser-api"; import BrowserPopupUtils from "../../../../platform/popup/browser-popup-utils"; -import { - BrowserFido2UserInterfaceSession, - fido2PopoutSessionData$, -} from "../../../fido2/browser-fido2-user-interface.service"; +import { BrowserFido2UserInterfaceSession } from "../../../fido2/browser-fido2-user-interface.service"; +import { fido2PopoutSessionData$ } from "../../utils/fido2-popout-session-data"; import { closeViewVaultItemPopout, VaultPopoutType } from "../../utils/vault-popout-window"; const BroadcasterSubscriptionId = "ChildViewComponent"; diff --git a/apps/browser/src/vault/popup/utils/fido2-popout-session-data.ts b/apps/browser/src/vault/popup/utils/fido2-popout-session-data.ts new file mode 100644 index 0000000000..9917b7411d --- /dev/null +++ b/apps/browser/src/vault/popup/utils/fido2-popout-session-data.ts @@ -0,0 +1,21 @@ +import { inject } from "@angular/core"; +import { ActivatedRoute } from "@angular/router"; +import { map } from "rxjs"; + +/** + * Function to retrieve FIDO2 session data from query parameters. + * Expected to be used within components tied to routes with these query parameters. + */ +export function fido2PopoutSessionData$() { + const route = inject(ActivatedRoute); + + return route.queryParams.pipe( + map((queryParams) => ({ + isFido2Session: queryParams.sessionId != null, + sessionId: queryParams.sessionId as string, + fallbackSupported: queryParams.fallbackSupported === "true", + userVerification: queryParams.userVerification === "true", + senderUrl: queryParams.senderUrl as string, + })), + ); +}