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
feat(secrets): keep the plaintext in the extension, release it only into a page field
Shahriare6146c9d32b0
diff --git a/lib/bridge/invoke.ts b/lib/bridge/invoke.tsindex 131ddd8..5139f0d 100644--- a/lib/bridge/invoke.ts+++ b/lib/bridge/invoke.ts@@ -21,6 +21,8 @@ import { stopMonitor } from '@/lib/actions/page/stop-monitor';import { switchTab } from '@/lib/actions/page/switch-tab';import { trustedClick } from '@/lib/actions/page/trusted-click';import { failure, success, type ActionResult } from '@/lib/actions/protocol';+import { EXPIRED_MESSAGE, REFUSED_MESSAGE } from '@/lib/secrets';+import { releaseForAction, sealForPage } from '@/lib/bridge/secret-vault';import { findCaptchaInTab, solveCaptchaInTab } from '@/lib/bridge/captcha';import { listMeta, readBytes } from '@/lib/bridge/file-store';import { awaitMonitorDone, monitorStatusFor, startTabMonitor, stopTabMonitor } from '@/lib/bridge/monitor';@@ -30,11 +32,48 @@ import { dragInTab, trustedClickInTab } from '@/lib/bridge/trusted-input';import { closeOpenTab, openNewTab, switchToTab, watchForLoad, type TabRef } from '@/lib/bridge/tabs';import { adoptSubtab, sessionForRun, sessionForTab, setCurrentTab, type TabSession } from '@/lib/bridge/tab-sessions';+/**+ * The sanitizer's client-side half, wrapped around every action the harness runs.+ *+ * In: a sealed handle becomes plaintext only if it sits in a field that types into the+ * page, and only one hop before the content script gets it. Out: whatever the page gave+ * back is scanned and sealed before it can reach the daemon, so a credential read from a+ * page never crosses the socket at all.+ */export async function invokeForHarness(action: string,input?: unknown,tabId?: number,runId?: string,+): Promise<ActionResult> {+ const release = await releaseForAction(action, input);+ if (release.refused.length) return failure('SECRET_NOT_RELEASABLE', REFUSED_MESSAGE);+ if (release.unresolved.length) return failure('SECRET_EXPIRED', EXPIRED_MESSAGE);++ const result = await dispatch(action, release.input, tabId, runId);+ const { value } = await sealForPage(result, await targetOrigin(tabId, runId));+ return value;+}++async function targetOrigin(tabId?: number, runId?: string): Promise<string | undefined> {+ const owner = runId ? await sessionForRun(runId) : null;+ const tab = await resolveTab(tabId, owner);+ return tab?.url ? hostOf(tab.url) : undefined;+}++function hostOf(url: string): string | undefined {+ try {+ return new URL(url).hostname.toLowerCase() || undefined;+ } catch {+ return undefined;+ }+}++async function dispatch(+ action: string,+ input: unknown,+ tabId?: number,+ runId?: string,): Promise<ActionResult> {if (action === listFiles.name) return listStoredFiles(input);if (action === listRecordings.name) return listStoredRecordings(input);diff --git a/lib/bridge/redact.ts b/lib/bridge/redact.tsindex f45007c..5984032 100644--- a/lib/bridge/redact.ts+++ b/lib/bridge/redact.ts@@ -1,4 +1,5 @@import { isSensitiveField } from '@/lib/recordings/events';+import { handlesIn } from '@/lib/secrets';const REDACTED = '[redacted]';const MAX_STRING = 200;@@ -31,10 +32,19 @@ const TYPED_FIELD: Record<string, string> = {'page.typeText': 'text',};+/**+ * A sealed handle is safe to show and worth showing: it names the kind of credential and+ * the site it was read on, which is exactly what someone answering a `secret-release`+ * prompt needs. Anything around it is not, so the field collapses to its handles alone.+ */export function redactInput(action: string, input: unknown): unknown {if (!input || typeof input !== 'object') return redactValue('', input, 0);const redacted = redactValue('', input, 0) as Record<string, unknown>;const typed = TYPED_FIELD[action];- if (typed && typed in redacted) redacted[typed] = REDACTED;+ if (typed && typed in redacted) {+ const typedValue = (input as Record<string, unknown>)[typed];+ const sealed = typeof typedValue === 'string' ? handlesIn(typedValue) : [];+ redacted[typed] = sealed.length ? sealed.map((handle) => handle.text).join(' ') : REDACTED;+ }return redacted;}diff --git a/lib/bridge/secret-vault.ts b/lib/bridge/secret-vault.tsnew file mode 100644index 0000000..131c618--- /dev/null+++ b/lib/bridge/secret-vault.ts@@ -0,0 +1,121 @@+/**+ * The one place a plaintext secret is kept.+ *+ * It lives in the extension, in `storage.session`, and nowhere else. Not in a+ * transcript, not in `storage.local`, and never across the socket — so the daemon, which+ * spawns an agent CLI and serves MCP clients, has no credential to lose. Session storage+ * is the right area for exactly one reason: the browser empties it on restart, so a+ * password read on Tuesday is not still here on Wednesday.+ *+ * `tag` is minted once per browser session and is the reason a page cannot help itself+ * to what is in here. Handles are public and a page can copy one, but resolving one+ * requires the tag, which is never rendered into page text, a tool result or a+ * transcript.+ */++import { browser } from 'wxt/browser';+import {+ handleFor,+ releaseInput,+ sealValue,+ type Handle,+ type Mint,+ type Release,+ type SealedFinding,+ type SecretKind,+} from '@/lib/secrets';++const VAULT_KEY = 'browsentic/secrets';+const MAX_ENTRIES = 64;+const TTL_MS = 2 * 60 * 60_000;++interface VaultEntry {+ id: string;+ value: string;+ kind: SecretKind;+ shape: string;+ origin?: string;+ at: number;+}++interface Vault {+ tag: string;+ entries: VaultEntry[];+}++let queue: Promise<unknown> = Promise.resolve();++function locked<T>(task: () => Promise<T>): Promise<T> {+ const run = queue.then(task, task);+ queue = run.catch(() => undefined);+ return run;+}++export function sealForPage<T>(value: T, origin?: string): Promise<{ value: T; found: SealedFinding[] }> {+ return locked(async () => {+ const vault = await readVault();+ const now = Date.now();+ const live = vault.entries.filter((entry) => now - entry.at < TTL_MS);+ const minted: VaultEntry[] = [];++ const mint: Mint = (secret, kind, shape) => {+ const known = [...live, ...minted].find((entry) => entry.value === secret && entry.origin === origin);+ if (known) {+ known.at = now;+ return handleFor(known, vault.tag);+ }+ const entry: VaultEntry = { id: newId(), value: secret, kind, shape, origin, at: now };+ minted.push(entry);+ return handleFor(entry, vault.tag);+ };++ const sealed = sealValue(value, { mint, tag: vault.tag });+ if (minted.length || live.length !== vault.entries.length) {+ await writeVault({ tag: vault.tag, entries: [...live, ...minted].slice(-MAX_ENTRIES) });+ }+ return sealed;+ });+}++export function releaseForAction(action: string, input: unknown): Promise<Release> {+ return locked(async () => {+ const vault = await readVault();+ const now = Date.now();+ const touched: VaultEntry[] = [];++ const resolve = (handle: Handle): string | null => {+ const entry = vault.entries.find((held) => held.id === handle.id);+ if (!entry || now - entry.at >= TTL_MS) return null;+ entry.at = now;+ touched.push(entry);+ return entry.value;+ };++ const release = releaseInput(action, input, vault.tag, resolve);+ if (touched.length) await writeVault(vault);+ return release;+ });+}++export function forgetSecrets(): Promise<void> {+ return locked(() => browser.storage.session.remove(VAULT_KEY));+}++async function readVault(): Promise<Vault> {+ const stored = await browser.storage.session.get(VAULT_KEY).catch(() => ({}) as Record<string, unknown>);+ const held = stored[VAULT_KEY] as Partial<Vault> | undefined;+ if (held?.tag && Array.isArray(held.entries)) return { tag: held.tag, entries: held.entries };+ const fresh: Vault = { tag: newTag(), entries: [] };+ await writeVault(fresh);+ return fresh;+}++function writeVault(vault: Vault): Promise<void> {+ return browser.storage.session.set({ [VAULT_KEY]: vault }).catch(() => undefined);+}++const hex = (bytes: number) =>+ [...crypto.getRandomValues(new Uint8Array(bytes))].map((byte) => byte.toString(16).padStart(2, '0')).join('');++const newTag = () => hex(8);+const newId = () => hex(4);