Skip to content

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

Key a declined submission by a fingerprint of every value it sends

Claude9181f14ed453
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index feb8907e4..38e5c9ed6 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -32451,8 +32451,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// control whose form, fields and action it could not read, or one whose
// form and button the page probe did not identify. Two forms can post
// the same visible fields to one endpoint (per-row forms told apart only
- // by hidden IDs), and one form can have several buttons, so the key
- // also names the frame and the form and button elements.
+ // by hidden IDs), one form can have several buttons, and the summary of
+ // changed fields leaves values out, so the key also names the frame, the
+ // form and button elements, and the probe's fingerprint of every value
+ // the form would send.
_declinableSubmissionKey(toolName, submitInfo) {
if (!submitInfo || toolName === 'execute_js' || toolName === 'execute_webmcp_tool') return '';
const resolved = (Array.isArray(submitInfo.changedFields) && submitInfo.changedFields.length > 0)
@@ -33362,18 +33364,25 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
};
const transactionOrderSite = /(?:^|\.)12306\.cn$/i.test(host);
// The form and the button a submission goes through, as identities of
- // the elements this frame holds. A declined submission is remembered by
- // them, so another form or button with the same fields and action
- // (per-row forms told apart only by hidden IDs, Reject beside Approve)
- // still gets its own card. An Enter in a field, or set_field({submit}),
- // submits through the form's default button.
- const submissionIdentity = (form, submitControl) => {
+ // the elements this frame holds, and every value the form would send, as
+ // a fingerprint keyed by a secret that never leaves this frame. A
+ // declined submission is remembered by them, so another form or button
+ // with the same fields and action (per-row forms told apart only by
+ // hidden IDs, Reject beside Approve), or the same form with any value
+ // changed (a field past the summary's first eight, a password, another
+ // file, a hidden record ID), still gets its own card. An Enter in a
+ // field, or set_field({submit}), submits through the form's default
+ // button.
+ const submissionIdentity = (form, submitControl, pendingEl = null, pendingValue = null) => {
try {
if (!(window.__wbSubmissionIdentities instanceof WeakMap)) {
window.__wbSubmissionIdentities = new WeakMap();
window.__wbSubmissionIdentityPrefix = Math.random().toString(36).slice(2, 10);
window.__wbSubmissionIdentityCount = 0;
}
+ if (typeof window.__wbSubmissionValueKey !== 'string' || !window.__wbSubmissionValueKey) {
+ window.__wbSubmissionValueKey = `${Math.random().toString(36).slice(2)}${Math.random().toString(36).slice(2)}`;
+ }
const identities = window.__wbSubmissionIdentities;
const identityOf = el => {
if (!el || el.nodeType !== 1) return '';
@@ -33395,9 +33404,40 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const submitter = owner && !typedField
? (owner.closest?.('button,input,[role="button"]') || owner)
: defaultButton();
+ const controls = (() => {
+ try {
+ return String(form?.tagName || '').toUpperCase() === 'FORM'
+ ? Array.from(form.elements || [])
+ : Array.from(form?.querySelectorAll?.('input, textarea, select, [contenteditable="true"]') || []);
+ } catch { return []; }
+ })();
+ const valueOf = el => {
+ if (el === pendingEl && pendingValue != null) return String(pendingValue);
+ const type = String(el?.type || '').toLowerCase();
+ if (type === 'checkbox' || type === 'radio') return `${el.checked ? 1 : 0}:${el.value ?? ''}`;
+ if (type === 'file') return Array.from(el.files || []).map(file => [file.name, file.size, file.lastModified, file.type].join(':')).join('|');
+ if (type === 'select-multiple') return Array.from(el.selectedOptions || []).map(option => option.value).join('|');
+ if (el?.isContentEditable && !('value' in el)) return String(el.textContent || '');
+ return String(el?.value ?? '');
+ };
+ const sent = window.__wbSubmissionValueKey + JSON.stringify(controls.map(el => [
+ String(el?.getAttribute?.('name') || ''), String(el?.type || el?.tagName || ''), valueOf(el)]));
+ // cyrb53, a 53-bit string hash; the frame's key makes it opaque.
+ let h1 = 0xdeadbeef;
+ let h2 = 0x41c6ce57;
+ for (let i = 0; i < sent.length; i += 1) {
+ const code = sent.charCodeAt(i);
+ h1 = Math.imul(h1 ^ code, 2654435761);
+ h2 = Math.imul(h2 ^ code, 1597334677);
+ }
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
+ h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
+ h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
+ const values = (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(36);
const formIdentity = identityOf(form);
const submitterIdentity = identityOf(submitter);
- return formIdentity || submitterIdentity ? `${formIdentity}/${submitterIdentity}` : '';
+ return formIdentity || submitterIdentity ? `${formIdentity}/${submitterIdentity}/${values}` : '';
} catch {
return '';
}
@@ -33456,7 +33496,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
reason,
validationSubmitEvidence,
frameDocumentIdentity: [url, performance.timeOrigin].join('|'),
- submissionIdentity: submissionIdentity(form, submitControl),
+ submissionIdentity: submissionIdentity(form, submitControl, pendingEl, pendingValue),
semanticCommit: nativeConfirmationCommit(control),
actionResource: resourceProofFor(control),
resourceBaseline: resourceProofs().map(resource => resource.url),
diff --git a/src/chrome/src/agent/permission-gate.js b/src/chrome/src/agent/permission-gate.js
index d414e24e6..ce43ebd2a 100644
--- a/src/chrome/src/agent/permission-gate.js
+++ b/src/chrome/src/agent/permission-gate.js
@@ -788,12 +788,13 @@ export class PermissionManager {
/**
* A form submission the user declined on WebBrain's own submit card in
* this turn. The agent keys it by submitActionKey() (the form's action,
- * method and changed values, hashed) together with the frame and the form
- * and button elements the page probe identified, so another form or
- * button with the same fields is a different submission. WebBrain does
- * not ask about the same submission again in the turn; a changed value, a
- * new turn, a correction or the user's own answer on a later card asks
- * again.
+ * method and changed values, hashed) together with the frame, the form and
+ * button elements the page probe identified, and the probe's fingerprint of
+ * every value the form would send, so another form or button with the same
+ * fields, or the same form with any value changed, is a different
+ * submission. WebBrain does not ask about the same submission again in the
+ * turn; a changed value, a new turn, a correction or the user's own answer
+ * on a later card asks again.
*/
declineSubmission(key, tabId) {
const normalizedKey = String(key || '');
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 42b0f2d70..9330a6fe5 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -29439,8 +29439,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// control whose form, fields and action it could not read, or one whose
// form and button the page probe did not identify. Two forms can post
// the same visible fields to one endpoint (per-row forms told apart only
- // by hidden IDs), and one form can have several buttons, so the key
- // also names the frame and the form and button elements.
+ // by hidden IDs), one form can have several buttons, and the summary of
+ // changed fields leaves values out, so the key also names the frame, the
+ // form and button elements, and the probe's fingerprint of every value
+ // the form would send.
_declinableSubmissionKey(toolName, submitInfo) {
if (!submitInfo || toolName === 'execute_js' || toolName === 'execute_webmcp_tool') return '';
const resolved = (Array.isArray(submitInfo.changedFields) && submitInfo.changedFields.length > 0)
@@ -30266,18 +30268,25 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
};
const transactionOrderSite = /(?:^|\.)12306\.cn$/i.test(host);
// The form and the button a submission goes through, as identities of
- // the elements this frame holds. A declined submission is remembered by
- // them, so another form or button with the same fields and action
- // (per-row forms told apart only by hidden IDs, Reject beside Approve)
- // still gets its own card. An Enter in a field, or set_field({submit}),
- // submits through the form's default button.
- const submissionIdentity = (form, submitControl) => {
+ // the elements this frame holds, and every value the form would send, as
+ // a fingerprint keyed by a secret that never leaves this frame. A
+ // declined submission is remembered by them, so another form or button
+ // with the same fields and action (per-row forms told apart only by
+ // hidden IDs, Reject beside Approve), or the same form with any value
+ // changed (a field past the summary's first eight, a password, another
+ // file, a hidden record ID), still gets its own card. An Enter in a
+ // field, or set_field({submit}), submits through the form's default
+ // button.
+ const submissionIdentity = (form, submitControl, pendingEl = null, pendingValue = null) => {
try {
if (!(window.__wbSubmissionIdentities instanceof WeakMap)) {
window.__wbSubmissionIdentities = new WeakMap();
window.__wbSubmissionIdentityPrefix = Math.random().toString(36).slice(2, 10);
window.__wbSubmissionIdentityCount = 0;
}
+ if (typeof window.__wbSubmissionValueKey !== 'string' || !window.__wbSubmissionValueKey) {
+ window.__wbSubmissionValueKey = `${Math.random().toString(36).slice(2)}${Math.random().toString(36).slice(2)}`;
+ }
const identities = window.__wbSubmissionIdentities;
const identityOf = el => {
if (!el || el.nodeType !== 1) return '';
@@ -30299,9 +30308,40 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const submitter = owner && !typedField
? (owner.closest?.('button,input,[role="button"]') || owner)
: defaultButton();
+ const controls = (() => {
+ try {
+ return String(form?.tagName || '').toUpperCase() === 'FORM'
+ ? Array.from(form.elements || [])
+ : Array.from(form?.querySelectorAll?.('input, textarea, select, [contenteditable="true"]') || []);
+ } catch { return []; }
+ })();
+ const valueOf = el => {
+ if (el === pendingEl && pendingValue != null) return String(pendingValue);
+ const type = String(el?.type || '').toLowerCase();
+ if (type === 'checkbox' || type === 'radio') return `${el.checked ? 1 : 0}:${el.value ?? ''}`;
+ if (type === 'file') return Array.from(el.files || []).map(file => [file.name, file.size, file.lastModified, file.type].join(':')).join('|');
+ if (type === 'select-multiple') return Array.from(el.selectedOptions || []).map(option => option.value).join('|');
+ if (el?.isContentEditable && !('value' in el)) return String(el.textContent || '');
+ return String(el?.value ?? '');
+ };
+ const sent = window.__wbSubmissionValueKey + JSON.stringify(controls.map(el => [
+ String(el?.getAttribute?.('name') || ''), String(el?.type || el?.tagName || ''), valueOf(el)]));
+ // cyrb53, a 53-bit string hash; the frame's key makes it opaque.
+ let h1 = 0xdeadbeef;
+ let h2 = 0x41c6ce57;
+ for (let i = 0; i < sent.length; i += 1) {
+ const code = sent.charCodeAt(i);
+ h1 = Math.imul(h1 ^ code, 2654435761);
+ h2 = Math.imul(h2 ^ code, 1597334677);
+ }
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
+ h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
+ h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
+ const values = (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(36);
const formIdentity = identityOf(form);
const submitterIdentity = identityOf(submitter);
- return formIdentity || submitterIdentity ? `${formIdentity}/${submitterIdentity}` : '';
+ return formIdentity || submitterIdentity ? `${formIdentity}/${submitterIdentity}/${values}` : '';
} catch {
return '';
}
@@ -30360,7 +30400,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
reason,
validationSubmitEvidence,
frameDocumentIdentity: [url, performance.timeOrigin].join('|'),
- submissionIdentity: submissionIdentity(form, submitControl),
+ submissionIdentity: submissionIdentity(form, submitControl, pendingEl, pendingValue),
semanticCommit: nativeConfirmationCommit(control),
actionResource: resourceProofFor(control),
resourceBaseline: resourceProofs().map(resource => resource.url),
diff --git a/src/firefox/src/agent/permission-gate.js b/src/firefox/src/agent/permission-gate.js
index 2e0aa3a1a..e9516363b 100644
--- a/src/firefox/src/agent/permission-gate.js
+++ b/src/firefox/src/agent/permission-gate.js
@@ -773,12 +773,13 @@ export class PermissionManager {
/**
* A form submission the user declined on WebBrain's own submit card in
* this turn. The agent keys it by submitActionKey() (the form's action,
- * method and changed values, hashed) together with the frame and the form
- * and button elements the page probe identified, so another form or
- * button with the same fields is a different submission. WebBrain does
- * not ask about the same submission again in the turn; a changed value, a
- * new turn, a correction or the user's own answer on a later card asks
- * again.
+ * method and changed values, hashed) together with the frame, the form and
+ * button elements the page probe identified, and the probe's fingerprint of
+ * every value the form would send, so another form or button with the same
+ * fields, or the same form with any value changed, is a different
+ * submission. WebBrain does not ask about the same submission again in the
+ * turn; a changed value, a new turn, a correction or the user's own answer
+ * on a later card asks again.
*/
declineSubmission(key, tabId) {
const normalizedKey = String(key || '');
diff --git a/test/declined-submission-identity.mjs b/test/declined-submission-identity.mjs
index 4952d4c92..bd59596a4 100644
--- a/test/declined-submission-identity.mjs
+++ b/test/declined-submission-identity.mjs
@@ -1,9 +1,10 @@
// A submission the user declined is remembered for the rest of the turn by
-// the page elements it goes through, as the submit probe identifies them:
-// the form and its button. Per-row forms that post the same visible fields to
-// one endpoint, told apart only by hidden IDs, and two buttons of one form are
-// different submissions. The same form and button, clicked again or reached
-// by an Enter in the form's field, is the same submission.
+// what the submit probe identifies it by: the form, its button, and a
+// fingerprint of every value the form would send. Per-row forms that post the
+// same visible fields to one endpoint, told apart only by hidden IDs, two
+// buttons of one form, and the same form with any value changed are different
+// submissions. The same form, button and values, clicked again or reached by
+// an Enter in the form's field, is the same submission.
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { chromium, firefox } from 'playwright';
@@ -54,6 +55,26 @@ for (const build of ['chrome', 'firefox']) {
assert.equal(enter?.isSubmit, true);
assert.equal(enter.submissionIdentity, save.submissionIdentity, 'an Enter in the field submits through the first button');
});
+
+ await t.test('any value the form sends changes the fingerprint, and none is shown', async () => {
+ await page.setContent('<form method="post" action="/profile">'
+ + Array.from({ length: 10 }, (_, i) => `<input name="f${i}" aria-label="Field ${i}" value="v${i}">`).join('')
+ + '<input type="password" name="pw" aria-label="Password" value="first-secret">'
+ + '<input type="hidden" name="record" value="41"><button id="go">Save</button></form>');
+ const before = await probe('click', { selector: '#go' });
+ assert.equal(before?.isSubmit, true);
+ assert.match(before.submissionIdentity, /^[a-z0-9]+\.\d+\/[a-z0-9]+\.\d+\/[a-z0-9]+$/, 'element identities and an opaque fingerprint');
+ assert.equal((await probe('click', { selector: '#go' })).submissionIdentity, before.submissionIdentity, 'nothing changed');
+ // A tenth field (past the summary's first eight), a password and a
+ // hidden record ID each make it a different submission.
+ for (const [selector, value] of [['[name=f9]', 'changed'], ['[name=pw]', 'second-secret'], ['[name=record]', '42']]) {
+ const previous = (await probe('click', { selector: '#go' })).submissionIdentity;
+ await page.evaluate(([target, text]) => { document.querySelector(target).value = text; }, [selector, value]);
+ const after = await probe('click', { selector: '#go' });
+ assert.notEqual(after.submissionIdentity, previous, `a change to ${selector}`);
+ assert.equal(after.submissionIdentity.split('/').slice(0, 2).join('/'), previous.split('/').slice(0, 2).join('/'), 'the same form and button');
+ }
+ });
} finally {
await browser.close();
}