Skip to content

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

fix(agent): editor-specific commit identity, selector distinctness escape

Emre Sokullucea882325f69
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index ccf185475..f459d9626 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -1704,6 +1704,15 @@ export class Agent extends LoopDetector {
// one identity).
const activeTaskToken = this._taskTokens.get(tabId);
const activeTaskTokenValid = typeof activeTaskToken === 'string' && activeTaskToken.length > 0;
+ // Editor identity must be GitHub-specific: the file editor exposes an
+ // accessible "Editing file contents" linkage (labelledby text, label, or
+ // wrapping label). A bare contentEditable flag is not enough β€” any other
+ // contenteditable on the edit route could otherwise mint a commit while
+ // the real editor still holds stale content. Records store the live
+ // digest metadata, so legit flows always carry the linkage.
+ const isGithubFileEditor = (record) => /\bediting\b[\s\S]*\bfile contents\b/i.test(String(
+ record?.fieldMeta?.ariaLabelledByText || record?.fieldMeta?.ariaLabel || record?.fieldMeta?.labelText || '',
+ ));
const githubEditorReplacements = replacementRecordValues
.filter(record => record?.ambiguous !== true
&& activeTaskTokenValid
@@ -1711,9 +1720,7 @@ export class Agent extends LoopDetector {
&& !!record?.expectedSha256
&& !!record?.readbackSha256
&& this._normalizeUrl(record.pageUrl || '') === this._normalizeUrl(pageUrl)
- && (record?.fieldMeta?.contentEditable === true
- || /contenteditable/i.test(String(record?.key || ''))
- || /\bediting\b[\s\S]*\bfile contents\b/i.test(String(record?.fieldMeta?.ariaLabelledByText || ''))));
+ && isGithubFileEditor(record));
const githubEditorPayloads = new Set(githubEditorReplacements
.map(record => `${record.expectedLength}:${record.expectedSha256}`));
const verifiedReplacement = githubEditorPayloads.size === 1
@@ -20550,6 +20557,17 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
} catch { /* an unavailable probe cannot prove that this is a different field */ }
return axReadback;
};
+ let selectorReadback = null;
+ let selectorReadbackAttempted = false;
+ const readSelectorTarget = async () => {
+ if (selectorReadbackAttempted) return selectorReadback;
+ selectorReadbackAttempted = true;
+ if (!(name === 'type_text' && typeof args.selector === 'string' && args.selector.trim())) return null;
+ try {
+ selectorReadback = await this._textMutationValueDigest(tabId, target);
+ } catch { /* an unavailable probe cannot prove that this is a different field */ }
+ return selectorReadback;
+ };
let debt = null;
for (const candidate of debts.values()) {
if (candidate.ambiguous || target.ambiguous || candidate.key === target.key) {
@@ -20564,6 +20582,20 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (readback?.success === true
&& this._textMutationFieldsProvenDistinct(candidate.fieldMeta, readback.fieldMeta)) continue;
}
+ // Mirror the AX escape hatch for selector pairs: the digest probe can
+ // read the target's live metadata, so a demonstrably different field
+ // (two or more differing identity fields, no shared one) must not be
+ // blocked by another field's debt. The debt is kept β€” only this
+ // dispatch is allowed β€” and an unprovable target stays blocked.
+ const distinctSelectors = candidate.locatorType === 'selector'
+ && target.locatorType === 'selector'
+ && typeof candidate.selector === 'string'
+ && typeof target.selector === 'string'
+ && candidate.selector !== target.selector;
+ if (distinctSelectors) {
+ const readback = await readSelectorTarget();
+ if (readback && this._textMutationFieldsProvenDistinct(candidate.fieldMeta, readback.fieldMeta)) continue;
+ }
debt = candidate;
break;
}
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index a83920fb9..7719d32fd 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -1418,6 +1418,15 @@ export class Agent extends LoopDetector {
// one identity).
const activeTaskToken = this._taskTokens.get(tabId);
const activeTaskTokenValid = typeof activeTaskToken === 'string' && activeTaskToken.length > 0;
+ // Editor identity must be GitHub-specific: the file editor exposes an
+ // accessible "Editing file contents" linkage (labelledby text, label, or
+ // wrapping label). A bare contentEditable flag is not enough β€” any other
+ // contenteditable on the edit route could otherwise mint a commit while
+ // the real editor still holds stale content. Records store the live
+ // digest metadata, so legit flows always carry the linkage.
+ const isGithubFileEditor = (record) => /\bediting\b[\s\S]*\bfile contents\b/i.test(String(
+ record?.fieldMeta?.ariaLabelledByText || record?.fieldMeta?.ariaLabel || record?.fieldMeta?.labelText || '',
+ ));
const githubEditorReplacements = replacementRecordValues
.filter(record => record?.ambiguous !== true
&& activeTaskTokenValid
@@ -1425,9 +1434,7 @@ export class Agent extends LoopDetector {
&& !!record?.expectedSha256
&& !!record?.readbackSha256
&& this._normalizeUrl(record.pageUrl || '') === this._normalizeUrl(pageUrl)
- && (record?.fieldMeta?.contentEditable === true
- || /contenteditable/i.test(String(record?.key || ''))
- || /\bediting\b[\s\S]*\bfile contents\b/i.test(String(record?.fieldMeta?.ariaLabelledByText || ''))));
+ && isGithubFileEditor(record));
const githubEditorPayloads = new Set(githubEditorReplacements
.map(record => `${record.expectedLength}:${record.expectedSha256}`));
const verifiedReplacement = githubEditorPayloads.size === 1
@@ -18121,6 +18128,17 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
} catch { /* an unavailable probe cannot prove that this is a different field */ }
return axReadback;
};
+ let selectorReadback = null;
+ let selectorReadbackAttempted = false;
+ const readSelectorTarget = async () => {
+ if (selectorReadbackAttempted) return selectorReadback;
+ selectorReadbackAttempted = true;
+ if (!(name === 'type_text' && typeof args.selector === 'string' && args.selector.trim())) return null;
+ try {
+ selectorReadback = await this._textMutationValueDigest(tabId, target);
+ } catch { /* an unavailable probe cannot prove that this is a different field */ }
+ return selectorReadback;
+ };
let debt = null;
for (const candidate of debts.values()) {
if (candidate.ambiguous || target.ambiguous || candidate.key === target.key) {
@@ -18135,6 +18153,20 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (readback?.success === true
&& this._textMutationFieldsProvenDistinct(candidate.fieldMeta, readback.fieldMeta)) continue;
}
+ // Mirror the AX escape hatch for selector pairs: the digest probe can
+ // read the target's live metadata, so a demonstrably different field
+ // (two or more differing identity fields, no shared one) must not be
+ // blocked by another field's debt. The debt is kept β€” only this
+ // dispatch is allowed β€” and an unprovable target stays blocked.
+ const distinctSelectors = candidate.locatorType === 'selector'
+ && target.locatorType === 'selector'
+ && typeof candidate.selector === 'string'
+ && typeof target.selector === 'string'
+ && candidate.selector !== target.selector;
+ if (distinctSelectors) {
+ const readback = await readSelectorTarget();
+ if (readback && this._textMutationFieldsProvenDistinct(candidate.fieldMeta, readback.fieldMeta)) continue;
+ }
debt = candidate;
break;
}
diff --git a/test/run.js b/test/run.js
index 551b4af8b..7d8678285 100644
--- a/test/run.js
+++ b/test/run.js
@@ -74825,7 +74825,7 @@ test('GitHub edit-file workflow verifies the exact committed raw blob', async ()
documentToken: 'doc',
pageUrl: editUrl,
ambiguous: false,
- fieldMeta: { contentEditable: true },
+ fieldMeta: { contentEditable: true, ariaLabelledByText: 'Editing file contents' },
expectedLength: duplicate.length,
expectedSha256: await agent._sha256Text(duplicate),
readbackLength: duplicate.length,
@@ -75549,6 +75549,128 @@ test('focused proofs revalidate through element-derived locators', async () => {
}
});
+test('commit gate requires editor-specific identity', async () => {
+ for (const [label, AgentClass, resolveJob, tabId] of [
+ ['chrome', AgentCh, resolveAdapterWorkflowJob, 9498],
+ ['firefox', AgentFx, resolveAdapterWorkflowJobFx, 9499],
+ ]) {
+ const agent = new AgentClass({});
+ const pageUrl = 'https://github.com/Example/Repo/edit/main/docs/plan.md';
+ agent._planExecutionGuards.set(tabId, {
+ enabled: true,
+ siteWorkflow: resolveJob(pageUrl, 'edit-file-and-commit'),
+ workflowMetadataRequirements: [],
+ workflowMetadataRequirementsResolved: true,
+ });
+ agent._taskTokens.set(tabId, 'task-identity');
+ const body = '# Doc\n';
+ const bodySha256 = await agent._sha256Text(body);
+ const recordFor = (key, fieldMeta) => ({
+ key,
+ locatorType: 'ax',
+ refId: 'ref_x',
+ documentToken: 'doc',
+ pageUrl,
+ ambiguous: false,
+ expectedLength: body.length,
+ expectedSha256: bodySha256,
+ expectedFp: agent._workflowInventoryFingerprint(body),
+ fieldMeta,
+ readbackLength: body.length,
+ readbackSha256: bodySha256,
+ verifiedAt: Date.now(),
+ taskToken: 'task-identity',
+ });
+ // Linked editor proof authorizes.
+ agent._verifiedTextReplacements.set(tabId, new Map([
+ ['ax:doc:ref_editor', recordFor('ax:doc:ref_editor',
+ { contentEditable: true, ariaLabelledByText: 'Editing file contents' })],
+ ]));
+ assert.ok(agent._workflowSubmitBindingForAttempt(tabId, pageUrl, {})?.githubFileCommit,
+ `${label}: linked editor proof did not authorize`);
+ // Bare contentEditable with no linkage must not: it could be any other
+ // contenteditable on the edit route.
+ agent._verifiedTextReplacements.set(tabId, new Map([
+ ['ax:doc:ref_other', recordFor('ax:doc:ref_other', { contentEditable: true })],
+ ]));
+ assert.equal(agent._workflowSubmitBindingForAttempt(tabId, pageUrl, {})?.githubFileCommit, undefined,
+ `${label}: an unlinked contenteditable authorized a commit`);
+ // A contenteditable-looking key alone must not either.
+ agent._verifiedTextReplacements.set(tabId, new Map([
+ ['selector:doc:[contenteditable="true"]', recordFor('selector:doc:[contenteditable="true"]',
+ { contentEditable: true, id: 'comment-box' })],
+ ]));
+ assert.equal(agent._workflowSubmitBindingForAttempt(tabId, pageUrl, {})?.githubFileCommit, undefined,
+ `${label}: a key-substring contenteditable authorized a commit`);
+ }
+});
+
+test('selector writes to proven-distinct fields bypass unrelated debt', async () => {
+ const originalChrome = globalThis.chrome;
+ const originalBrowser = globalThis.browser;
+ try {
+ const pageUrl = 'https://example.test/form';
+ const fieldMetaA = { id: 'field-a', name: 'field-a', labelText: 'First' };
+ // Demonstrably different field: two differing identity fields, none shared.
+ const fieldMetaB = { id: 'field-b', name: 'field-b', labelText: 'Second' };
+ // Same label: shares one identity field, so not provably distinct.
+ const fieldMetaC = { id: 'field-c', name: 'field-c', labelText: 'First' };
+ for (const [label, AgentClass, tabId, controlTabId] of [
+ ['chrome', AgentCh, 9500, 9502],
+ ['firefox', AgentFx, 9501, 9503],
+ ]) {
+ const agent = new AgentClass({});
+ agent._lastAxScopes.set(tabId, { documentToken: 'doc-multi', pageUrl });
+ const tabs = {
+ async sendMessage(_tabId, message) {
+ const selector = message.params?.selector;
+ if (selector === '#a') {
+ return { success: false, documentToken: 'doc-multi', refScopeUrl: pageUrl };
+ }
+ if (selector === '#b') {
+ return { success: true, valueLength: 3, valueSha256: 'b'.repeat(64), fieldMeta: fieldMetaB };
+ }
+ if (selector === '#c') {
+ return { success: true, valueLength: 3, valueSha256: 'c'.repeat(64), fieldMeta: fieldMetaC };
+ }
+ return { success: false, documentToken: 'doc-multi', refScopeUrl: pageUrl };
+ },
+ };
+ globalThis.chrome = { tabs };
+ globalThis.browser = { tabs };
+ await agent._finalizeTextMutationResult(
+ tabId, 'type_text', { selector: '#a', text: 'alpha', clear: true },
+ { success: false, dispatched: true, verified: false, fieldMeta: fieldMetaA },
+ );
+ assert.equal(agent._uncertainTextMutations.get(tabId)?.size, 1, `${label}: debt was not recorded`);
+ // Provably different field: allowed, and the original debt is kept.
+ const allowed = await agent._uncertainTextMutationBlock(
+ tabId, 'type_text', { selector: '#b', text: 'beta' },
+ );
+ assert.equal(allowed, null, `${label}: distinct selector field stayed blocked by unrelated debt`);
+ assert.equal(agent._uncertainTextMutations.get(tabId)?.size, 1,
+ `${label}: distinct-field dispatch dropped the original debt`);
+ // Shared identity field: fail-closed, still blocked.
+ const control = new AgentClass({});
+ control._lastAxScopes.set(controlTabId, { documentToken: 'doc-multi', pageUrl });
+ await control._finalizeTextMutationResult(
+ controlTabId, 'type_text', { selector: '#a', text: 'alpha', clear: true },
+ { success: false, dispatched: true, verified: false, fieldMeta: fieldMetaA },
+ );
+ const blocked = await control._uncertainTextMutationBlock(
+ controlTabId, 'type_text', { selector: '#c', text: 'gamma' },
+ );
+ assert.equal(blocked?.repeatBlocked, true,
+ `${label}: unprovable selector field escaped the debt guard`);
+ }
+ } finally {
+ if (originalChrome === undefined) delete globalThis.chrome;
+ else globalThis.chrome = originalChrome;
+ if (originalBrowser === undefined) delete globalThis.browser;
+ else globalThis.browser = originalBrowser;
+ }
+});
+
test('focused field_value_digest and live scope cover selectorless writes', async () => {
for (const rel of [
'src/chrome/src/content/content.js',