From 47913b8920c8c3c5556e3dea69944076cb9c1d0f Mon Sep 17 00:00:00 2001 From: Conner Turnbull <133619638+cturnbull-bitwarden@users.noreply.github.com> Date: Thu, 20 Mar 2025 09:56:08 -0400 Subject: [PATCH] Wrapped phishing detection feature behind feature flag (#13915) --- .../browser/src/background/main.background.ts | 21 +++++++++++++------ .../reports/pages/reports-home.component.ts | 19 +++++++++++++---- .../tools/reports/reports-routing.module.ts | 4 +++- libs/common/src/enums/feature-flag.enum.ts | 2 ++ 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index 11131134862..b75df010714 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -1284,12 +1284,21 @@ export default class MainBackground { this.inlineMenuFieldQualificationService = new InlineMenuFieldQualificationService(); - PhishingDetectionService.initialize( - this.auditService, - this.logService, - this.storageService, - this.taskSchedulerService, - ); + this.configService + .getFeatureFlag(FeatureFlag.PhishingDetection) + .then((enabled) => { + if (enabled) { + PhishingDetectionService.initialize( + this.auditService, + this.logService, + this.storageService, + this.taskSchedulerService, + ); + } + }) + .catch((error) => + this.logService.error("Failed to check phishing detection feature flag", error), + ); } async bootstrap() { diff --git a/apps/web/src/app/tools/reports/pages/reports-home.component.ts b/apps/web/src/app/tools/reports/pages/reports-home.component.ts index f6691c7405a..9127b7320ac 100644 --- a/apps/web/src/app/tools/reports/pages/reports-home.component.ts +++ b/apps/web/src/app/tools/reports/pages/reports-home.component.ts @@ -5,6 +5,8 @@ import { firstValueFrom } from "rxjs"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service"; +import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum"; +import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { reports, ReportType } from "../reports"; import { ReportEntry, ReportVariant } from "../shared"; @@ -19,6 +21,7 @@ export class ReportsHomeComponent implements OnInit { constructor( private billingAccountProfileStateService: BillingAccountProfileStateService, private accountService: AccountService, + private configService: ConfigService, ) {} async ngOnInit(): Promise { @@ -30,6 +33,10 @@ export class ReportsHomeComponent implements OnInit { ? ReportVariant.Enabled : ReportVariant.RequiresPremium; + const phishingDetectionEnabled = await this.configService.getFeatureFlag( + FeatureFlag.PhishingDetection, + ); + this.reports = [ { ...reports[ReportType.ExposedPasswords], @@ -47,10 +54,14 @@ export class ReportsHomeComponent implements OnInit { ...reports[ReportType.UnsecuredWebsites], variant: reportRequiresPremium, }, - { - ...reports[ReportType.PhishingWebsitesReport], - variant: reportRequiresPremium, - }, + ...(phishingDetectionEnabled + ? [ + { + ...reports[ReportType.PhishingWebsitesReport], + variant: ReportVariant.Enabled, + }, + ] + : []), { ...reports[ReportType.Inactive2fa], variant: reportRequiresPremium, diff --git a/apps/web/src/app/tools/reports/reports-routing.module.ts b/apps/web/src/app/tools/reports/reports-routing.module.ts index d86121a605e..6373fb11a6f 100644 --- a/apps/web/src/app/tools/reports/reports-routing.module.ts +++ b/apps/web/src/app/tools/reports/reports-routing.module.ts @@ -2,6 +2,8 @@ import { NgModule } from "@angular/core"; import { RouterModule, Routes } from "@angular/router"; import { authGuard } from "@bitwarden/angular/auth/guards"; +import { canAccessFeature } from "@bitwarden/angular/platform/guard/feature-flag.guard"; +import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum"; import { hasPremiumGuard } from "../../billing/guards/has-premium.guard"; @@ -66,7 +68,7 @@ const routes: Routes = [ path: "phishing-website-report", component: PhishingWebsiteReport, data: { titleId: "phishingWebsiteReport" }, - canActivate: [hasPremiumGuard()], + canActivate: [canAccessFeature(FeatureFlag.PhishingDetection)], }, ], }, diff --git a/libs/common/src/enums/feature-flag.enum.ts b/libs/common/src/enums/feature-flag.enum.ts index c96c168c718..8a17930271d 100644 --- a/libs/common/src/enums/feature-flag.enum.ts +++ b/libs/common/src/enums/feature-flag.enum.ts @@ -45,6 +45,7 @@ export enum FeatureFlag { PM15179_AddExistingOrgsFromProviderPortal = "pm-15179-add-existing-orgs-from-provider-portal", RecoveryCodeLogin = "pm-17128-recovery-code-login", PM12276_BreadcrumbEventLogs = "pm-12276-breadcrumbing-for-business-features", + PhishingDetection = "phishing-detection", } export type AllowedFeatureFlagTypes = boolean | number | string; @@ -100,6 +101,7 @@ export const DefaultFeatureFlagValue = { [FeatureFlag.PM15179_AddExistingOrgsFromProviderPortal]: FALSE, [FeatureFlag.RecoveryCodeLogin]: FALSE, [FeatureFlag.PM12276_BreadcrumbEventLogs]: FALSE, + [FeatureFlag.PhishingDetection]: FALSE, } satisfies Record; export type DefaultFeatureFlagValueType = typeof DefaultFeatureFlagValue;