fix notification bar content script using old server config state storage (#8618)

This commit is contained in:
Jonathan Prusik 2024-04-05 17:36:52 -04:00 committed by GitHub
parent 8ae44b13ed
commit 216bbdb44c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 25 additions and 20 deletions

View File

@ -1,4 +1,5 @@
import { NeverDomains } from "@bitwarden/common/models/domain/domain-service"; import { NeverDomains } from "@bitwarden/common/models/domain/domain-service";
import { ServerConfig } from "@bitwarden/common/platform/abstractions/config/server-config";
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view"; import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
import { NotificationQueueMessageTypes } from "../../enums/notification-queue-message-type.enum"; import { NotificationQueueMessageTypes } from "../../enums/notification-queue-message-type.enum";
@ -113,6 +114,7 @@ type NotificationBackgroundExtensionMessageHandlers = {
bgGetEnableChangedPasswordPrompt: () => Promise<boolean>; bgGetEnableChangedPasswordPrompt: () => Promise<boolean>;
bgGetEnableAddedLoginPrompt: () => Promise<boolean>; bgGetEnableAddedLoginPrompt: () => Promise<boolean>;
bgGetExcludedDomains: () => Promise<NeverDomains>; bgGetExcludedDomains: () => Promise<NeverDomains>;
bgGetActiveUserServerConfig: () => Promise<ServerConfig>;
getWebVaultUrlForNotification: () => Promise<string>; getWebVaultUrlForNotification: () => Promise<string>;
}; };

View File

