Skip to content

feat(browser): enforce per-bot browserPolicy across MCP, CDP, fill_login, and egress gate - #66

Closed
zereight wants to merge 1 commit into
mainfrom
feat/bot-browser-policy
Closed

zereight wants to merge 1 commit into
mainfrom
feat/bot-browser-policy

Conversation

@zereight

Copy link
Copy Markdown
Owner

Summary

Adds harness-enforced per-bot browser host access control (bot.browserPolicy) so a bot without permission for specific external sites (e.g., Bitbucket PRs) is structurally blocked from reading or reaching them through the built-in browser and directed to the designated delegate bot.

  • Data model & API (browserPolicy):
    • packages/phone-protocol/src/browser-policy.ts, shared/browser-policy.ts, packages/phone-protocol/src/wire.ts, src/state/store.tsx: defines BrowserPolicy ({ rules?: Array<{ hosts: string[]; reason?: string; delegateTo?: string }>; allowHosts?: string[] }) with fail-closed URL/scheme parsing, subdomain & IPv6 canonical host matching, wildcard rejection, browserPolicyWidens diffing, and browserPolicyPrompt generation.
    • server/store.ts, server/routes/bots-create.ts, server/routes/bot-patch.ts, server/admin-activity.ts: validates, persists, and audits browserPolicy; blocks unauthenticated loopback policy widening while any bot is busy (409), mirroring toolScope.
    • shared/team-backup.ts, server/team-backup.ts: preserves browserPolicy across team backup export/import so policies do not fail open on restore.
  • 3-layer harness enforcement + fill_login + system prompt:
    • Layer 1 (MCP ingress & prompt): server/browser/engines.ts (RuntimeRouter.agentRpc), server/browser/bot-policy.ts, server/index.ts — blocks denied URLs and non-http(s)/about:blank schemes (javascript:, data:, file:, chrome:, view-source:) before dispatch (including on My Chrome), discards legacy agent-browser results whose output references a blocked host, and injects browserPolicyPrompt(bot.browserPolicy) into browserPromptFor.
    • Layer 2 (omb-cdp CDP dispatch & service): server/browser/dispatch.ts, server/browser/service.ts — enforces default-deny on already-open blocked tabs (e.g., shared browser profiles or tabs left by a person/another bot) with explicit escape actions (open/navigate/read to an allowed URL, tabs(close/list/new), close, restart_browser, redacted status), redacts blocked tab URLs/titles/dialogs/auth prompts/downloads from status/tabs/reopenedNote/recoveredResult, blocks and closes popups to denied hosts, and discards post-action tool output (snapshot, read, screenshot, eval, wait, observeChange) if an action lands on a denied host.
    • Layer 3 (SOCKS5 egress gate): server/browser/egress/policy.ts, server/browser/egress/registry.ts, server/host/browser.ts, server/turn-resources.ts — blocks TCP/DNS egress to denied hosts (Refusal = "bot-policy") before resolution or upstream tunneling, maps omb-cdp gateKey to browser session, resolves the active bot accurately in both 1:1 and room turns via TurnOwner.botId (and retains lastBotBySession between turns), bypasses bot policy while a person holds browser control (heldBy(session) !== null), and appends the policy refusal/delegation message into takeNotice.
    • fill_login gate: server/login-fill.ts, server/host/fill-login-turn.ts — refuses fill_login on blocked hosts before DOM inspection or credential lookup, and blocks post-submit redirects onto denied hosts.

Why

Prompt/SOUL instructions are soft rules that models can violate (for example, a dev bot directly opening a Bitbucket PR in the built-in browser instead of delegating to PR Reviewer). Enforcing browserPolicy at tool ingress, tab/CDP dispatch, fill_login, and the SOCKS5 egress gate closes direct navigation, redirects, link clicks, in-page fetch(), popups, eval, and shared-profile already-open tab leaks.

Before / After

  • Before:
    • BotRecord had no per-bot host restriction (browser: false was all-or-nothing).
    • A bot with the built-in browser enabled could open, click into, redirect to, fetch(), or inspect already-open tabs on unauthorized hosts (e.g., bitbucket.org) despite SOUL rules.
  • After (verified against real Google Chrome 158, real BrowserEgress SOCKS5 gate, local HTTP servers, Store, createTeamBackup, and POST /api/bots / PATCH /api/bots/:id):
    • Direct open to blocked host (http://blocked.localhost:<port>/secret-pr) -> refused before Chrome starts (isError: true, includes delegateTo: "PR Reviewer"), 0 HTTP hits.
    • 302 redirect (allowed.localhost -> blocked.localhost), in-page fetch(), link click, and window.open() popup -> killed at SOCKS5 egress gate / popup blocker with 0 HTTP hits and delegation notice.
    • Shared profile where unrestricted Bot B leaves blocked.localhost open -> Bot A's open({}), snapshot, read, screenshot, eval, wait, navigate(reload), and tabs(switch) are all refused without leaking page content; status and tabs(list) redact URL/title to blocked://blocked.localhost / [blocked by browser policy]; open({ url: allowed }) escapes cleanly.
    • fillLogin on a blocked page -> refused before candidates() is called (0 lookups).
    • POST /api/bots rejects wildcard *.bitbucket.org (400), PATCH /api/bots/:id blocks loopback widening while busy (409), allows narrowing while busy (200), and clears via null when idle (200).
    • Room turns (store.botByThread(roomThreadId) === null) resolve Bot A's policy via TurnOwner.botId on shared profiles and keep it active after release via lastBotBySession until Bot B claims the browser.

Verification

  • pnpm typecheck — passed (tsc -b, tsconfig.server.json, packages/phone-protocol/tsconfig.json).
  • pnpm lint (oxlint --deny-warnings .) — passed with 0 warnings/errors.
  • pnpm i18n:check — passed (16 languages, 11,387 strings).
  • pnpm build — passed (tsc + vite build).
  • pnpm vitest run across 14 related test files (egress/{registry,policy,gate}, engines, service, tools, browser-runtime, host/browser, host/fill-login-turn, login-fill, routes/bot-patch, routes/bots-create, team-backup, turn-resources) — all passed (454 passed, 1 skipped).
  • Pre-push source guards (src/locales/vocabulary.test.ts, scripts/testing/file-size-ratchet.test.ts) — passed.
  • Real-runtime E2E scripts (outside repo in /tmp):
    • OMB_DATA_DIR=<tmp> OMB_CHROME_PATH="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" node --experimental-strip-types /tmp/verify-bot-browser-policy.ts -> ALL 10 REAL-RUNTIME CHECKS PASSED!
    • OMB_DATA_DIR=<tmp> node --experimental-strip-types /tmp/verify-api-and-host.ts -> PASS [api-routes] and PASS [host-room-shared-egress].

Notes / Follow-ups

  • Settings UI editing (src/components/bot-settings/AccessSection.tsx) is intentionally deferred to a separate PR to keep this core harness PR focused.
  • On My Chrome (external user Chrome without OpenMyBot's SOCKS5 gate), Layer 1 pre-dispatch URL/scheme checks, fill_login checks, and legacy post-call URL filtering apply, while network-level egress blocking applies to OpenMyBot-managed browsers (omb-cdp and agent-browser).

@zereight

Copy link
Copy Markdown
Owner Author

방향 전환: 내장 브라우저 전용 URL 정책 대신 봇별 범용 도구·명령·MCP 가드레일(+ 위임 안내 강제)로 새 PR에서 설계·구현합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant