Skip to content

An agentic browser harness: an AI side panel & orb in your own logged-in Chrome, Edge, Arc, Brave or even Firefox run by the agent/subscription you already use (Claude Code, Codex, Antigravity). Free, open source, no API key. Also an MCP server.

fix(guardrails): deny page.injectCode to MCP clients outright

Shahriara30193002a8e
diff --git a/docs/guide/approvals.md b/docs/guide/approvals.md
index 44c919d..fc07784 100644
--- a/docs/guide/approvals.md
+++ b/docs/guide/approvals.md
@@ -53,6 +53,7 @@ depend on declaration order.
| `leaves-pinned-tab` | Moving to a tab the run was not pointed at | confirm |
| `captcha-solve` | `page_solveCaptcha` — ticking a site's "I am a human" box | confirm |
| `code-injection` | `page_injectCode` — installing JavaScript the agent wrote into the page | confirm |
+| `external-code-injection` | `page_injectCode` called by an MCP client rather than the side panel | **deny** |
| `external-code-execution` | `page_runCode` called by an MCP client rather than the side panel | **deny** |
| `secret-in-url` | A saved secret placed in a navigation URL | **deny** |
| `secret-release` | A saved secret about to be typed into the page | confirm |
@@ -124,6 +125,11 @@ someone allowlists the browsentic tools to stop being asked.
waives them instead, going back to "the client's permissions are the only gate".
+It does not waive a `deny`. That is why the two live-tool rules deny rather than confirm: a
+client allowlisting the Browsentic tools is exactly the setup where `unattended: allow` gets
+turned on, and writing code into your logged-in page is not something a client's own prompt is
+in any position to judge.
+
---
## Tuning it
diff --git a/scripts/check-security.mjs b/scripts/check-security.mjs
index d11f079..91f4383 100644
--- a/scripts/check-security.mjs
+++ b/scripts/check-security.mjs
@@ -162,11 +162,19 @@ check('external never returns confirm', external('page.attachFile', { fileId: 'f
check('external download denied by default', external('page.captureDownload', { url: 'https://example.com/f.csv' }).effect, 'deny');
// Nobody to show the code to, so nobody can approve it — and a toolkit a person approved
// in the panel is not thereby available to an MCP client.
-check('external code injection denied by default', external('page.injectCode', { purpose: 'p', code: 'x' }).effect, 'deny');
+check('external code injection denied outright', external('page.injectCode', { purpose: 'p', code: 'x' }).effect, 'deny');
+check('the injection refusal names its rule', external('page.injectCode', { purpose: 'p', code: 'x' }).matched.map((r) => r.id), ['external-code-injection']);
check('external code execution denied outright', external('page.runCode', { function: 'x' }).effect, 'deny');
check('the refusal names its rule', external('page.runCode', { function: 'x' }).matched.map((r) => r.id), ['external-code-execution']);
check('unattended=allow does not open it', external('page.runCode', { function: 'x' }, policyFrom({ unattended: 'allow' })).effect, 'deny');
-check('the panel is unaffected by that rule', agent('page.runCode', { function: 'x' }).matched.map((r) => r.id), []);
+// The gap this pair closes: `code-injection` only confirms, and `unattended: allow` waives
+// a confirm, so installing was reachable from an MCP client with one line of config. The
+// `call` argument on page.injectCode then runs a function without passing this way again,
+// which made an allowed install an execution too.
+check('unattended=allow does not open injection either', external('page.injectCode', { purpose: 'p', code: 'x' }, policyFrom({ unattended: 'allow' })).effect, 'deny');
+check('nor does it open an install that calls straight through', external('page.injectCode', { purpose: 'p', code: 'x', call: { function: 'x', args: [] } }, policyFrom({ unattended: 'allow' })).effect, 'deny');
+check('the panel is unaffected by those rules', agent('page.runCode', { function: 'x' }).matched.map((r) => r.id), []);
+check('the panel still only confirms an install', agent('page.injectCode', { purpose: 'p', code: 'x' }).matched.map((r) => r.id), ['code-injection']);
// ── guardrails: policy overrides ─────────────────────────────────────────────────
const strict = policyFrom({ rules: { 'raw-html-read': 'deny', 'off-scope-navigation': 'deny' } });
diff --git a/src/daemon/guardrails/policy.ts b/src/daemon/guardrails/policy.ts
index f74959c..9587f2e 100644
--- a/src/daemon/guardrails/policy.ts
+++ b/src/daemon/guardrails/policy.ts
@@ -110,11 +110,17 @@ export const CONDITIONS = {
injectsCode: (request) => request.action === INJECT_ACTION,
/**
- * The one place a caller is named in a condition rather than left to `unattended`.
+ * The two places a caller is named in a condition rather than left to `unattended`.
* A toolkit is approved by a person reading it in the side panel, for the conversation
* they were having; an MCP client was never in that room, and the switch the user
* turned off is not one it can see.
+ *
+ * Both halves have to say so themselves. `unattended` only answers a `confirm`, so a
+ * rule that merely confirms is one config line away from being waived, and writing new
+ * code is the more powerful half of the pair, not the lesser one.
*/
+ injectsCodeOutsideThePanel: (request) => request.action === INJECT_ACTION && request.caller === 'external',
+
runsCodeOutsideThePanel: (request) => request.action === RUN_CODE_ACTION && request.caller === 'external',
/**
@@ -227,14 +233,25 @@ export const DEFAULT_RULES: readonly Rule[] = [
// its work: the panel puts the source behind a Review button, because "allow this
// action?" is not a question anyone can answer about code they have not read. It
// confirms rather than denies because a reviewed function is how twenty repetitions
- // stop being twenty round trips — and `unattended: deny` keeps an external MCP
- // client, which has nobody to show the code to, from installing any at all.
+ // stop being twenty round trips.
id: 'code-injection',
when: 'injectsCode',
effect: 'confirm',
title: 'Runs code it wrote in the page',
reason: 'That installs JavaScript the agent wrote into the page, with your logged-in session.',
},
+ {
+ // `code-injection` confirms, and a confirm is what `unattended: allow` waives, so on
+ // its own it left installation one config line away from an MCP client. Denying is
+ // not a duplicate of that rule: it is the half that cannot be configured off, which
+ // is what the equivalent rule below has always been for calls.
+ id: 'external-code-injection',
+ when: 'injectsCodeOutsideThePanel',
+ effect: 'deny',
+ title: 'Installs code from outside the panel',
+ reason:
+ 'Installing page code needs a person to read it first, and an MCP client has nobody to show it to. Ask from the Browsentic side panel instead.',
+ },
{
id: 'external-code-execution',
when: 'runsCodeOutsideThePanel',