From 0ee06127d8350910d17f2982cb3ce51356ff4bab Mon Sep 17 00:00:00 2001 From: Nicholas Ellul Date: Wed, 6 Mar 2024 10:20:59 -0500 Subject: [PATCH] Update blockedDomainCheck to match extension --- scripts/inpage-bridge/content-script/index.js | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/scripts/inpage-bridge/content-script/index.js b/scripts/inpage-bridge/content-script/index.js index f0ab33010432..16052682c1ff 100644 --- a/scripts/inpage-bridge/content-script/index.js +++ b/scripts/inpage-bridge/content-script/index.js @@ -105,7 +105,10 @@ function documentElementCheck() { * @returns {boolean} {@code true} if the current domain is blocked */ function blockedDomainCheck() { + // If making any changes, please also update the same list found in the MetaMask-Mobile & SDK repositories const blockedDomains = [ + 'execution.consensys.io', + 'execution.metamask.io', 'uscourts.gov', 'dropbox.com', 'webbyawards.com', @@ -115,19 +118,32 @@ function blockedDomainCheck() { 'ani.gamer.com.tw', 'blueskybooking.com', 'sharefile.com', - ] + 'battle.net', + ]; - const blockedHrefs = [ + // Matching will happen based on the hostname, and path + const blockedUrlPaths = [ 'cdn.shopify.com/s/javascripts/tricorder/xtld-read-only-frame.html', - ] + ]; - const hostname = window.location.hostname; - const path = window.location.pathname; - - const blockedDomainFound = blockedDomains.some(blockedDomain => blockedDomain === hostname || hostname.endsWith(`.${blockedDomain}`)); - const blockedHrefFound = blockedHrefs.some(blockedHref => (hostname + path).includes(blockedHref)); + const { hostname: currentHostname, pathname: currentPathname } = + window.location; - return blockedDomainFound || blockedHrefFound; + const trimTrailingSlash = (str) => + str.endsWith('/') ? str.slice(0, -1) : str; + + return ( + blockedDomains.some( + (blockedDomain) => + blockedDomain === currentHostname || + currentHostname.endsWith(`.${blockedDomain}`), + ) || + blockedUrlPaths.some( + (blockedUrlPath) => + trimTrailingSlash(blockedUrlPath) === + trimTrailingSlash(currentHostname + currentPathname), + ) + ); } /**