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.
TypeScript agentic-browseragentic-browsingagy-cliaiai-agentai-browser-extensionai-toolsbrave-extensionbrowser-agentbrowser-automationbrowser-extensionbrowser-usebrowserskillchrome-extensionclaude-codecodexfirefox-addonmcp-servernanobrowserweb-automation
fix(guardrails): judge a navigation by where it lands, not by whether it parses
Shahriar2a214c9d983a
diff --git a/docs/guide/approvals.md b/docs/guide/approvals.mdindex 650e392..b80d788 100644--- a/docs/guide/approvals.md+++ b/docs/guide/approvals.md@@ -43,9 +43,10 @@ depend on declaration order.| --- | --- | --- || `reserved-action` | An internal `browsentic.*` verb is called from outside | **deny** || `non-http-navigation` | A `javascript:`, `data:` or `file:` URL dressed up as a navigation | **deny** |+| `unreadable-navigation` | A URL that resolves to no destination Browsentic can check | **deny** || `raw-html-read` | `page_extractText` with `format: "html"` | **deny** || `network-body-read` | `page_readNetwork` with `includeBodies: true` | **deny** |-| `off-scope-navigation` | Navigating off the sites this run is about | confirm |+| `off-scope-navigation` | Navigating off the sites this run is about, however the URL is spelled | confirm || `url-payload` | A navigation whose query string or fragment exceeds `urlPayloadBytes` (512 by default) | confirm || `form-submission` | Anything that commits a form, however spelled | confirm || `site-tool-call` | `page_callSiteTool` — running a tool the site registered through WebMCP | confirm |@@ -185,7 +186,7 @@ shipped default still reaches you.A run takes its policy when it starts. A change applies to the next run, not one already going.-Three rows are shown but **locked**: `reserved-action`, `non-http-navigation` and `secret-in-url`.+Four rows are shown but **locked**: `reserved-action`, `non-http-navigation`, `unreadable-navigation` and `secret-in-url`.Allowing a `javascript:` URL, letting a page call an internal verb, or letting a credential travelin a query string are not preferences, and none of them has a use worth a switch you can hit byaccident. Hand-editing config.json still works if you genuinely mean it.diff --git a/docs/internals/guardrails.md b/docs/internals/guardrails.mdindex cdc2fdd..66ee5da 100644--- a/docs/internals/guardrails.md+++ b/docs/internals/guardrails.md@@ -41,9 +41,10 @@ The condition vocabulary is closed on purpose: a rule cannot express anything th| --- | --- | --- | --- || `reserved-action` | `reservedAction` | **deny** | The action starts with `browsentic.` || `non-http-navigation` | `nonHttpNavigation` | **deny** | `javascript:`, `data:`, `file:` and friends dressed up as a navigation |+| `unreadable-navigation` | `unreadableNavigation` | **deny** | The URL resolves to no destination, with or without a page to resolve against || `raw-html-read` | `readsRawHtml` | **deny** | `page.extractText` with `format: 'html'` || `network-body-read` | `readsResponseBodies` | **deny** | `page.readNetwork` with `includeBodies: true` |-| `off-scope-navigation` | `navigatesOffScope` | confirm | The target host is not in the run's scope |+| `off-scope-navigation` | `navigatesOffScope` | confirm | The target host is not in the run's scope, whether the caller named it absolutely or with a `//host` reference || `url-payload` | `carriesUrlPayload` | confirm | Query string + fragment exceed `urlPayloadBytes` (512) || `form-submission` | `submitsForm` | confirm | Anything that commits a form, however spelled || `file-upload` | `uploadsFile` | confirm | `page.attachFile` |diff --git a/scripts/check-security.mjs b/scripts/check-security.mjsindex 91f4383..1428b4c 100644--- a/scripts/check-security.mjs+++ b/scripts/check-security.mjs@@ -91,7 +91,8 @@ const SUBMITS = [for (const [action, input, want] of SUBMITS) check(`submitsForm(${action})`, guardrails.submitsForm(action, input), want);// ── guardrails: scope ────────────────────────────────────────────────────────────-const { ANYWHERE, decide, fence, hostAllowed, policyFrom, scopeFor, shouldFence, urlPayloadBytes } = guardrails;+const { ANYWHERE, decide, fence, hostAllowed, hostBearingUrl, policyFrom, scopeFor, shouldFence, targetUrl, urlPayloadBytes } =+ guardrails;const HOSTS = [['example.com', ['example.com'], true],@@ -117,6 +118,40 @@ check('pinTab on pins the tab', scopeFor({ url: 'https://a.com/', tabId: 7, pinTcheck('url payload counts query and fragment', urlPayloadBytes(new URL('https://a.com/p?q=12345#ab')), 11);+// Whether a url string brings its own host or borrows the page's. The probes are two+// constants carrying the whole classification, so this table is what catches an edit that+// makes them agree — `//one.probe.invalid/x` in particular, which proves that naming a+// probe buys a reference nothing.+const TARGET_KINDS = [+ ['https://evil.com/x', 'absolute'],+ ['javascript:alert(1)', 'absolute'],+ ['https:evil.com/x', 'absolute'],+ ['//evil.com/x', 'authority'],+ ['\\\\evil.com/x', 'authority'],+ ['/\\evil.com/x', 'authority'],+ ['\t//evil.com/x', 'authority'],+ ['/\t/evil.com', 'authority'],+ ['//[email protected]/', 'authority'],+ ['//0x7f000001/x', 'authority'],+ ['//one.probe.invalid/x', 'authority'],+ ['/pricing', 'path'],+ ['\\evil.com/x', 'path'],+ ['#//evil.com', 'path'],+ ['/%2f/evil.com/x', 'path'],+ ['//', 'opaque'],+ ['//evil.com%09/x', 'opaque'],+];+for (const [url, kind] of TARGET_KINDS) {+ check(`targetUrl reads ${JSON.stringify(url)} as ${kind}`, targetUrl('page.navigate', { url }).kind, kind);+}+check('a non-navigation has no target', targetUrl('page.clickElement', { url: '//evil.com/x' }), null);+check('nor does a history move', targetUrl('page.navigate', { action: 'back' }), null);+check(+ 'only a host the caller supplied is judged',+ [hostBearingUrl('page.navigate', { url: '//evil.com/x' }).hostname, hostBearingUrl('page.navigate', { url: '/pricing' })],+ ['evil.com', null],+);+// ── guardrails: decisions ────────────────────────────────────────────────────────const scope = scopeFor({ url: 'https://example.com/', tabId: 3, pinTab: true });const agent = (action, input) => decide({ action, input, caller: 'agent', scope });@@ -126,6 +161,38 @@ check('in-scope navigation allowed', agent('page.navigate', { url: 'https://app.check('off-scope navigation confirms', agent('page.navigate', { url: 'https://evil.com/x' }).effect, 'confirm');check('off-scope openTab confirms', agent('page.openTab', { url: 'https://evil.com/x' }).effect, 'confirm');check('relative navigation is not a host decision', agent('page.navigate', { url: '/pricing' }).effect, 'allow');++// The extension does not open the URL; the page does, and it resolves what it was handed+// against the URL it is already on. So a string the daemon cannot parse alone is not a+// string that goes nowhere: on example.com, `//evil.com/x` is the page's own resolver+// handing the run to evil.com, and every url condition used to read the null and stay+// quiet. A path still names no host, because where the tab actually is is not something+// scope knows.+check('a protocol-relative navigation is a host decision', agent('page.navigate', { url: '//evil.com/x' }).matched.map((r) => r.id), ['off-scope-navigation']);+check('and so is a backslashed one', agent('page.navigate', { url: '\\\\evil.com/x' }).matched.map((r) => r.id), ['off-scope-navigation']);+check('and a half-backslashed one', agent('page.navigate', { url: '/\\evil.com/x' }).effect, 'confirm');+check('and one hidden behind a control character', agent('page.navigate', { url: '\t//evil.com/x' }).effect, 'confirm');+check('and one spliced with a tab mid-path', agent('page.navigate', { url: '/\t/evil.com' }).effect, 'confirm');+check('userinfo does not decide the host', [agent('page.navigate', { url: '//[email protected]/' }).effect, agent('page.navigate', { url: '//[email protected]/' }).effect], ['allow', 'confirm']);+check('a single backslash is still a path', agent('page.navigate', { url: '\\evil.com/x' }).effect, 'allow');+check('the same reference in scope is not gated', agent('page.navigate', { url: '//app.example.com/x' }).effect, 'allow');+check('naming the probe buys nothing', agent('page.navigate', { url: '//one.probe.invalid/x' }).effect, 'confirm');+check('a relative openTab is judged the same way', agent('page.openTab', { url: '//evil.com/x' }).matched.map((r) => r.id), ['off-scope-navigation']);+check('a relative download url too', agent('page.captureDownload', { url: '//evil.com/f.csv' }).matched.map((r) => r.id), ['off-scope-navigation', 'file-download']);+check('and still when file-download is turned off', decide({ action: 'page.captureDownload', input: { url: '//evil.com/f.csv' }, caller: 'agent', scope }, policyFrom({ rules: { 'file-download': 'allow' } })).matched.map((r) => r.id), ['off-scope-navigation']);++// A URL is a destination or it is nothing. What no parser settles is refused rather than+// skipped, so the next spelling nobody thought of fails closed instead of silently.+check('a url with no readable destination is denied', agent('page.navigate', { url: '//evil.com%09/x' }).matched.map((r) => r.id), ['unreadable-navigation']);+check('and nothing else has an opinion about it', agent('page.navigate', { url: '//' }).matched.map((r) => r.id), ['unreadable-navigation']);++// Bytes leaving the browser are counted whatever the URL's shape, because that rule is+// about the payload and not about where it lands.+check('a relative payload counts the same bytes', agent('page.navigate', { url: `/pricing?d=${'x'.repeat(600)}` }).matched.map((r) => r.id), ['url-payload']);+check('a fragment counts too', agent('page.navigate', { url: `#d=${'x'.repeat(600)}` }).effect, 'confirm');+check('a small relative query string is still fine', agent('page.navigate', { url: '/search?q=kettle' }).effect, 'allow');+check('an unattended caller cannot smuggle one out', external('page.navigate', { url: `//evil.com/log?d=${'x'.repeat(600)}` }).effect, 'deny');+check('which is what the absolute spelling already said', external('page.navigate', { url: `https://evil.com/log?d=${'x'.repeat(600)}` }).effect, 'deny');check('history navigation is not a host decision', agent('page.navigate', { action: 'back' }).effect, 'allow');check('javascript: navigation denied', agent('page.navigate', { url: 'javascript:alert(1)' }).effect, 'deny');check('reserved action denied', agent('browsentic.saveSiteMap', {}).effect, 'deny');@@ -453,7 +520,7 @@ check('each row falls back to the shipped effect', untouched.rules.every((row, acheck('rows carry the reason the agent is given', untouched.rules.every((row) => row.reason.length > 0), true);const LOCKED = untouched.rules.filter((r) => r.locked).map((r) => r.id);-check('the structural rules are locked', LOCKED, ['reserved-action', 'non-http-navigation', 'secret-in-url']);+check('the structural rules are locked', LOCKED, ['reserved-action', 'non-http-navigation', 'unreadable-navigation', 'secret-in-url']);check('every locked rule denies', untouched.rules.filter((r) => r.locked).every((r) => r.fallback === 'deny'), true);for (const id of LOCKED) check(`the panel cannot write ${id}`, settingWritable(id, 'allow'), false);check('an unlocked rule is writable', settingWritable('form-submission', 'allow'), true);@@ -611,6 +678,8 @@ check('a secret from another site says so', agent('page.fillInput', { value: offcheck('a secret from the run’s own site does not', agent('page.fillInput', { value: `⟦password:[email protected]#${TAG}⟧` }).matched.map((r) => r.id).includes('secret-off-scope'), false);check('a secret in a url is denied outright', agent('page.navigate', { url: `https://example.com/?p=${real}` }).effect, 'deny');check('even on the run’s own site', agent('page.navigate', { url: `https://example.com/?p=${real}` }).matched.map((r) => r.id), ['secret-in-url']);+check('however the url is spelled', [agent('page.navigate', { url: `//evil.com/?p=${real}` }).effect, agent('page.navigate', { url: `/x?p=${real}` }).effect], ['deny', 'deny']);+check('and it is secret-in-url that says so', agent('page.navigate', { url: `/x?p=${real}` }).matched.map((r) => r.id), ['secret-in-url']);check('an unattended caller cannot release at all', external('page.fillInput', withSecret).effect, 'deny');check('an ordinary fill is untouched', agent('page.fillInput', { value: 'kettles' }).effect, 'allow');// The panel renders a fillInput value as [redacted], but a handle is public bydiff --git a/src/daemon/guardrails/index.ts b/src/daemon/guardrails/index.tsindex eeefd8f..efb1c0b 100644--- a/src/daemon/guardrails/index.ts+++ b/src/daemon/guardrails/index.ts@@ -17,8 +17,8 @@* for the spawn — so every caller is covered.*/-export { ANYWHERE, hostAllowed, normalizeHost, scopeFor, targetUrl, targetsAnotherTab, urlPayloadBytes } from './scope';-export type { Scope, ScopeSeed } from './scope';+export { ANYWHERE, hostAllowed, hostBearingUrl, normalizeHost, scopeFor, targetUrl, targetsAnotherTab, urlPayloadBytes } from './scope';+export type { NavigationTarget, Scope, ScopeSeed } from './scope';export {CONDITIONS,diff --git a/src/daemon/guardrails/policy.ts b/src/daemon/guardrails/policy.tsindex daef4c5..deb4696 100644--- a/src/daemon/guardrails/policy.ts+++ b/src/daemon/guardrails/policy.ts@@ -26,7 +26,7 @@import { RESERVED_PREFIX } from '@/lib/actions/reserved';import { handlesIn, sealedHandles } from '@/lib/secrets';import type { RuleEffect } from '@/lib/settings/guardrails';-import { hostAllowed, targetUrl, targetsAnotherTab, urlPayloadBytes, type Scope } from './scope';+import { hostAllowed, hostBearingUrl, targetUrl, targetsAnotherTab, urlPayloadBytes, type Scope } from './scope';export const SUBMIT_ACTION = 'page.submitForm';export const UPLOAD_ACTION = 'page.attachFile';@@ -68,25 +68,38 @@ export const CONDITIONS = {/** javascript:, data:, file: and friends dressed up as a navigation. */nonHttpNavigation: (request) => {- const url = targetUrl(request.action, request.input);+ const url = hostBearingUrl(request.action, request.input);return !!url && url.protocol !== 'http:' && url.protocol !== 'https:';},+ /**+ * A navigation URL nothing resolves to a destination. Every other url condition asks a+ * question about a host, and a string no parser settles has no host to ask it of — so+ * they all fall silent together, on the input that deserves it least. This is the one+ * condition that fires on not knowing. It costs nothing the caller wanted: the+ * extension refuses such a URL a moment later anyway. The daemon parses in Node and the+ * browser that acts parses in Chrome, and agreeing to differ there is how the last hole+ * opened.+ */+ unreadableNavigation: (request) => targetUrl(request.action, request.input)?.kind === 'opaque',+/** Leaving the hosts the run was scoped to — the exfiltration path that matters most. */navigatesOffScope: (request) => {- const url = targetUrl(request.action, request.input);+ const url = hostBearingUrl(request.action, request.input);return !!url && !hostAllowed(url.hostname, request.scope.hosts);},/**- * A navigation whose query string or fragment is large enough to be a payload. Downloads- * are exempt: a signed file url is mostly query string by design, and gating those would- * mean a prompt on every export.+ * A navigation whose query string or fragment is large enough to be a payload. The one+ * url condition with no host in it, and deliberately: bytes leaving the browser are+ * bytes leaving the browser, and `/collect?d=…` carries the same ones as the absolute+ * spelling of it. Downloads are exempt — a signed file url is mostly query string by+ * design, and gating those would mean a prompt on every export.*/carriesUrlPayload: (request, policy) => {if (request.action === DOWNLOAD_ACTION) return false;- const url = targetUrl(request.action, request.input);- return !!url && urlPayloadBytes(url) > policy.urlPayloadBytes;+ const target = targetUrl(request.action, request.input);+ return !!target?.url && urlPayloadBytes(target.url) > policy.urlPayloadBytes;},/** Anything that commits a form, however it is spelled. */@@ -141,7 +154,8 @@ export const CONDITIONS = {/*** A sealed secret in a URL is a credential on its way out of the browser. Read from* the raw argument, not the parsed URL: parsing percent-encodes the handle's brackets- * and the placeholder stops looking like one.+ * and the placeholder stops looking like one. Any navigation counts, whatever shape its+ * URL is in — that a credential is in a URL at all settles this before its host does.*/carriesSecretInUrl: (request) => {if (!targetUrl(request.action, request.input)) return false;@@ -194,6 +208,18 @@ export const DEFAULT_RULES: readonly Rule[] = [title: 'Non-http navigation',reason: 'Only http(s) URLs can be opened.',},+ {+ // A URL is a destination or it is nothing, and this is the rule that makes that true.+ // `//evil.com/x` used to arrive here as a null every url condition skipped, while the+ // page it was typed on resolved it and left the site. Classifying fixed that spelling;+ // refusing what still will not classify is what stops the next one, without anybody+ // having to think of it first.+ id: 'unreadable-navigation',+ when: 'unreadableNavigation',+ effect: 'deny',+ title: 'URL with no readable destination',+ reason: 'That URL does not resolve to a destination Browsentic can check. Pass an absolute https:// URL.',+ },{id: 'off-scope-navigation',when: 'navigatesOffScope',diff --git a/src/daemon/guardrails/scope.ts b/src/daemon/guardrails/scope.tsindex 0bb45bc..63207f4 100644--- a/src/daemon/guardrails/scope.ts+++ b/src/daemon/guardrails/scope.ts@@ -84,29 +84,86 @@ export function hostAllowed(host: string, hosts: readonly string[]): boolean {return hosts.some((entry) => target === entry || target.endsWith(`.${entry}`));}-function hostOf(url: string | undefined): string | null {- if (!url) return null;+function parseUrl(url: string, base?: string): URL | null {try {- return normalizeHost(new URL(url).hostname);+ return new URL(url, base);} catch {return null;}}+function hostOf(url: string | undefined): string | null {+ const parsed = url ? parseUrl(url) : null;+ return parsed ? normalizeHost(parsed.hostname) : null;+}++/**+ * Two origins that disagree with each other. Not a guess at where a run is — nothing is+ * ever compared against them — but the question put to the parser: does this string bring+ * its own host, or take one from whatever page it lands on? Two rather than one, so that+ * naming the probe cannot buy a reference the answer it wants. `.invalid` is reserved by+ * RFC 2606 and resolves nowhere.+ */+const PROBES = ['https://one.probe.invalid/', 'https://two.probe.invalid/'];+const PROBE_HOSTS = PROBES.map((base) => new URL(base).hostname);++/**+ * A navigation, and how much of the destination the caller's own string settles:+ *+ * absolute parses alone — scheme and host both came from the caller+ * authority only parses against a base, but brings its own host: `//evil.com/x` is+ * evil.com whatever page it is typed on, and borrows only the scheme+ * path takes its host from the page it lands on and cannot change it+ * opaque nothing settles it, base or no base+ *+ * A path's `url` carries a probe's host. Read a host off one of these only when the kind+ * says the caller supplied it — `hostBearingUrl` is that question asked properly.+ */+export type NavigationTarget =+ | { readonly kind: 'absolute' | 'authority' | 'path'; readonly url: URL }+ | { readonly kind: 'opaque'; readonly url: null };+/**- * The absolute URL an action would open or fetch, or null when there is none to judge.- * A relative URL resolves against the tab the run is already on, so it cannot- * change host and is not a navigation decision worth gating.+ * The navigation an action is asking for, or null when it is not asking for one.+ *+ * This used to return the absolute URL and null for every string `new URL` refused, on+ * the reasoning that a relative URL resolves against the tab the run is already on and so+ * cannot change host. That holds for a path and is false for an authority: the extension+ * hands the string to the page's own resolver — `location.href` for page.navigate, the+ * anchor tab for page.openTab — so `//evil.com/x` on a bank's page is that resolver+ * handing the run to evil.com, and `\\evil.com/x`, `/\evil.com/x`, `///evil.com/x` and+ * every whitespace-prefixed spelling of them are the same URL. Every url condition read+ * the null and stayed quiet.+ *+ * Classifying separates a host the daemon cannot know from a host it was handed in a+ * spelling it did not recognise. The classifier is the parser itself, asked twice against+ * bases that disagree, so there is no list of tricks to keep up to date — and what still+ * will not resolve comes back `opaque` rather than as nothing to see.*/-export function targetUrl(action: string, input: unknown): URL | null {+export function targetUrl(action: string, input: unknown): NavigationTarget | null {if (!NAVIGATIONS.has(action)) return null;const url = (input as { url?: unknown } | undefined)?.url;if (typeof url !== 'string') return null;- try {- return new URL(url);- } catch {- return null;- }++ const alone = parseUrl(url);+ if (alone) return { kind: 'absolute', url: alone };++ const [one, two] = PROBES.map((base) => parseUrl(url, base));+ if (!one || !two) return { kind: 'opaque', url: null };+ if (one.hostname === two.hostname) return { kind: 'authority', url: one };+ if (one.hostname === PROBE_HOSTS[0] && two.hostname === PROBE_HOSTS[1]) return { kind: 'path', url: one };+ return { kind: 'opaque', url: null };+}++/**+ * The URL when the caller's own string settled the host, and null when it did not. A+ * path's host belongs to whichever page the run is on, and that is not a fact the daemon+ * holds: scope is derived from where a run started and never learns where the tab went.+ * Standing something in for it here would let a host rule report a check it never made.+ */+export function hostBearingUrl(action: string, input: unknown): URL | null {+ const target = targetUrl(action, input);+ return target && (target.kind === 'absolute' || target.kind === 'authority') ? target.url : null;}/** Bytes a navigation would carry out of the browser in the query string or fragment. */diff --git a/src/daemon/guardrails/settings.ts b/src/daemon/guardrails/settings.tsindex 00b7eab..55f4e92 100644--- a/src/daemon/guardrails/settings.ts+++ b/src/daemon/guardrails/settings.ts@@ -24,10 +24,11 @@ import { DEFAULT_RULES, policyFrom, type GuardrailConfig } from './policy';/*** Not preferences. Allowing `javascript:` navigation, letting a page call an internal- * verb, or letting a released credential travel in a query string have no use worth a- * switch someone can hit by accident. Hand-editing config.json still works.+ * verb, waving through a URL that resolves to no destination, or letting a released+ * credential travel in a query string have no use worth a switch someone can hit by+ * accident. Hand-editing config.json still works.*/-const LOCKED = new Set(['reserved-action', 'non-http-navigation', 'secret-in-url']);+const LOCKED = new Set(['reserved-action', 'non-http-navigation', 'unreadable-navigation', 'secret-in-url']);const RULE_IDS = new Set(DEFAULT_RULES.map((rule) => rule.id));