1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-09 13:10:17 +00:00

[PM-19814] Use webNavigation.onCompleted for redirect to ensure that the redirect only happens when they land on the page.

This commit is contained in:
Jimmy Vo
2025-04-16 15:44:16 -04:00
parent 537eec25b0
commit 3031d712e9

View File

@@ -226,19 +226,27 @@ export class PhishingDetectionService {
}
static setupListeners(): void {
chrome.webRequest.onCompleted.addListener(
(details: chrome.webRequest.WebRequestDetails): void => {
chrome.webNavigation.onCompleted.addListener(
(details: chrome.webNavigation.WebNavigationFramedCallbackDetails): void => {
const url = new URL(details.url);
const result = PhishingDetectionService.knownPhishingDomains.has(url.hostname);
if (PhishingDetectionService.knownPhishingDomains.has(url.hostname)) {
this.logService.debug("Phishing detection check", {
details,
result,
url,
});
if (result) {
PhishingDetectionService.RedirectToWarningPage(url.hostname, details.tabId);
}
},
{ urls: ["<all_urls>"], types: ["main_frame"] },
);
}
static RedirectToWarningPage(hostname: string, tabId: number) {
this.logService.debug("Redirecting to warning page.");
const phishingWarningPage = chrome.runtime.getURL(
"popup/index.html#/security/phishing-warning",
);