Skip to content

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

Require a declared trigger link for hidden native file slots

Barack Sokullu702e5677a073
diff --git a/src/chrome/src/content/page-monitor.js b/src/chrome/src/content/page-monitor.js
index 1298336cb..94f584cd2 100644
--- a/src/chrome/src/content/page-monitor.js
+++ b/src/chrome/src/content/page-monitor.js
@@ -1355,7 +1355,21 @@
// an arbitrary Upload button is not enough.
const sameForm = target.form && owner.closest('form') === target.form
&& ('form' in activator ? activator.form : activator.closest('form')) === target.form;
- if (hiddenTransport || (hiddenTarget && sameForm)) return {
+ // Sharing a form and being the only visible button proves nothing. A
+ // hidden slot accepts only an activator the page itself ties to this
+ // input: its label, a button whose aria-controls names it, or the
+ // file-attachment element that owns exactly this one input (and names it
+ // when it uses the element's input attribute).
+ let attachment = null;
+ for (let node = bindingParent(target); node; node = bindingParent(node)) {
+ if (node.localName === 'file-attachment') { attachment = node; break; }
+ if (node === owner) break;
+ }
+ const linked = (activator.matches('label') && activator.control === target)
+ || (!!target.id && String(activator.getAttribute('aria-controls') || '').split(/\s+/).includes(target.id))
+ || (!!attachment && attachment.contains(activator) && attachment.querySelectorAll('input[type="file"]').length === 1
+ && (!attachment.hasAttribute('input') || attachment.getAttribute('input') === target.id));
+ if (hiddenTransport || (hiddenTarget && sameForm && linked)) return {
owner, activator, transport, contextForm: hiddenTransport ? null : target.form,
};
}
diff --git a/src/firefox/src/content/page-monitor.js b/src/firefox/src/content/page-monitor.js
index 1298336cb..94f584cd2 100644
--- a/src/firefox/src/content/page-monitor.js
+++ b/src/firefox/src/content/page-monitor.js
@@ -1355,7 +1355,21 @@
// an arbitrary Upload button is not enough.
const sameForm = target.form && owner.closest('form') === target.form
&& ('form' in activator ? activator.form : activator.closest('form')) === target.form;
- if (hiddenTransport || (hiddenTarget && sameForm)) return {
+ // Sharing a form and being the only visible button proves nothing. A
+ // hidden slot accepts only an activator the page itself ties to this
+ // input: its label, a button whose aria-controls names it, or the
+ // file-attachment element that owns exactly this one input (and names it
+ // when it uses the element's input attribute).
+ let attachment = null;
+ for (let node = bindingParent(target); node; node = bindingParent(node)) {
+ if (node.localName === 'file-attachment') { attachment = node; break; }
+ if (node === owner) break;
+ }
+ const linked = (activator.matches('label') && activator.control === target)
+ || (!!target.id && String(activator.getAttribute('aria-controls') || '').split(/\s+/).includes(target.id))
+ || (!!attachment && attachment.contains(activator) && attachment.querySelectorAll('input[type="file"]').length === 1
+ && (!attachment.hasAttribute('input') || attachment.getAttribute('input') === target.id));
+ if (hiddenTransport || (hiddenTarget && sameForm && linked)) return {
owner, activator, transport, contextForm: hiddenTransport ? null : target.form,
};
}
diff --git a/test/page-monitor-upload-release.mjs b/test/page-monitor-upload-release.mjs
index af4461922..9cb586c8c 100644
--- a/test/page-monitor-upload-release.mjs
+++ b/test/page-monitor-upload-release.mjs
@@ -7,7 +7,7 @@ import { uploadReleaseHtml, stageSequentialReleaseUploads } from './lib/upload-r
const recipientUploadHtml = `<!doctype html><style>
#binary-widget{display:block;width:400px;padding:10px}input[type=file]{width:1px;height:1px;opacity:0}
</style><form id="release-form"><div id="recipient">Upload recipient: Alice</div>
-<div id="binary-widget"><button type="button">Upload document</button><input type="file" id="releases-upload"></div></form>
+<div id="binary-widget"><button type="button" aria-controls="releases-upload">Upload document</button><input type="file" id="releases-upload"></div></form>
<script>window.attachmentEvents={markdown:[],binary:[]};window.chooserClicks=0;window.uploadRecipients=[];
document.getElementById('releases-upload').onchange=event=>{
attachmentEvents.binary.push([...event.target.files].map(file=>({name:file.name,size:file.size})));
@@ -128,6 +128,18 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {
assert.equal(attached.fence.ready, !changed);
assert.deepEqual(await page.evaluate(() => uploadRecipients), changed ? [] : ['Upload recipient: Alice']);
}, recipientUploadHtml));
+ for (const unrelated of ['aria-controls removed', 'aria-controls names another input'])
+ await t.test(`a direct hidden slot cannot borrow an unrelated button in its form: ${unrelated}`, () => withFixture(async page => {
+ await page.evaluate(unrelated => {
+ const button = document.querySelector('#binary-widget button');
+ if (unrelated === 'aria-controls removed') button.removeAttribute('aria-controls');
+ else button.setAttribute('aria-controls', 'another-upload');
+ }, unrelated);
+ const snapshot = await capture(page, { uploadTargets: ['#releases-upload'] });
+ assert.equal((await validate(page, snapshot)).ready, false, 'A button merely sharing the form is not the slot\'s activator');
+ const attached = await attach(page, snapshot);
+ assert.equal(attached.events.binary.length, 0); assert.equal(attached.chooserClicks, 0);
+ }, recipientUploadHtml));
await t.test('a direct hidden slot cannot use partially observed recipient text', () => withFixture(async page => {
await page.evaluate(() => { document.getElementById('recipient').textContent = 'Upload recipient: ' + 'Alice '.repeat(100); });
const snapshot = await capture(page, { uploadTargets: ['#releases-upload'] });