Building ScamShield AI: Week 3 โ The Dual-Network Trap: Locking Down a Headless Browser Sandbox
๐ก๏ธ ScamShield AI: Week 3 Build Log The Dual-Network Trap: Building an Adversarially Verified Browser Sandbox ๐จ The Mission This Week In Week 2, we tackled Stage 1: hardening our inspection proxy
๐ก๏ธ ScamShield AI: Week 3 Build Log
The Dual-Network Trap: Building an Adversarially Verified Browser Sandbox
๐จ The Mission This Week
In Week 2, we tackled Stage 1: hardening our inspection proxy with fail-closed iptables and SSRF prevention.
This week was all about Stage 2 & Stage 3: The Browser Container & Orchestration.
The goal: Run an automated Headless Chromium browser to visit live, weaponized scam URLs (fake bank KYC portals, malicious APK delivery pages, phishing sites) without allowing the attacker to attack our infrastructure.
If an exploited page escapes Chromium, it must find itself trapped in an isolated network with zero default gateway, zero direct internet, and zero ambient privileges.
Here is how we designed a dual-network sandbox, killed covert egress channels (WebRTC, QUIC, DoH), preserved Chromium's internal sandbox, and verified it against a 25-checkpoint adversarial test matrix.
๐๏ธ Architecture: The "Air-Gapped" Dual-Network Model
Most Docker setups connect containers to a single shared bridge network. If you run a browser that visits malicious URLs on a standard Docker bridge:
- It has a default gateway to the public internet.
- It can directly query Docker's embedded DNS server (
127.0.0.11). - An attacker can bypass your inspection proxy simply by using unproxied UDP sockets, direct IP connections, or raw sockets.
To prevent this, we created a Dual-Network Architecture:
[ Malicious URL / External Web ]
โฒ
โ (Public Traffic Only)
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ scamshield_external โ (Standard Docker Bridge with Internet)
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ eth1
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Track C Inspection Proxy โ (Dual-Homed: eth0 + eth1)
โ (mitmdump + iptables) โ - Forwarding DISABLED in kernel
โโโโโโโโโโโโโโโฒโโโโโโโโโโโโโโ - Strict boundary between doors
โ eth0 (172.28.10.2)
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ scamshield_internal โ (INTERNAL ISOLATED NETWORK)
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ - NO Gateway (gateway: null)
โ - NO External DNS
โผ eth0 (172.28.10.3)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Browser Sandbox Container โ (Zero ambient capabilities)
โ (Chromium / Playwright) โ - CapDrop=ALL, NoNewPrivs=true
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ - CAN ONLY TALK TO 172.28.10.2:8080
The Rules of the Sandbox:
-
The Browser Container sits exclusively on
scamshield_internal. It has no default route to the internet. If it tries to send a packet directly to8.8.8.8or169.254.169.254, the kernel immediately raisesENETUNREACH(Network is unreachable). -
The Proxy Container is dual-homed. It listens on
eth0(internal door) and fetches outbound traffic througheth1(external door). -
Kernel IP Forwarding is Disabled: The proxy container is explicitly forbidden from routing packets between interfaces (
net.ipv4.ip_forward = 0). It operates purely at the application layer via our vetted inspection addon.
๐ง Lesson 1: The "Lazy Docker" Anti-Pattern (--no-sandbox)
Search for "Playwright inside Docker" on StackOverflow or GitHub, and almost every tutorial tells you to launch Chromium like this:
# โ THE DANGEROUS WAY
browser = playwright.chromium.launch(
args=["--no-sandbox", "--disable-setuid-sandbox"]
)
Never do this in a security system.
--no-sandbox completely disables Chromiumโs multi-process defense-in-depth isolation. If a malicious web page uses a zero-day exploit to trigger a heap overflow in the V8 JavaScript engine or Blink rendering engine, the attacker instantly gets arbitrary code execution inside the container.
๐ ๏ธ How We Kept the Native Sandbox Enabled:
Instead of running as root and disabling the sandbox, we:
- Created an unprivileged user (
UID 1001,browseruser). - Dropped all ambient Linux capabilities (
--cap-drop=ALL). - Set
no-new-privileges:true. - Allocated sufficient shared memory (
shm_size: 1gb) to prevent renderer crashes. - Allowed Chromium to leverage Linux unprivileged user namespaces (
kernel.unprivileged_userns_clone=1).
The result: Chromium's internal process sandbox remains fully active. An attacker must break out of Chromium's sandbox first, and even then, they are trapped in a capability-stripped container with no network route.
๐ฅท Lesson 2: Covert Egress Leaks (WebRTC, QUIC, and DoH)
Modern browsers are designed to bypass restrictive networks to deliver real-time communication and low latency. When designing a sandbox, these features become critical data exfiltration and proxy-bypass vectors:
- WebRTC STUN/TURN Requests: WebRTC attempts to establish direct peer-to-peer UDP connections. If an attacker puts a WebRTC script on their page, Chromium will send raw UDP packets containing local network IPs to external STUN servers, completely bypassing HTTP proxies!
- QUIC (HTTP/3) over UDP/443: Modern web servers negotiate QUIC over UDP. Because traditional proxies operate on TCP, unmediated QUIC requests can slip past inspection or fail unpredictable connections.
-
DNS-over-HTTPS (DoH): If the browser resolves domain names over encrypted HTTPS directly to Cloudflare (
1.1.1.1) or Google (8.8.8.8), your proxy never gets to evaluate DNS rebinding or domain reputation!
๐ ๏ธ Hardened Runtime Flags:
In our browser worker launcher (run_scan.py), we explicitly locked down Chromium's engine flags:
HARDENED_CHROMIUM_FLAGS = [
# Force ALL traffic through the inspection proxy
f"--proxy-server={PROXY_HOST}:{PROXY_PORT}",
# Kill covert UDP/STUN leaks
"--disable-webrtc",
"--webrtc-ip-handling-policy=disable_non_proxied_udp",
"--enforce-webrtc-ip-permission-check",
# Block QUIC / HTTP/3 evasion (forces standard HTTP/1.1 & HTTP/2 over proxy tunnel)
"--disable-quic",
# Disable internal DNS-over-HTTPS & asynchronous background resolvers
"--disable-features=DnsOverHttps,AsyncDns",
# Block background sync, metrics, and cloud communications
"--disable-background-networking",
"--disable-component-update",
"--disable-default-apps",
"--disable-sync",
]
๐ Lesson 3: What Happens When the Proxy Dies? (Testing the Fail-Closed Boundary)
A core principle of secure architecture is: A failure must never degrade security.
What happens if our proxy container runs out of memory, segfaults, or gets killed by Docker? Does the browser fall back to direct connections?
To verify this, we wrote an automated adversarial test:
- Spin up the browser and proxy stack.
- In the middle of an active scan, execute
docker kill scamshield-track-c-proxy. - Attempt to trigger page navigations from the browser.
The Result:
Because the browser container has no gateway on scamshield_internal, any attempt to navigate immediately throws ERR_PROXY_CONNECTION_FAILED. It cannot fall back to direct internet because the host kernel simply has no physical route for it. Fail-Closed guaranteed.
๐งช The 25-Checkpoint Adversarial Matrix
To ensure our security claims are mathematically sound and verifiable on every git commit, we implemented a full live adversarial test suite (test_track_c_compose_security.py).
| Category | Checks | Adversarial Scenario Tested | Result |
|---|---|---|---|
| 1. Direct Egress Blocks | Checkpoints 1โ8 | Attempting direct TCP/UDP connections to Public IPs (1.1.1.1), AWS Metadata (169.254.169.254), RFC1918 subnets (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), and IPv6 (::1, fc00::1). |
๐ข ENETUNREACH (Blocked)
|
| 2. DNS Leakage & Rebinding | Checkpoints 9โ15 | Direct port 53 UDP/TCP queries, Docker embedded DNS resolution of external hostnames, DNS rebinding to internal infrastructure. | ๐ข NXDOMAIN / 502 Bad Gateway |
| 3. Complex Web Attack Vectors | Checkpoints 16โ23 | Cross-origin 302 redirects to prohibited IPs, subresource injection (<img src="http://127.0.0.1:port">), iframe smuggling, WebSocket tunnels, and WebRTC STUN leaks. |
๐ข Refused / Blocked by Proxy |
| 4. Confinement & Crash Testing | Checkpoints 24โ25 | Hard proxy termination (docker kill) fail-closed verification, non-root user verification (UID 1001), capability verification (CapEff=0), and Chromium sandbox state. |
๐ข Strictly Confined & Fail-Closed |
๐ Project Status: Sandbox Frozen! ๐ง
With this week's sprint completed:
- All 143 Track C integration, regression, and Docker security tests are 100% green.
- The Track C Sandbox Architecture is officially FROZEN.
We now have a bulletproof, isolated environment capable of receiving hostile, weaponized URLs, following redirects, taking screenshots, and inspecting DOM structures without exposing our backend servers, cloud keys, or internal network.
๐ What's Up Next?
Now that the sandbox is secure and locked down, we move to Pipeline Integration:
- Wire the FastAPI backend directly to our Docker Compose runner via an asynchronous worker queue.
- Structure the returned forensic artifacts (redirect chains, DOM password/OTP inputs, screenshot buffers) for the Deterministic Risk Aggregation Engine.
- Begin baseline dataset curation for Track D (The Multilingual Transformer Model) on our local RTX 5050 GPU.
๐ฌ Discussion
How do you prevent DNS leaks and WebRTC bypasses when running headless browsers for crawling or threat intelligence? Have you ever had a container escape or SSRF bypass slip past unit tests?
Let's discuss in the comments below! ๐
Follow our build-in-public journey on GitHub: github.com/Siddharthrane07/scamshield`
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.