Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Recognize fully qualified (trailing-dot) hosts in iframe urlFilter hints

Clauded8b14cd11149
diff --git a/src/chrome/src/agent/permission-gate.js b/src/chrome/src/agent/permission-gate.js
index 0d6bfc7e4..1a3d8b4ea 100644
--- a/src/chrome/src/agent/permission-gate.js
+++ b/src/chrome/src/agent/permission-gate.js
@@ -594,7 +594,8 @@ export function frameHostMatches(frameUrl, urlFilter) {
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) {
const first = filter.replace(/^[a-z][a-z0-9+.-]*:\/\//i, '').split(/[/?#]/)[0];
- const host = first.replace(/:\d+$/, '');
+ // A fully qualified name may end in a dot ("stripe.com.").
+ const host = first.replace(/:\d+$/, '').replace(/\.$/, '');
if (!host) return false;
return /^\[[0-9a-f:.]+\]$/i.test(host) || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(host) || host.toLowerCase() === 'localhost'
|| (/^[a-z0-9-]+(?:\.[a-z0-9-]+)+$/i.test(host) && !FILE_NAME_SUFFIX.test(host));
diff --git a/src/firefox/src/agent/permission-gate.js b/src/firefox/src/agent/permission-gate.js
index 917e586a5..34d08a075 100644
--- a/src/firefox/src/agent/permission-gate.js
+++ b/src/firefox/src/agent/permission-gate.js
@@ -579,7 +579,8 @@ export function frameHostMatches(frameUrl, urlFilter) {
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) {
const first = filter.replace(/^[a-z][a-z0-9+.-]*:\/\//i, '').split(/[/?#]/)[0];
- const host = first.replace(/:\d+$/, '');
+ // A fully qualified name may end in a dot ("stripe.com.").
+ const host = first.replace(/:\d+$/, '').replace(/\.$/, '');
if (!host) return false;
return /^\[[0-9a-f:.]+\]$/i.test(host) || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(host) || host.toLowerCase() === 'localhost'
|| (/^[a-z0-9-]+(?:\.[a-z0-9-]+)+$/i.test(host) && !FILE_NAME_SUFFIX.test(host));
diff --git a/test/run.js b/test/run.js
index d62561052..8be37468e 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 ['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`);
+ }
assert.equal(gate.urlFilterHostHint('shop.do', ['https://evil.example/?next=shop.do']), '', `${build}: .do is a country domain, so shop.do names a host`);
// No hint when the filter names a host (even one no frame has: a page
// cannot steer "stripe.com" to its own frame that mentions it), when