{"slug": "zero-dependency-multi-profile-ai-browser-isolation-in-1-18-mib-of-rust-per-proxy", "title": "Zero-Dependency Multi-Profile AI Browser Isolation in 1.18 MiB of Rust: Per-Context Proxy Guards, 42 MiB Moli Pools, and 2-Phase Human Handoff", "summary": "A developer released sessfork v0.4.1, a 1.18 MiB pure-std Rust binary with no new crates or Python runtime dependencies, adding named profile vaults with per-context proxy leak guards, a loopback process-isolated CDP orchestrator, and a two-phase non-blocking human takeover tool. The work was informed by paired positive/negative CDP probes against moli 1.1.29 and Chromium, which showed per-context proxy isolation works natively, dead proxies fail without silent direct fallback, and invalid proxy schemes only fail at navigation time, prompting upfront scheme validation.", "body_md": "Single-state headless browser setups work fine until your agents need **multiple isolated accounts, per-profile proxy routing, external Python/CLI CDP orchestration, or a clean escape hatch when headless runs hit interactive SSO / 2FA walls**.\n\nOnce you cross that line in production, four systems problems show up immediately:\n\n`storageState` file—or if an MCP tool accepts arbitrary `proxyServer` URLs straight from LLM parameters—a single prompt-injected webpage can trick an agent into routing authenticated requests through an attacker-controlled proxy.`FD_SETSIZE=1024` ceiling:`moli` process beyond `BrowserContext` s`1,024` (`1,063` observed via `lsof`), triggering `net::ERR_CONNECTION_REFUSED` on subsequent navigations.`/json/list` on a shared port lets external worker A inspect and attach to worker B's targets.\nIn `sessfork`[` v0.4.1`](https://github.com/wasabihu/sessfork/releases/tag/v0.4.1), we solved all four inside our **`1,233,344`-byte (`~1.18 MiB`)** pure-` std` Rust binary with **zero new Rust crates** and **zero Python runtime dependencies**: named Profile Vaults with per-context proxy leak guards (`P0-1`), a loopback process-isolated CDP orchestrator (` serve-api`, `P0-2`), and a 2-phase non-blocking human takeover tool (` browser_handoff`, `P0-3`).\n\n`moli 1.1.29` & Chromium)\nBefore writing isolation layers, we ran paired positive/negative CDP probes against `moli`` 1.1.29` (over anonymous pipe FDs 3/4 `--remote-debugging-pipe`) and local Chromium (`--cdp-url`):\n\n| CDP Probe | Observed Behavior ( `moli 1.1.29` / Chromium) | Design Takeaway | \n|---|---|---|\n| `createBrowserContext` (`proxyServer` ,`bypass` ) | Returns isolated `browserContextId` ; parallel contexts hit only their own proxy (`PROXY_HIT` ) | Per-context proxy isolation works natively inside one engine process | \n| Dead proxy ( `http` /`socks5` closed port) | Immediately fails with `ERR_CONNECTION_REFUSED` (**no silent direct fallback** ) | Paired with preflight TCP checks, prevents accidental IP leakage | \n| Invalid scheme ( `ftp://127.0.0.1:8080` ) | `createBrowserContext` succeeds; navigation later fails (`ERR_FAILED` ) | Rust must validate schemes upfront via `ProxySpec` before context spawn | \n| `Emulation.*Override` (TZ / Locale / UA / Geo) | All return `{}` ;`timeZone` &`navigator.language` update to`America/New_York` /`en-US` | Apply deterministic timezone/locale/geo overrides on every attached tab | \n\nImplemented across [`profile.rs`](https://github.com/wasabihu/sessfork/blob/main/rust/sessfork-mcp/src/profile.rs), [`proxy.rs`](https://github.com/wasabihu/sessfork/blob/main/rust/sessfork-mcp/src/proxy.rs), and [`profiles.py`](https://github.com/wasabihu/sessfork/blob/main/src/sessfork/profiles.py), named vaults preserve 100% compatibility with `~/.sessfork/state.json` while adding strict boundaries:\n\n`~/.sessfork/profiles/<name>/`):`^[a-z0-9][a-z0-9_-]{0,47}$` (blocking `default`, `..`, and hidden names). Both Rust and Python check for symlinks `O_NOFOLLOW` + `0600` atomic rename.`browser_tabs` rejects `proxy`, and `proxyBypassList` parameters outright. Only local `profile` names are accepted, and named contexts hydrate `state.json`—never leaking `ps aux`:` http://user:pass@host:port`) are parsed into `ProxySpec`, stripped of `userinfo@` in every CLI argument, log line, and error receipt, and answered in memory via CDP `Fetch.enable({ handleAuthRequests: true })` / `Fetch.authRequired`.`--ephemeral`:` requireProxy: true` (default), a `3s` loopback-safe TCP probe verifies proxy reachability before any context spawns. Optional outlet verification (`preflightUrl` / `expectedCountry`) executes only when explicitly configured (zero background telemetry by default). \n\n```\n# Create an ephemeral US vault with proxy + timezone/locale alignment\nsessfork profile create us-qa \\\n  --domains example.com \\\n  --proxy socks5h://127.0.0.1:1080 \\\n  --timezone America/New_York \\\n  --locale en-US \\\n  --ephemeral\n\n# Or fork specific domains from your active Chrome profile into a named vault\n# (uses --vault so existing -p / --profile stays orthogonal for Chrome source directories)\nsessfork github.com --vault work -p \"Profile 4\"\n```\n\n`serve-api` — A `3.1 MiB` Pure-`std` Orchestrator for `42.2 MiB` Isolated CDP Sessions\nTo bypass single-process FD limits and prevent one external worker from inspecting another worker's CDP targets on a shared port, `sessfork-mcp serve-api` ([`api_server.rs`](https://github.com/wasabihu/sessfork/blob/main/rust/sessfork-mcp/src/api_server.rs)) acts as a lightweight OS-process orchestrator:\n\n`127.0.0.1`, generates a `/dev/urandom` on Unix, `SystemFunction036` on Windows) compared in constant time, enforces strict `Host` / `Origin` / `Sec-Fetch-Site` anti-DNS-rebinding checks, and caps headers (`16 KiB`) and bodies (` 64 KiB`).` 409 Conflict` with the owning `activeSessionId`. Routes like `/cookies` or `/state` are deliberately omitted. Every child `chrome-headless-shell` process is reaped via Unix `killpg` or Win32 Job Objects when stopped or on `SIGTERM`.` cdpWsUrl` bound only to that profile's child process, zero-dependency Python `api_client.py`` sess.cdp_ws_url` straight into Playwright, `browser-use` (`Browser(cdp_url=sess.cdp_ws_url)`), or `agent-browser --cdp ...` without requiring custom WebSocket auth headers.\n\n``` python\nfrom sessfork.api_client import open_profile_session\n\n# Start daemon once: sessfork-mcp serve-api --port 7331\nwith open_profile_session(\n    \"work\",\n    base_url=\"http://127.0.0.1:7331\",\n    engine=\"moli\",  # or \"chrome\" when full WebGL/Blink fidelity is needed\n) as sess:\n    # Hand sess.cdp_ws_url directly to Playwright connect_over_cdp\n    # or browser-use Browser(cdp_url=sess.cdp_ws_url)\n    print(\"Isolated CDP endpoint:\", sess.cdp_ws_url, sess.timezone, sess.locale)\n# Context exit automatically calls /stop and reaps the child process (0 orphans)\n```\n\nMeasured on **macOS 26.6.2 (Apple Silicon `arm64`)** running `sessfork-mcp 0.4.1` and **8 simultaneous process-isolated `moli 1.1.29` sessions** with distinct timezones/locales and seeded cookies (reproducible harness documented in [`docs/benchmarks.md`](https://github.com/wasabihu/sessfork/blob/main/docs/benchmarks.md)):\n\n| Metric ( `serve-api --max-sessions 16` , 8 Isolated`moli 1.1.29` Processes) | Measured Result | \n|---|---|\n| **Cold `serve-api` ready latency** | **`8.7 ms`** (includes` 0600` 256-bit token generation & JSON ready signal) | \n| **Per-session start latency (p50 / mean / max)** | **`43.8 ms` / `76.0 ms` / `222.1 ms`** (process spawn + cookie hydration +` Emulation.*` overrides) | \n| **`serve-api` daemon RSS** | **`3.1 MiB`** | \n| **Total stack RSS (daemon + 8 isolated `moli` processes)** | **`340.9 MiB`** (**` 42.2 MiB` / session avg** ) | \n| **Cross-session CDP & timezone verification** | **`8 / 8 PASS`** (` 0` cross-profile leaks) | \n| **Orphan processes after `SIGTERM`** | **` 0`** | \n\n`browser_handoff`)\nEven when `--compact --diff` slashes cumulative LLM input tokens by **`-85.4%`**, automated flows still hit interactive MFA, passkeys, or human verification walls. Rather than touching CAPTCHA-bypass tooling, `sessfork` adds MCP tool #20 [`browser_handoff`](https://github.com/wasabihu/sessfork/blob/main/rust/sessfork-mcp/src/handoff.rs) (`start` / `status` / `complete` / `cancel`):\n\n`start`:` window.localStorage` (preserving in-flight OAuth PKCE `code_verifier` / CSRF state), writes them into an isolated `0700` `--user-data-dir`, and pops a desktop Chromium window (` 1,374.0 ms` measured on real macOS Chrome `--new-window`) without touching your daily Chrome profile.` MAX_ACTIVE_HANDOFFS=1`, `2s` start cooldown, and bounded timeouts (`60..=3600s`, default `600s`).` complete`:` localStorage` back into the headless context, `{start_host, end_host} ∪ allowDomains`` 0` raw secrets in MCP replies).`v0.4.1`\nAdversarial diff review, `scripts/security_verify.py` (`D1..D13`), and the 3-OS release matrix caught four subtle defects before shipping ([`20fbb38`](https://github.com/wasabihu/sessfork/commit/20fbb38), [` 06de95f`](https://github.com/wasabihu/sessfork/commit/06de95f)):\n\n`profile.json` load validation:`create` paths rejected malformed domains and unsupported `encryption` values, whereas load paths in `profile.rs` and `profiles.py` trusted existing disk fields. Both now enforce `schemaVersion == 1`, `encryption == \"none\"`, valid `engine`, and public-suffix domain rejection on load.` Drop` after explicit cleanup:`terminated: bool` guard to `ActiveHandoff` and `ManagedApiSession` so explicit `cleanup()`/` wait()` prevents `libc::killpg`.` handoff start`:` pkce_carried=True` asserted in `D13.2`).`-D warnings` errors:`_clean_profile_ref` / `_clean_session_id` slug guards in `SessforkApiClient`, and scoped Unix `api_server.rs` cleanly under `#[cfg(unix)]` alongside a `1,233,344` bytes (`~1.18 MiB`) stripped Rust binary; `73 / 73` Rust unit tests (`cargo test --locked --all-targets`), `clippy -- -D warnings` issues across macOS/Linux/Windows, `66 / 66` Python `unittest` cases, and `29 / 29 PASS`` D1..D13` in `docs/security-report.md``--engine dual` or `engine=\"chrome\"` in \n\n```\n# Install sessfork + native Rust sessfork-mcp (v0.4.1)\ncurl --proto '=https' --tlsv1.2 -fsSL \\\n  https://raw.githubusercontent.com/wasabihu/sessfork/v0.4.1/install.sh \\\n  | bash -s -- --with-rust-mcp\n\n# Or install the standalone Rust binary via Homebrew\nbrew install wasabihu/tap/sessfork-mcp\n```\n\n", "url": "https://wpnews.pro/news/zero-dependency-multi-profile-ai-browser-isolation-in-1-18-mib-of-rust-per-proxy", "canonical_source": "https://dev.to/wasabi_hu_d2b4b4d9b9f6bda/zero-dependency-multi-profile-ai-browser-isolation-in-118-mib-of-rust-per-context-proxy-guards-3ooh", "published_at": "2026-12-06 05:42:00+00:00", "updated_at": "2026-12-06 05:44:41.468689+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "agent-protocols"], "entities": ["sessfork", "moli", "Chromium", "GitHub"], "also_reported_by": [], "takeaway": "sessfork v0.4.1 adds named profile vaults, per-context proxy leak guards with preflight TCP checks, and a loopback CDP orchestrator in a 1.18 MiB zero-dependency Rust binary, after probes showed invalid proxy schemes pass createBrowserContext and only fail at navigation.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/zero-dependency-multi-profile-ai-browser-isolation-in-1-18-mib-of-rust-per-proxy", "markdown": "https://wpnews.pro/news/zero-dependency-multi-profile-ai-browser-isolation-in-1-18-mib-of-rust-per-proxy.md", "text": "https://wpnews.pro/news/zero-dependency-multi-profile-ai-browser-isolation-in-1-18-mib-of-rust-per-proxy.txt", "jsonld": "https://wpnews.pro/news/zero-dependency-multi-profile-ai-browser-isolation-in-1-18-mib-of-rust-per-proxy.jsonld"}}