Skip to content

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

fix(guard): validate recipient semantics on displayed question regardless of declared purpose

Emre Sokullu7a50628a5941
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index bf5cd18f8..372a7fd06 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -17899,20 +17899,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
_isRecipientClarification(context, pendingType = 'message_recipient', observedCandidates = []) {
if (!context || typeof context !== 'object') return false;
const purpose = String(context.purpose || '').trim();
+ if (purpose === 'research_escalation') return false;
+
+ const questionText = [
+ context.question,
+ ...(Array.isArray(context.options) ? context.options : []),
+ ].filter(Boolean).join(' ').toLowerCase();
+
if (pendingType === 'recipient_change') {
- if (purpose === 'recipient_change') return true;
- if (purpose === 'research_escalation') return false;
- const text = [
- context.question,
- context.reason,
- ...(Array.isArray(context.options) ? context.options : []),
- ].filter(Boolean).join(' ').toLowerCase();
- const changeWord = /(change|switch|different|instead|update|replace|another|new|更改|更换|切换|替换|换成)/i.test(text);
- const targetWord = /(recipient|conversation|contact|send to|person|address|target|someone else|\b(?:to|cc|bcc|role|field)\b|收件人|联系人|发送)/i.test(text);
+ const changeWord = /(change|switch|different|instead|update|replace|another|new|更改|更换|切换|替换|换成)/i.test(questionText);
+ const targetWord = /(recipient|conversation|contact|send to|person|address|target|someone else|\b(?:to|cc|bcc|role|field)\b|收件人|联系人|发送)/i.test(questionText);
return changeWord && targetWord;
}
- if (purpose === 'message_recipient' || purpose === 'recipient_change') return true;
- if (purpose === 'research_escalation') return false;
// Check if the clarify question, reason, or options explicitly mention any observed candidate identity or alias
if (Array.isArray(observedCandidates) && observedCandidates.length > 0) {
@@ -17933,16 +17931,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
}
- const text = [
- context.question,
- context.reason,
- ...(Array.isArray(context.options) ? context.options : []),
- ].filter(Boolean).join(' ').toLowerCase();
-
- if (/recipient|收件人/i.test(text)) return true;
+ if (/recipient|收件人/i.test(questionText)) return true;
- const hasRecipientTerm = /(contact|person|address|who|whom|which contact|which person|which recipient|which user|which address|to whom|for whom|someone|联系人|哪位|谁)/i.test(text);
- const hasMessagingTerm = /(send|receive|deliver|message|email|mail|draft|reply|chat|conversation|发送|邮件|信息|消息|寄|回复)/i.test(text);
+ const hasRecipientTerm = /(contact|person|address|who|whom|which contact|which person|which recipient|which user|which address|to whom|for whom|someone|联系人|哪位|谁)/i.test(questionText);
+ const hasMessagingTerm = /(send|receive|deliver|message|email|mail|draft|reply|chat|conversation|发送|邮件|信息|消息|寄|回复)/i.test(questionText);
return hasRecipientTerm && hasMessagingTerm;
}
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 5a480f418..8d9a0c9a8 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -15652,20 +15652,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
_isRecipientClarification(context, pendingType = 'message_recipient', observedCandidates = []) {
if (!context || typeof context !== 'object') return false;
const purpose = String(context.purpose || '').trim();
+ if (purpose === 'research_escalation') return false;
+
+ const questionText = [
+ context.question,
+ ...(Array.isArray(context.options) ? context.options : []),
+ ].filter(Boolean).join(' ').toLowerCase();
+
if (pendingType === 'recipient_change') {
- if (purpose === 'recipient_change') return true;
- if (purpose === 'research_escalation') return false;
- const text = [
- context.question,
- context.reason,
- ...(Array.isArray(context.options) ? context.options : []),
- ].filter(Boolean).join(' ').toLowerCase();
- const changeWord = /(change|switch|different|instead|update|replace|another|new|更改|更换|切换|替换|换成)/i.test(text);
- const targetWord = /(recipient|conversation|contact|send to|person|address|target|someone else|\b(?:to|cc|bcc|role|field)\b|收件人|联系人|发送)/i.test(text);
+ const changeWord = /(change|switch|different|instead|update|replace|another|new|更改|更换|切换|替换|换成)/i.test(questionText);
+ const targetWord = /(recipient|conversation|contact|send to|person|address|target|someone else|\b(?:to|cc|bcc|role|field)\b|收件人|联系人|发送)/i.test(questionText);
return changeWord && targetWord;
}
- if (purpose === 'message_recipient' || purpose === 'recipient_change') return true;
- if (purpose === 'research_escalation') return false;
// Check if the clarify question, reason, or options explicitly mention any observed candidate identity or alias
if (Array.isArray(observedCandidates) && observedCandidates.length > 0) {
@@ -15686,16 +15684,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
}
- const text = [
- context.question,
- context.reason,
- ...(Array.isArray(context.options) ? context.options : []),
- ].filter(Boolean).join(' ').toLowerCase();
-
- if (/recipient|收件人/i.test(text)) return true;
+ if (/recipient|收件人/i.test(questionText)) return true;
- const hasRecipientTerm = /(contact|person|address|who|whom|which contact|which person|which recipient|which user|which address|to whom|for whom|someone|联系人|哪位|谁)/i.test(text);
- const hasMessagingTerm = /(send|receive|deliver|message|email|mail|draft|reply|chat|conversation|发送|邮件|信息|消息|寄|回复)/i.test(text);
+ const hasRecipientTerm = /(contact|person|address|who|whom|which contact|which person|which recipient|which user|which address|to whom|for whom|someone|联系人|哪位|谁)/i.test(questionText);
+ const hasMessagingTerm = /(send|receive|deliver|message|email|mail|draft|reply|chat|conversation|发送|邮件|信息|消息|寄|回复)/i.test(questionText);
return hasRecipientTerm && hasMessagingTerm;
}
diff --git a/test/run.js b/test/run.js
index c0a70e75f..3c1431ea2 100644
--- a/test/run.js
+++ b/test/run.js
@@ -5772,6 +5772,29 @@ test('direct-message recipient guard uses structured intent and exact active ide
recipients: [{ identity: '[email protected]', role: 'to' }],
}, `${label}: recipient change did not update target`);
+ // A mislabeled question with purpose: 'recipient_change' but lacking recipient-change semantics
+ // must never authorize changing the recipient.
+ agent._planExecutionGuards.set(tabId, recipientChangeGuardState([{ identity: '[email protected]', role: 'to' }]));
+ assert.equal(
+ agent._bindClarifiedMessageRecipient(tabId, '[email protected]', 'user', {
+ question: 'Which colleague should present?',
+ purpose: 'recipient_change',
+ }),
+ false,
+ `${label}: mislabeled clarification question with purpose: recipient_change authorized recipient change`,
+ );
+
+ // A mislabeled question with purpose: 'message_recipient' must never authorize a standard recipient either.
+ agent._planExecutionGuards.set(tabId, clarifyGuardState([{ identity: '[email protected]', role: 'to' }]));
+ assert.equal(
+ agent._bindClarifiedMessageRecipient(tabId, '[email protected]', 'user', {
+ question: 'Which colleague should present?',
+ purpose: 'message_recipient',
+ }),
+ false,
+ `${label}: mislabeled clarification question with purpose: message_recipient authorized recipient`,
+ );
+
// Role preservation during recipient-change clarification:
// A plan authorizing Alice as BCC when composer exposes Alice as To must retain BCC
// on an identity-only answer, preventing unauthorized exposure on next send.