Skip to content

Commit

Permalink
[PM-4766] Disable fido2 integration on bw vault page (#6861)
Browse files Browse the repository at this point in the history
* [PM-4766] feat: disable fido2 integration on bw vault page

* [PM-4766] fix: lint
  • Loading branch information
coroiu authored Dec 11, 2023
1 parent 43bda8b commit 2984160
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions apps/browser/src/vault/fido2/content/content-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function getFromLocalStorage(keys: string | string[]): Promise<Record<stri
});
}

async function isDomainExcluded() {
async function getActiveUserSettings() {
// TODO: This is code copied from `notification-bar.tsx`. We should refactor this into a shared function.
// Look up the active user id from storage
const activeUserIdKey = "activeUserId";
Expand All @@ -32,10 +32,14 @@ async function isDomainExcluded() {
activeUserId = activeUserStorageValue[activeUserIdKey];
}

const settingsStorage = await getFromLocalStorage(activeUserId);

// Look up the user's settings from storage
const userSettingsStorageValue = await getFromLocalStorage(activeUserId);
return settingsStorage?.[activeUserId]?.settings;
}

const excludedDomains = userSettingsStorageValue[activeUserId]?.settings?.neverDomains;
async function isDomainExcluded(activeUserSettings: Record<string, any>) {
const excludedDomains = activeUserSettings?.neverDomains;
return excludedDomains && window.location.hostname in excludedDomains;
}

Expand All @@ -53,6 +57,10 @@ function isSameOriginWithAncestors() {
}
}

async function isLocationBitwardenVault(activeUserSettings: Record<string, any>) {
return window.location.origin === activeUserSettings.serverConfig.environment.vault;
}

function initializeFido2ContentScript() {
const s = document.createElement("script");
s.src = chrome.runtime.getURL("content/fido2/page-script.js");
Expand Down Expand Up @@ -132,9 +140,21 @@ function initializeFido2ContentScript() {
}

async function run() {
if ((await hasActiveUser()) && (await isFido2FeatureEnabled()) && !(await isDomainExcluded())) {
initializeFido2ContentScript();
if (!(await hasActiveUser())) {
return;
}

const activeUserSettings = await getActiveUserSettings();
if (
activeUserSettings == null ||
!(await isFido2FeatureEnabled()) ||
(await isDomainExcluded(activeUserSettings)) ||
(await isLocationBitwardenVault(activeUserSettings))
) {
return;
}

initializeFido2ContentScript();
}

run();

0 comments on commit 2984160

Please sign in to comment.