mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 15:23:33 +00:00
[PM-18219] Normalize blocked domain checks to a common util (#13416)
* normalize blocked domain checks to common util * do not use currentTabIsOnBlocklist$ in showCurrentTabIsBlockedBanner$ resolution * update additional vault popup autofill service cases to use isUrlInList * cleanup and use Utils get hostname instead of tldts directly
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import { NeverDomains } from "@bitwarden/common/models/domain/domain-service";
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
|
||||
import { CardView } from "../vault/models/view/card.view";
|
||||
|
||||
import {
|
||||
@@ -329,3 +332,29 @@ export function parseYearMonthExpiry(combinedExpiryValue: string): [Year | null,
|
||||
|
||||
return [parsedYear, parsedMonth];
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a URL string and a NeverDomains object and determines if the passed URL's hostname is in `urlList`
|
||||
*
|
||||
* @param {string} url - representation of URL to check
|
||||
* @param {NeverDomains} urlList - object with hostname key names
|
||||
*/
|
||||
export function isUrlInList(url: string = "", urlList: NeverDomains = {}): boolean {
|
||||
const urlListKeys = urlList && Object.keys(urlList);
|
||||
|
||||
if (urlListKeys.length && url?.length) {
|
||||
let tabHostname;
|
||||
try {
|
||||
tabHostname = Utils.getHostname(url);
|
||||
} catch {
|
||||
// If the input was invalid, exit early and return false
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tabHostname) {
|
||||
return urlListKeys.some((blockedHostname) => tabHostname.endsWith(blockedHostname));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user