mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-21 16:18:28 +01:00
[PM-4766] Disable fido2 integration on bw vault page (#6861)
* [PM-4766] feat: disable fido2 integration on bw vault page * [PM-4766] fix: lint
This commit is contained in:
parent
43bda8b139
commit
29841605fb
@ -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";
|
||||
@ -32,10 +32,14 @@ async function isDomainExcluded() {
|
||||
activeUserId = activeUserStorageValue[activeUserIdKey];
|
||||
}
|
||||
|
||||
// Look up the user's settings from storage
|
||||
const userSettingsStorageValue = await getFromLocalStorage(activeUserId);
|
||||
const settingsStorage = await getFromLocalStorage(activeUserId);
|
||||
|
||||
const excludedDomains = userSettingsStorageValue[activeUserId]?.settings?.neverDomains;
|
||||
// Look up the user's settings from storage
|
||||
return settingsStorage?.[activeUserId]?.settings;
|
||||
}
|
||||
|
||||
async function isDomainExcluded(activeUserSettings: Record<string, any>) {
|
||||
const excludedDomains = activeUserSettings?.neverDomains;
|
||||
return excludedDomains && window.location.hostname in excludedDomains;
|
||||
}
|
||||
|
||||
@ -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");
|
||||
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user