From 64c01e57b261264b04b7bf1851f7e4a98ea07a2b Mon Sep 17 00:00:00 2001 From: Jimmy Vo Date: Wed, 19 Mar 2025 13:18:20 -0400 Subject: [PATCH] Fix domain error. --- ...ger-phishing-detection-script-injection.ts | 5 ++-- .../services/phishing-detection.service.ts | 30 +++---------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/apps/browser/src/phishing-detection/trigger-phishing-detection-script-injection.ts b/apps/browser/src/phishing-detection/trigger-phishing-detection-script-injection.ts index 319c7e50be8..167d76da7cc 100644 --- a/apps/browser/src/phishing-detection/trigger-phishing-detection-script-injection.ts +++ b/apps/browser/src/phishing-detection/trigger-phishing-detection-script-injection.ts @@ -1,4 +1,3 @@ -import { Utils } from "@bitwarden/common/platform/misc/utils"; import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service"; import { PhishingDetectionBrowserService } from "./content/phishing-detection-browser.service"; @@ -22,9 +21,9 @@ async function loadPhishingDetectionContent() { }); if (isPhishingDomain) { - const domain = Utils.getDomain(activeUrl); + const url = new URL(activeUrl); - PhishingDetectionBrowserService.notifyUser(domain); + PhishingDetectionBrowserService.notifyUser(url.hostname); } } diff --git a/apps/browser/src/platform/services/phishing-detection.service.ts b/apps/browser/src/platform/services/phishing-detection.service.ts index a40ccd54c82..39820659f94 100644 --- a/apps/browser/src/platform/services/phishing-detection.service.ts +++ b/apps/browser/src/platform/services/phishing-detection.service.ts @@ -3,7 +3,6 @@ import { Subscription } from "rxjs"; import { AuditService } from "@bitwarden/common/abstractions/audit.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; -import { Utils } from "@bitwarden/common/platform/misc/utils"; import { ScheduledTaskNames } from "@bitwarden/common/platform/scheduling"; import { TaskSchedulerService } from "@bitwarden/common/platform/scheduling/task-scheduler.service"; @@ -38,9 +37,6 @@ export class PhishingDetectionService { PhishingDetectionService.setupCheckUrlListener(); - // Initializing the data for local development - PhishingDetectionService.loadMockedData(); - // Register the update task this.taskSchedulerService.registerTaskHandler( ScheduledTaskNames.phishingDomainUpdate, @@ -130,9 +126,10 @@ export class PhishingDetectionService { } } - static checkUrl(url: string): boolean { - const domain = Utils.getDomain(url); - return domain ? PhishingDetectionService.knownPhishingDomains.has(domain) : false; + static checkUrl(inputUrl: string): boolean { + const url = new URL(inputUrl); + + return url ? PhishingDetectionService.knownPhishingDomains.has(url.hostname) : false; } static async updateKnownPhishingDomains(): Promise { @@ -211,25 +208,6 @@ export class PhishingDetectionService { this.retryCount = 0; } - static async getActiveUrl(): Promise { - const win = await BrowserApi.getCurrentWindow(); - const currentWindow = await BrowserApi.tabsQuery({ windowId: win.id, active: true }); - - // @TODO: Account for cases with no active windows. - return currentWindow[0].url; - } - - // @TODO: WIP. We can have a pop-up or send a notification to other services. - static notifyUser(url: string) {} - - // @TODO: This can be remove once we implement the real code. - static loadMockedData() { - PhishingDetectionService.knownPhishingDomains.add("google.com"); - PhishingDetectionService.knownPhishingDomains.add("atlassian.net"); - PhishingDetectionService.knownPhishingDomains.add("example.com"); - PhishingDetectionService.knownPhishingDomains.add("w3schools.com"); - } - /* This listener will check the URL when the tab has finished loading. */