@ -6,6 +6,7 @@ import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authenticatio
import { AuthService } from "@bitwarden/common/auth/services/auth.service"; import { AuthService } from "@bitwarden/common/auth/services/auth.service";
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service"; import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
import { UserNotificationSettingsService } from "@bitwarden/common/autofill/services/user-notification-settings.service"; import { UserNotificationSettingsService } from "@bitwarden/common/autofill/services/user-notification-settings.service";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { SelfHostedEnvironment } from "@bitwarden/common/platform/services/default-environment.service"; import { SelfHostedEnvironment } from "@bitwarden/common/platform/services/default-environment.service";
@ -54,6 +55,7 @@ describe("NotificationBackground", () => {
const environmentService = mock<EnvironmentService>(); const environmentService = mock<EnvironmentService>();
const logService = mock<LogService>(); const logService = mock<LogService>();
const themeStateService = mock<ThemeStateService>(); const themeStateService = mock<ThemeStateService>();
const configService = mock<ConfigService>();
beforeEach(() => { beforeEach(() => {
notificationBackground = new NotificationBackground( notificationBackground = new NotificationBackground(
@ -68,6 +70,7 @@ describe("NotificationBackground", () => {
environmentService, environmentService,
logService, logService,
themeStateService, themeStateService,
configService,
); );
}); });

View File

@ -8,6 +8,8 @@ import { NOTIFICATION_BAR_LIFESPAN_MS } from "@bitwarden/common/autofill/constan
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service"; import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
import { UserNotificationSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/user-notification-settings.service"; import { UserNotificationSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/user-notification-settings.service";
import { NeverDomains } from "@bitwarden/common/models/domain/domain-service"; import { NeverDomains } from "@bitwarden/common/models/domain/domain-service";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { ServerConfig } from "@bitwarden/common/platform/abstractions/config/server-config";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { Utils } from "@bitwarden/common/platform/misc/utils"; import { Utils } from "@bitwarden/common/platform/misc/utils";
@ -64,6 +66,7 @@ export default class NotificationBackground {
bgGetEnableChangedPasswordPrompt: () => this.getEnableChangedPasswordPrompt(), bgGetEnableChangedPasswordPrompt: () => this.getEnableChangedPasswordPrompt(),
bgGetEnableAddedLoginPrompt: () => this.getEnableAddedLoginPrompt(), bgGetEnableAddedLoginPrompt: () => this.getEnableAddedLoginPrompt(),
bgGetExcludedDomains: () => this.getExcludedDomains(), bgGetExcludedDomains: () => this.getExcludedDomains(),
bgGetActiveUserServerConfig: () => this.getActiveUserServerConfig(),
getWebVaultUrlForNotification: () => this.getWebVaultUrl(), getWebVaultUrlForNotification: () => this.getWebVaultUrl(),
}; };
@ -79,6 +82,7 @@ export default class NotificationBackground {
private environmentService: EnvironmentService, private environmentService: EnvironmentService,
private logService: LogService, private logService: LogService,
private themeStateService: ThemeStateService, private themeStateService: ThemeStateService,
private configService: ConfigService,
) {} ) {}
async init() { async init() {
@ -112,6 +116,13 @@ export default class NotificationBackground {
return await firstValueFrom(this.domainSettingsService.neverDomains$); return await firstValueFrom(this.domainSettingsService.neverDomains$);
} }
/**
* Gets the active user server config from the config service.
*/
async getActiveUserServerConfig(): Promise<ServerConfig> {
return await firstValueFrom(this.configService.serverConfig$);
}
/** /**
* Checks the notification queue for any messages that need to be sent to the * Checks the notification queue for any messages that need to be sent to the
* specified tab. If no tab is specified, the current tab will be used. * specified tab. If no tab is specified, the current tab will be used.

View File

@ -1,3 +1,4 @@
import { ServerConfig } from "../../../../../libs/common/src/platform/abstractions/config/server-config";
import { import {
AddLoginMessageData, AddLoginMessageData,
ChangePasswordMessageData, ChangePasswordMessageData,
@ -6,12 +7,7 @@ import AutofillField from "../models/autofill-field";
import { WatchedForm } from "../models/watched-form"; import { WatchedForm } from "../models/watched-form";
import { NotificationBarIframeInitData } from "../notification/abstractions/notification-bar"; import { NotificationBarIframeInitData } from "../notification/abstractions/notification-bar";
import { FormData } from "../services/abstractions/autofill.service"; import { FormData } from "../services/abstractions/autofill.service";
import { UserSettings } from "../types"; import { sendExtensionMessage, setupExtensionDisconnectAction } from "../utils";
import {
getFromLocalStorage,
sendExtensionMessage,
setupExtensionDisconnectAction,
} from "../utils";
interface HTMLElementWithFormOpId extends HTMLElement { interface HTMLElementWithFormOpId extends HTMLElement {
formOpId: string; formOpId: string;
@ -95,25 +91,17 @@ async function loadNotificationBar() {
); );
const enableAddedLoginPrompt = await sendExtensionMessage("bgGetEnableAddedLoginPrompt"); const enableAddedLoginPrompt = await sendExtensionMessage("bgGetEnableAddedLoginPrompt");
const excludedDomains = await sendExtensionMessage("bgGetExcludedDomains"); const excludedDomains = await sendExtensionMessage("bgGetExcludedDomains");
const activeUserServerConfig: ServerConfig = await sendExtensionMessage(
"bgGetActiveUserServerConfig",
);
const activeUserVault = activeUserServerConfig?.environment?.vault;
let showNotificationBar = true; let showNotificationBar = true;
// Look up the active user id from storage
const activeUserIdKey = "activeUserId";
let activeUserId: string;
const activeUserStorageValue = await getFromLocalStorage(activeUserIdKey);
if (activeUserStorageValue[activeUserIdKey]) {
activeUserId = activeUserStorageValue[activeUserIdKey];
}
// Look up the user's settings from storage
const userSettingsStorageValue = await getFromLocalStorage(activeUserId);
if (userSettingsStorageValue[activeUserId]) {
const userSettings: UserSettings = userSettingsStorageValue[activeUserId].settings;
if (activeUserVault) {
// Do not show the notification bar on the Bitwarden vault // Do not show the notification bar on the Bitwarden vault
// because they can add logins and change passwords there // because they can add logins and change passwords there
if (window.location.origin === userSettings.serverConfig.environment.vault) { if (window.location.origin === activeUserVault) {
showNotificationBar = false; showNotificationBar = false;
} else { } else {
// NeverDomains is a dictionary of domains that the user has chosen to never // NeverDomains is a dictionary of domains that the user has chosen to never

View File

@ -908,6 +908,7 @@ export default class MainBackground {
this.environmentService, this.environmentService,
this.logService, this.logService,
themeStateService, themeStateService,
this.configService,
); );
this.overlayBackground = new OverlayBackground( this.overlayBackground = new OverlayBackground(
this.cipherService, this.cipherService,