Hardening an AI Browser MCP Without Stripping CSP: Origin-Guarded Iframes, Fail-Fast Batching & 17 Adversarial Probes
How sessfork-mcp v0.3.1 (913 KiB pure-Rust CDP MCP, zero Node.js / zero Tokio) adds cross-origin iframe execution, multi-step batching, and trusted mouse events while keeping CSP intact and verifying 9 security domains with 17 live black-box probes.
On this page
- 1. Cross-Origin Iframes Without Touching CSP (browser_frames + Scoped browser_evaluate)
- 2. Fail-Fast, Zero-Secret-Echo Action Batching (browser_batch)
- 3. On-Demand Real Mouse Events (browser_click(trusted=true))
- 4. Nine Security Domains, 17 Live Adversarial Probes (scripts/security_verify.py)
- Reproduce Everything Offline in ~5 Seconds
- 5. Honest Boundaries (Not Tested ≠ Clean)
- Install or Inspect v0.3.1

Most browser-automation tools for AI agents end up making an uncomfortable trade-off:
- Option A: Keep the automation surface minimal and safe, and watch the agent fail whenever it meets an OAuth iframe, a multi-field form that eats 6 LLM round trips, or a button checking
event.isTrusted. - Option B: Make the automation “just work” by relaxing browser security — stripping
Content-Security-Policyheaders globally in an extension, exposing raw cookie/localStorage getters to the LLM, or executing queued clicks blindly even after a redirect swaps the page underneath.
In sessfork-mcp v0.3.1 (a single 913.2 KiB stripped Rust binary with zero Node.js and zero Tokio), we added all three high-leverage capabilities — cross-origin iframe execution, multi-step form batching, and real trusted mouse events — without loosening a single security invariant. Every boundary is backed by a runnable black-box adversarial suite (scripts/security_verify.py: 17/17 PASS across 9 security domains, plus 45 Rust unit tests and 51 Python/E2E tests).
Here is how the architecture works and how each failure mode is tested.
1. Cross-Origin Iframes Without Touching CSP (browser_frames + Scoped browser_evaluate)
A common shortcut in browser-driver extensions is attaching a declarativeNetRequest rule that strips Content-Security-Policy response headers across the entire browser so injected scripts and eval never get blocked. That is unacceptable when the host browser holds live developer, cloud, or corporate sessions.
Instead of weakening CSP, sessfork-mcp works entirely through Chrome DevTools Protocol (CDP) isolation primitives:
- Secret-redacted frame discovery (
browser_frames): Enumerates the live frame tree viaPage.getFrameTreeand classifies each frame asmain,child (same-origin),child (cross-origin), orchild (opaque). Before returning the frame list to the LLM, all URL query strings and#fragmentsare stripped so OAuthcode=, embeddedjwt=, or fragment tokens in iframe URLs never leak into model context. - Main-frame-only default + isolated CDP worlds:
browser_evaluatedefaults strictly to the main frame and executes inside a dedicated CDP isolated JavaScript world (Page.createIsolatedWorld). Even if a hostile page overrideswindow.JSON.stringifyor mutatesObject.prototypein the main world, the isolated world remains untouched. - Two-factor cross-origin binding + TOCTOU re-check:
To target a cross-origin frame, the caller must pass both
allowCrossOrigin: trueand an explicitexpectedOriginmatching the frame’s current origin. Right before evaluation, the server re-verifies the frame’s authoritative origin via CDP to close time-of-check-to-time-of-use (TOCTOU) redirect races. - Fail-closed on
data:and sandboxed opaque origins: Frames withdata:URLs or<iframe sandbox="allow-scripts">resolve to opaque ("null") origins. Both are rejected fail-closed even whenallowCrossOrigin: trueis supplied.
In D9_frames_batch_and_trusted_click, the test harness mounts four iframes simultaneously (same-origin with ?code=OAUTH_SECRET_1#tok=FRAG_1, cross-origin with ?jwt=CROSS_SECRET_2 and a hostile window.JSON.stringify = () => 'HIJACKED', a data:text/html frame, and a sandbox="allow-scripts" frame) and verifies:
0query/fragment secrets appear inbrowser_frames;- default cross-origin
browser_evaluatefails closed; - mismatched
expectedOriginfails closed; - matching
(frameId, allowCrossOrigin: true, expectedOrigin)succeeds cleanly inside the isolated world (CROSS_ORIGIN_OK, neverHIJACKED); - both
data:and sandboxed opaque frames are rejected.
2. Fail-Fast, Zero-Secret-Echo Action Batching (browser_batch)
Filling a login or settings form one MCP call at a time burns 4–6 extra LLM round trips. Yet letting an agent pass an arbitrary sequence of blind actions introduces two nasty hazards: password values echoing back into conversation history and post-navigation blind clicks (e.g., step 1 clicks a link that loads a confirmation page, and step 2 blindly clicks #danger on the new DOM).
browser_batch solves both at the protocol layer:
- Strict pre-validation allowlist (max 12 steps):
Only safe high-level interaction primitives are allowed. Attempts to sneak raw
evaluate, rawcdpcommands (such asStorage.getCookies), chained long waits, or trailing steps after asubmit: trueinput are rejected upfront before step 1 ever runs. - Zero plaintext echo on password inputs:
Typing into
<input type="password">(or masked fields) executes cleanly in the page while returning redacted action receipts — verified with a sentinel secret (SENTINEL_BATCH_PW_7741) that must appear0times in MCP stdout/receipts. - Hard navigation circuit breaker (
STOPPED_NAVIGATED): Before and after each step, the runtime compares document navigation state. The moment step k triggers a page navigation, steps k+1..n are aborted immediately withSTOPPED_NAVIGATED. In the adversarial probe, batchingclick(#gonext)followed byclick(#danger)lands on/nextand halts before#dangercan fire (SAFE_AFTER_NAV, neverDELETED).
3. On-Demand Real Mouse Events (browser_click(trusted=true))
For normal browsing, sessfork-mcp runs zero-layout on Moli (--compact --diff), avoiding getBoundingClientRect() layout triggers so peak RSS stays at 66.6 MB, cumulative 8-step SaaS SPA input tokens drop by -85.4% (25,474 vs 174,114 on Playwright MCP), and a single 24 GB MacBook scales to 160 parallel agents (+0.0 MB swap).
However, certain widgets explicitly check event.isTrusted === true or apply CSS transforms (transform: rotate(15deg)) where synthetic DOM .click() gets ignored.
v0.3.1 adds opt-in browser_click(..., trusted=true):
- Computes the click coordinates by averaging all 4 corners of the CSS box-model quad (
DOM.getBoxModel), which stays accurate even on rotated elements; - Dispatches real CDP
Input.dispatchMouseEvent(mouseMoved→mousePressed→mouseReleased) so listeners receiveev.isTrusted === true; - Preserves
WARNING: NO_OPdead-click protection ondisabledbuttons; - Fails loudly in zero-layout mode instead of silently falling back to a fake synthetic click — so the caller always knows whether a real layout-backed pointer event occurred.
4. Nine Security Domains, 17 Live Adversarial Probes (scripts/security_verify.py)
Security prose is cheap; runnable exploit probes stay honest across refactors. Every release of sessfork ships a zero-dependency local harness (python3 scripts/security_verify.py) that spawns the real compiled sessfork-mcp Rust binary and attacks it across 9 trust boundaries:
| Domain | What It Attacks | Verified Result (v0.3.1) |
|---|---|---|
D1 · SSRF (--cdp-url) |
14 malformed/non-loopback targets (169.254.169.254, RFC1918, 127.0.0.1@evil.com, file://, https://) |
14/14 exit fail-closed (code 2) before opening any socket |
| D2 · Navigation Sandbox | file:///etc/passwd, javascript:alert(1), data:text/html, chrome://settings |
4/4 rejected (isError: true) |
| D3 · Cross-Origin & Isolated World | Multi-origin localStorage hydration + live hot-reload under hostile window.JSON.stringify hijack |
Exact-origin isolation preserved; immune to main-world tampering |
| D4 · Filesystem & Symlinks | ../../ traversal, symlink clobber, existence-oracle probing outside --output-dir |
Blocked with identical sanitized error; valid outputs 0600, dir 0700 |
| D5 · Native Host Scope | Public suffixes (github.io, co.uk), @ userinfo spoofing, foreign cookie injection, corrupt state.json |
Foreign cookies dropped, zero-echo replies, corrupt state never wiped |
| D6 · MCP Surface & Redaction | Live tools/list audit against 7 forbidden raw cookie/storage export tools + CLI sentinel check |
18 tools exposed, 0 raw credential-read tools, 0 leaked sentinel bytes |
D7 · Studio UI (--ui) |
Unauth requests, DNS rebinding (Host: evil.com), forged Origin, missing CSRF token |
6/6 attacks return HTTP 403; authed responses enforce DENY & frame-ancestors 'none' |
| D8 · Python Domain Allowlist | Blank domains, TLDs, shared cloud suffixes (vercel.app, amazonaws.com), @ userinfo |
9/9 rejected fail-closed |
| D9 · Frames, Batch & Trusted Click | Frame URL secret leakage, cross-origin TOCTOU, data:/sandbox frames, password echo, post-nav #danger click, rotated isTrusted button |
3/3 live checks PASS (17/17 suite total) |
Reproduce Everything Offline in ~5 Seconds
Zero API keys, zero external network calls, and zero access to your real browser profile:
git clone https://github.com/wasabihu/sessfork.git
cd sessfork
# 1. Build the single Rust MCP binary (~913 KiB, zero Tokio)
cd rust/sessfork-mcp && cargo build --release --locked && cargo test --locked --all-targets && cd ../..
# 2. Run all 17 live black-box adversarial probes (D1–D9)
python3 scripts/security_verify.py
# 3. Run Python unit & integration tests (51 tests)
PYTHONPATH=src python3 -m unittest discover -s tests
5. Honest Boundaries (Not Tested ≠ Clean)
A security write-up is only useful if it states what the system does not protect against:
- Same-UID local compromise (Out of Scope): Any process already running under your OS user account can read
~/.sessfork/state.jsonjust as it can read Chrome’s own profile directory. - Same-origin JS semantics: Running
browser_evaluateon an authenticated tab obeys web-platform rules —HttpOnlycookies remain unreadable to JS, whilelocalStorageand non-HttpOnlycookies are readable to same-origin scripts. - Opt-in
--cache-key(Off by default): Persists the derived cookie key in~/.sessfork/keys.json(0600) to avoid repeated Keychain prompts; clear anytime withsessfork --purge-keys. - Untested surfaces: We have not yet run a third-party commercial pen-test, a
cargo-fuzzcampaign against the pure-std RFC 6455 WebSocket parser (src/ws_cdp.rs), or a Linux multi-user SELinux/AppArmor confinement audit.
Install or Inspect v0.3.1
- Prebuilt binaries (macOS / Linux / Windows): GitHub Release v0.3.1
- PyPI (
pip install -U sessfork): pypi.org/project/sessfork/0.3.1 - Official MCP Registry:
io.github.wasabihu/sessfork(0.3.1) - Full Threat Model & Benchmarks:
docs/security-report.md·docs/benchmarks.md