# BrowserGuard BrowserGuard is a runtime safety layer for browser and computer-use agents. It evaluates browser actions before they execute, blocks high-risk operations by policy, and writes redacted local audit logs. It is designed for developers building agents with Playwright, Puppeteer-style page objects, QA automation, web research agents, and GUI-driven assistants. ## What It Blocks - Navigation to local, private, or cloud metadata hosts - URLs containing secret-like query parameters - Non-HTTP navigation such as `file:`, `javascript:`, and `data:` - Sensitive form fields such as passwords, tokens, API keys, and card data - Uploads from sensitive paths such as `.env`, `~/.ssh`, and cloud credential files - Payment, checkout, bid, destructive, and message-send actions unless policy permits them BrowserGuard does not claim full browser sandboxing. It is a policy gate and audit layer that must be placed before the agent performs an action. ## Install From GitHub today: ```bash pnpm add github:David-Wu1119/browserguard ``` After the package is published to npm: ```bash pnpm add browserguard ``` For local development from this repository: ```bash corepack enable pnpm install pnpm check ``` ## CLI Quickstart Create a starter policy: ```bash pnpm browserguard init ``` Evaluate one action: ```bash pnpm browserguard check \ --action '{"type":"navigate","url":"https://example.com/callback?token=sk-demo-token-1234567890"}' \ --json ``` Generate a local demo report: ```bash pnpm browserguard demo --out .browserguard/demo ``` Expected result: the secret-bearing URL, SSH key upload, delete-click, and message-send action are blocked or require confirmation. The audit log redacts form values, copied content, message content, and sensitive URL query values. ## SDK Quickstart ```ts import { evaluateBrowserPolicy } from "browserguard"; const decision = evaluateBrowserPolicy( { type: "form_submit", fields: { password: "secret" } }, { defaults: { high_risk: "block" } }, ); console.log(decision.action); // "block" ``` ## Playwright-Style Wrapper ```ts import { wrapPlaywrightPage } from "browserguard"; const page = wrapPlaywrightPage(rawPage, { network: { allow_domains: ["docs.github.com"], deny_private_hosts: true, deny_sensitive_query_params: true, }, }); await page.goto("https://docs.github.com"); await page.goto("https://example.com?token=sk-demo-token-1234567890"); // blocked before rawPage.goto runs ``` The wrapper guards direct `goto`, `click`, `fill`, `type`, and `setInputFiles` calls. It does not yet intercept every Playwright locator API or every desktop computer-use event. See [Threat Model](docs/threat-model.md) for exact scope. ## Policy BrowserGuard policies are YAML files: ```yaml version: 1 network: allow_domains: - docs.github.com deny_private_hosts: true deny_sensitive_query_params: true forms: block_sensitive_fields: true files: deny_paths: - .env - ~/.ssh actions: payment_action: confirm destructive_action: confirm message_send: confirm defaults: low_risk: allow medium_risk: confirm high_risk: block critical_risk: block ``` Full policy details are in [Policy Reference](docs/policy.md). ## Audit Logs Use `eventPath` in the SDK or `--event-path` in the CLI to append redacted JSONL events: ```bash pnpm browserguard check \ --event-path .browserguard/events.jsonl \ --action '{"type":"form_submit","fields":{"password":"secret"}}' ``` BrowserGuard records action type, policy decision, matched rules, risk category, severity, and reason. It redacts raw form values, copied content, message content, and sensitive URL query values. ## Development ```bash corepack enable pnpm install pnpm typecheck pnpm test pnpm build npm pack --dry-run ``` ## Security Boundary BrowserGuard only protects actions routed through its SDK, CLI, or wrappers. It cannot stop code that bypasses BrowserGuard and calls Playwright, Puppeteer, Chrome DevTools Protocol, the filesystem, or the network directly. Treat it as one enforcement layer, not a complete sandbox. ## License MIT