Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Parse explicit and protocol-relative urlFilter addresses before the host heuristics
Claude7a8f98f90318
diff --git a/src/chrome/src/agent/permission-gate.js b/src/chrome/src/agent/permission-gate.jsindex 1a3d8b4ea..e6b5895fe 100644--- a/src/chrome/src/agent/permission-gate.js+++ b/src/chrome/src/agent/permission-gate.js@@ -593,6 +593,13 @@ export function frameHostMatches(frameUrl, urlFilter) {// domain people use as a host (.do, .pl, .py, .sh, .cc) is left out on purpose.const FILE_NAME_SUFFIX = /\.(?:html?|xhtml|shtml?|php[345]?|phtml|aspx?|ashx|asmx|axd|jspx?|jsf|faces|cfml?|cgi|fcgi|action|esp|nsf|js|mjs|css|json|xml|txt|svg|png|jpe?g|gif|webp|pdf)$/i;function urlFilterNamesHost(filter) {+ // An explicit address ("https://payments/path", "//stripe.com/pay") names+ // whatever host it parses to, a single-label internal name included.+ if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(filter)) {+ try {+ if (new URL(filter.startsWith('//') ? `https:${filter}` : filter).hostname) return true;+ } catch { /* not an address; the host heuristics below decide */ }+ }const first = filter.replace(/^[a-z][a-z0-9+.-]*:\/\//i, '').split(/[/?#]/)[0];// A fully qualified name may end in a dot ("stripe.com.").const host = first.replace(/:\d+$/, '').replace(/\.$/, '');diff --git a/src/firefox/src/agent/permission-gate.js b/src/firefox/src/agent/permission-gate.jsindex 34d08a075..c51283ac4 100644--- a/src/firefox/src/agent/permission-gate.js+++ b/src/firefox/src/agent/permission-gate.js@@ -578,6 +578,13 @@ export function frameHostMatches(frameUrl, urlFilter) {// domain people use as a host (.do, .pl, .py, .sh, .cc) is left out on purpose.const FILE_NAME_SUFFIX = /\.(?:html?|xhtml|shtml?|php[345]?|phtml|aspx?|ashx|asmx|axd|jspx?|jsf|faces|cfml?|cgi|fcgi|action|esp|nsf|js|mjs|css|json|xml|txt|svg|png|jpe?g|gif|webp|pdf)$/i;function urlFilterNamesHost(filter) {+ // An explicit address ("https://payments/path", "//stripe.com/pay") names+ // whatever host it parses to, a single-label internal name included.+ if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(filter)) {+ try {+ if (new URL(filter.startsWith('//') ? `https:${filter}` : filter).hostname) return true;+ } catch { /* not an address; the host heuristics below decide */ }+ }const first = filter.replace(/^[a-z][a-z0-9+.-]*:\/\//i, '').split(/[/?#]/)[0];// A fully qualified name may end in a dot ("stripe.com.").const host = first.replace(/:\d+$/, '').replace(/\.$/, '');diff --git a/test/run.js b/test/run.jsindex 8be37468e..1cf2ed4a0 100644--- a/test/run.js+++ b/test/run.js@@ -2569,6 +2569,9 @@ test('iframe tools say how to name a frame host when urlFilter is only a path',for (const name of ['checkout.cfm', 'order.action', 'frame.shtml', 'handler.ashx', 'pay.jspx']) {assert.match(gate.urlFilterHostHint(name, [`https://shop.example/x/${name}`]), new RegExp(`for example "shop\\.example/x/${name.replace('.', '\\.')}"`), `${build}: ${name} is a file name, not a host`);}+ for (const filter of ['https://payments/path', '//stripe.com/pay', 'http://intranet:8080/x']) {+ assert.equal(gate.urlFilterHostHint(filter, ['https://evil.example/?next=' + filter]), '', `${build}: ${filter} is an explicit address`);+ }for (const filter of ['stripe.com.', 'https://stripe.com./pay', 'stripe.com.:8443']) {assert.equal(gate.urlFilterHostHint(filter, ['https://evil.example/?next=' + filter]), '', `${build}: ${filter} is a fully qualified host`);}