Skip to content

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

fix(agent): verbatim message digest, terminal path rawValue

Emre Sokullu5ba48dcd0382
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index db6a03a60..2a3d5a3ad 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -1746,7 +1746,13 @@ export class Agent extends LoopDetector {
: null;
const commitMessageRequirement = metadataRequirements
.find(requirement => requirement?.field === 'commit_message');
- const expectedCommitMessage = this._workflowMetadataValue(commitMessageRequirement?.value);
+ // Verbatim requirement text: the digest gate must hash what was asked
+ // for, not its NFKC fold — otherwise an exact write is blocked while a
+ // normalized rewrite could commit different bytes. Mirrors the byte-exact
+ // path scope handling. Absent rawValue means verbatim equals normalized.
+ const expectedCommitMessage = commitMessageRequirement
+ ? String(commitMessageRequirement.rawValue ?? commitMessageRequirement.value ?? '')
+ : '';
// Collision-resistant comparison: replacement records already carry a
// SHA-256 digest, so require it here too. A 32-bit FNV-1a fingerprint
// collides practically (e.g. 'PSgOcTcQ' vs '9SHghNQJ'), which would set
@@ -2588,7 +2594,10 @@ export class Agent extends LoopDetector {
const metadataMatched = binding?.metadataRequirementsIncomplete !== true
&& requirements.every(requirement => {
if (requirement?.field === 'path') {
- return String(requirement.value || '').replace(/^\/+/, '') === binding?.githubFileCommit?.path;
+ // Byte-exact like the scope parser: the bound path was resolved
+ // against the verbatim request text.
+ const raw = typeof requirement.rawValue === 'string' ? requirement.rawValue : requirement.value;
+ return String(raw || '').replace(/^\/+/, '') === binding?.githubFileCommit?.path;
}
if (requirement?.field === 'branch') {
return this._workflowMetadataValue(requirement.value) === this._workflowMetadataValue(
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 31ebe2ff1..929dc4577 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -1460,7 +1460,13 @@ export class Agent extends LoopDetector {
: null;
const commitMessageRequirement = metadataRequirements
.find(requirement => requirement?.field === 'commit_message');
- const expectedCommitMessage = this._workflowMetadataValue(commitMessageRequirement?.value);
+ // Verbatim requirement text: the digest gate must hash what was asked
+ // for, not its NFKC fold — otherwise an exact write is blocked while a
+ // normalized rewrite could commit different bytes. Mirrors the byte-exact
+ // path scope handling. Absent rawValue means verbatim equals normalized.
+ const expectedCommitMessage = commitMessageRequirement
+ ? String(commitMessageRequirement.rawValue ?? commitMessageRequirement.value ?? '')
+ : '';
// Collision-resistant comparison: replacement records already carry a
// SHA-256 digest, so require it here too. A 32-bit FNV-1a fingerprint
// collides practically (e.g. 'PSgOcTcQ' vs '9SHghNQJ'), which would set
@@ -2302,7 +2308,10 @@ export class Agent extends LoopDetector {
const metadataMatched = binding?.metadataRequirementsIncomplete !== true
&& requirements.every(requirement => {
if (requirement?.field === 'path') {
- return String(requirement.value || '').replace(/^\/+/, '') === binding?.githubFileCommit?.path;
+ // Byte-exact like the scope parser: the bound path was resolved
+ // against the verbatim request text.
+ const raw = typeof requirement.rawValue === 'string' ? requirement.rawValue : requirement.value;
+ return String(raw || '').replace(/^\/+/, '') === binding?.githubFileCommit?.path;
}
if (requirement?.field === 'branch') {
return this._workflowMetadataValue(requirement.value) === this._workflowMetadataValue(
diff --git a/test/run.js b/test/run.js
index 0a1dc5da6..4da19be21 100644
--- a/test/run.js
+++ b/test/run.js
@@ -75790,6 +75790,113 @@ test('edit-file scope keeps Git paths byte-exact', () => {
}
});
+test('commit gate hashes the verbatim message text', async () => {
+ for (const [label, AgentClass, resolveJob, tabId] of [
+ ['chrome', AgentCh, resolveAdapterWorkflowJob, 9514],
+ ['firefox', AgentFx, resolveAdapterWorkflowJobFx, 9515],
+ ]) {
+ 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: [{ field: 'commit_message', value: 'A', rawValue: 'A' }],
+ workflowMetadataRequirementsResolved: true,
+ });
+ agent._taskTokens.set(tabId, 'task-verbatim');
+ const body = '# Doc\n';
+ const bodySha256 = await agent._sha256Text(body);
+ const editorRecord = {
+ key: 'ax:doc:ref_editor',
+ locatorType: 'ax',
+ refId: 'ref_editor',
+ documentToken: 'doc',
+ pageUrl,
+ ambiguous: false,
+ expectedLength: body.length,
+ expectedSha256: bodySha256,
+ expectedFp: agent._workflowInventoryFingerprint(body),
+ fieldMeta: { contentEditable: true, ariaLabelledByText: 'Editing file contents' },
+ readbackLength: body.length,
+ readbackSha256: bodySha256,
+ verifiedAt: Date.now(),
+ taskToken: 'task-verbatim',
+ };
+ const messageRecordFor = async (text) => ({
+ key: 'ax:doc:ref_msg',
+ locatorType: 'ax',
+ refId: 'ref_msg',
+ documentToken: 'doc',
+ pageUrl,
+ ambiguous: false,
+ expectedLength: text.length,
+ expectedSha256: await agent._sha256Text(text),
+ expectedFp: agent._workflowInventoryFingerprint(text),
+ fieldMeta: { id: 'commit-message-input', name: 'commit-message-input' },
+ readbackLength: text.length,
+ readbackSha256: await agent._sha256Text(text),
+ verifiedAt: Date.now(),
+ taskToken: 'task-verbatim',
+ });
+ // An exact write of the verbatim request authorizes.
+ agent._verifiedTextReplacements.set(tabId, new Map([
+ ['ax:doc:ref_editor', editorRecord],
+ ['ax:doc:ref_msg', await messageRecordFor('A')],
+ ]));
+ assert.ok(agent._workflowSubmitBindingForAttempt(tabId, pageUrl, {})?.githubFileCommit,
+ `${label}: exact verbatim commit message did not authorize`);
+ // The NFKC fold is different bytes from the request: must not.
+ agent._verifiedTextReplacements.set(tabId, new Map([
+ ['ax:doc:ref_editor', editorRecord],
+ ['ax:doc:ref_msg', await messageRecordFor('A')],
+ ]));
+ assert.equal(agent._workflowSubmitBindingForAttempt(tabId, pageUrl, {})?.githubFileCommit, undefined,
+ `${label}: normalized rewrite authorized a different message`);
+ }
+});
+
+test('terminal path match compares verbatim request text', async () => {
+ for (const [label, AgentClass, tabId] of [
+ ['chrome', AgentCh, 9516],
+ ['firefox', AgentFx, 9517],
+ ]) {
+ const agent = new AgentClass({});
+ const body = '# Normalized path document\n\nOne complete copy.\n';
+ const sha = await agent._sha256Text(body);
+ const state = { siteWorkflow: { adapterName: 'github', job: { id: 'edit-file-and-commit' } } };
+ const commitUrl = 'https://github.com/Example/Repo/commit/0123456789abcdef0123456789abcdef01234567';
+ const bindingFor = (requirements) => ({
+ metadataRequirements: requirements,
+ githubFileCommit: {
+ repository: 'example/repo',
+ branch: 'main',
+ path: 'A.txt',
+ expectedLength: body.length,
+ expectedSha256: sha,
+ commitMessageVerified: true,
+ },
+ });
+ const pageState = {
+ githubCommittedFileVerification: {
+ verified: true,
+ repository: 'example/repo',
+ path: 'A.txt',
+ expectedSha256: sha,
+ },
+ };
+ // Verbatim request matches the byte-exact bound path.
+ assert.equal(agent._workflowPublishedResourcePayloadMatch(
+ bindingFor([{ field: 'path', value: 'A.txt', rawValue: 'A.txt' }]),
+ state, pageState, commitUrl, {},
+ ), true, `${label}: verbatim path did not match the bound blob`);
+ // A genuinely different path still reports missing evidence.
+ assert.equal(agent._workflowPublishedResourcePayloadMatch(
+ bindingFor([{ field: 'path', value: 'other.md', rawValue: 'other.md' }]),
+ state, pageState, commitUrl, {},
+ ), false, `${label}: mismatched path reported evidence`);
+ }
+});
+
test('GitHub edit-file workflow verifies the exact committed raw blob', async () => {
const originalFetch = globalThis.fetch;
const body = '# Corrected document\n\nOne complete copy.\n';