Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Keep the deletion guard for destructive GET links
Claude507d575b8daa
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 1ed108bce..bb4981f3f 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -29835,14 +29835,30 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai};const deleteAction = value => /(?:^|[^\p{L}])(?:delete|remove|trash|erase|destroy|sil|kaldır|supprimer|eliminar|borrar|löschen|удалить|åˆ é™¤|刪除|削除|ì‚ì œ)(?:[^\p{L}]|$)/iu.test(String(value || '').trim());const deletionCaption = value => deleteAction(withoutViewStateRemoval(value));+ // A GET link whose query names a destructive action (WordPress+ // action=trash, admin panels' action=delete, _method=DELETE) mutates+ // when followed. Path segments such as /trash or /delete/ usually name a+ // folder or a confirmation page, so they stay navigation.+ const destructiveLinkQuery = link => {+ try {+ const destructive = /^(?:delete|destroy|remove|trash|erase|purge)(?:$|[._-])/i;+ for (const [name, value] of new URL(link.href).searchParams) {+ if (/^(?:delete|destroy|remove|trash|erase|purge)$/i.test(name)) return true;+ if (/^(?:action|do|op|operation|task|cmd|command|act|a|_method|method|mode)$/i.test(name) && destructive.test(value)) return true;+ }+ } catch {}+ return false;+ };// A link with a real destination navigates even when its caption names// a folder such as Trash. A placeholder href or an explicit button role- // marks a scripted command drawn as a link, which keeps its caption.+ // marks a scripted command drawn as a link, which keeps its caption, as+ // does a link whose query performs a destructive action.const navigationOwnsActivation = (() => {const link = target && ['click', 'click_ax', 'iframe_click'].includes(toolName) ? navigationLinkFor(target) : null;if (!link) return false;return !String(link.getAttribute('href') || '').trim().startsWith('#')- && String(link.getAttribute('role') || '').toLowerCase() !== 'button';+ && String(link.getAttribute('role') || '').toLowerCase() !== 'button'+ && !destructiveLinkQuery(link);})();if (control && ['click', 'click_ax', 'iframe_click'].includes(toolName)&& nativeResourceVisible(control) && !control.disabled && control.getAttribute('aria-disabled') !== 'true'@@ -31241,6 +31257,8 @@ If the user has already named or confirmed this exact recipient, do NOT ask agaithis._lastCdpClickIdent?.delete(tabId);this._lastClickProgress?.delete(tabId);this._clickAxCdpFallbacks?.delete(tabId);+ // Task-scoped click locks: a cleared conversation starts a new task anyway.+ this._taskClickLocks?.delete(tabId);this.progressPageScopes.delete(tabId);this.progressSessions.delete(tabId);this.progressExpectedItems.delete(tabId);diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex baf0e8293..a064fa9d2 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -27187,14 +27187,30 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d};const deleteAction = value => /(?:^|[^\p{L}])(?:delete|remove|trash|erase|destroy|sil|kaldır|supprimer|eliminar|borrar|löschen|удалить|åˆ é™¤|刪除|削除|ì‚ì œ)(?:[^\p{L}]|$)/iu.test(String(value || '').trim());const deletionCaption = value => deleteAction(withoutViewStateRemoval(value));+ // A GET link whose query names a destructive action (WordPress+ // action=trash, admin panels' action=delete, _method=DELETE) mutates+ // when followed. Path segments such as /trash or /delete/ usually name a+ // folder or a confirmation page, so they stay navigation.+ const destructiveLinkQuery = link => {+ try {+ const destructive = /^(?:delete|destroy|remove|trash|erase|purge)(?:$|[._-])/i;+ for (const [name, value] of new URL(link.href).searchParams) {+ if (/^(?:delete|destroy|remove|trash|erase|purge)$/i.test(name)) return true;+ if (/^(?:action|do|op|operation|task|cmd|command|act|a|_method|method|mode)$/i.test(name) && destructive.test(value)) return true;+ }+ } catch {}+ return false;+ };// A link with a real destination navigates even when its caption names// a folder such as Trash. A placeholder href or an explicit button role- // marks a scripted command drawn as a link, which keeps its caption.+ // marks a scripted command drawn as a link, which keeps its caption, as+ // does a link whose query performs a destructive action.const navigationOwnsActivation = (() => {const link = target && ['click', 'click_ax', 'iframe_click'].includes(toolName) ? navigationLinkFor(target) : null;if (!link) return false;return !String(link.getAttribute('href') || '').trim().startsWith('#')- && String(link.getAttribute('role') || '').toLowerCase() !== 'button';+ && String(link.getAttribute('role') || '').toLowerCase() !== 'button'+ && !destructiveLinkQuery(link);})();if (control && ['click', 'click_ax', 'iframe_click'].includes(toolName)&& nativeResourceVisible(control) && !control.disabled && control.getAttribute('aria-disabled') !== 'true'diff --git a/test/guards-control-classification.mjs b/test/guards-control-classification.mjsindex 95db69371..b4f530f92 100644--- a/test/guards-control-classification.mjs+++ b/test/guards-control-classification.mjs@@ -86,6 +86,10 @@ for (const build of ['chrome', 'firefox']) {({ detected, block } = await gate(f, 'click_ax', { ref_id: await ref('t') }));assert.equal(detected?.resolvedNavigationTarget, true, 'Trash folder link');assert.equal(block, null);+ f = await setup('https://mail.example/inbox', '<nav><a role="menuitem" href="/mail?folder=inbox">Inbox</a> <a id="t" role="menuitem" href="/mail?folder=trash">Trash</a></nav>', { steering, gate: { requiresStateChange: false } });+ ({ detected, block } = await gate(f, 'click_ax', { ref_id: await ref('t') }));+ assert.equal(detected?.resolvedNavigationTarget, true, 'Trash folder selected by query');+ assert.equal(block, null);f = await setup('https://mail.example/compose', '<section><textarea aria-label="Body">Hi Bob</textarea><div class="attachment"><span>report.pdf</span><button id="t" type="button" aria-label="Remove attachment">×</button></div><button type="button">Send</button></section>', { steering });({ detected, block } = await gate(f, 'click_ax', { ref_id: await ref('t') }));assert.equal(detected?.resolvedDraftControl, true, 'draft attachment');@@ -99,6 +103,9 @@ for (const build of ['chrome', 'firefox']) {['https://admin.example/users', '<table><tr><td>[email protected]</td><td><button id="t" type="button">Delete</button></td></tr></table>'],['https://mail.example/msg/42', '<div role="toolbar"><div id="t" role="button" tabindex="0" aria-label="Delete">🗑</div></div><h2>Subject</h2>'],['https://app.example/items', '<ul><li>Item <a id="t" role="button" href="#">Delete</a></li></ul>'],+ // A GET link whose query performs the deletion keeps its caption.+ ['https://blog.example/wp-admin/edit.php', '<ul><li>Post 1 <span role="menu"><a id="t" role="menuitem" href="/wp-admin/post.php?post=1&action=trash&_wpnonce=abc">Trash</a></span></li></ul>'],+ ['https://admin.example/list', '<ul><li>Row 5 <span role="menu"><a id="t" role="menuitem" href="/admin.php?do=delete_row&id=5">Delete</a></span></li></ul>'],['https://notes.example/', '<section><textarea aria-label="New note"></textarea><div class="note"><p>Buy milk</p><button id="t" type="button">Remove</button></div></section>'],['https://app.example/settings', '<dialog open><form method="dialog"><p>Delete this item?</p><button value="cancel">Cancel</button><button id="t" value="confirm">Delete</button></form></dialog>'],]) {