A transparent proxy-based cookie firewall built on mitmproxy + Electron.
Browser (Electron)
↓ all HTTP/S traffic
mitmproxy :8080 ← CookieShield engine (engine.py)
│
└── FastAPI :5000 ← REST API + SSE log stream (GET /api/logs)
The frontend (index.html) connects to the SSE stream with a native
EventSource('http://127.0.0.1:5000/api/logs') — no extra library needed.
pip install mitmproxy fastapi uvicornNote:
flask,flask-cors, andwebsocketsare NOT needed.
The engine uses FastAPI + uvicorn with Server-Sent Events.
npm installRun mitmproxy once so it generates its self-signed CA:
mitmdump --listen-port 8080Then install the generated certificate:
| OS | Location | Action |
|---|---|---|
| macOS | ~/.mitmproxy/mitmproxy-ca-cert.pem |
Keychain Access → trust for SSL |
| Linux | ~/.mitmproxy/mitmproxy-ca-cert.pem |
Follow your distro's CA install steps |
| Windows | %USERPROFILE%\.mitmproxy\mitmproxy-ca-cert.p12 |
Double-click → install to Trusted Root |
npm startThe Electron app will:
- Spawn
mitmdump -s engine.py --listen-port 8080 --ssl-insecure - The
CookieShield.running()hook starts FastAPI (uvicorn) on port 5000 - Electron routes all its traffic through
127.0.0.1:8080
(loopback addresses bypass the proxy so the UI can reach the API directly) - Load
index.htmlwhich polls/api/stateevery 2 s and subscribes to/api/logsvia SSE
mitmdump -s engine.py --listen-port 8080Then open index.html directly in any browser (configure the browser's proxy
to 127.0.0.1:8080 manually).
| Mode | Outbound (request) | Inbound (Set-Cookie) |
|---|---|---|
| Reject All | Poisons all known tracker cookies | Drops all tracker Set-Cookie headers |
| Essential Only | Poisons trackers, keeps session/auth | Drops trackers, keeps essentials |
| Custom | Respects per-site trust/block list | Drops only from explicitly blocked hosts |
Trusted sites always bypass all cookie filtering.
| Port | Service |
|---|---|
| 8080 | mitmproxy intercept proxy |
| 5000 | FastAPI REST API + SSE log stream (GET /api/logs) |
| Symptom | Likely cause | Fix |
|---|---|---|
| Proxy pill stays OFF | mitmproxy not found | pip install mitmproxy, ensure mitmdump is on your PATH |
| SSE terminal says "Retrying…" | FastAPI not started yet | Wait 2–3 s after launch; engine starts async |
| HTTPS sites show SSL error | CA cert not trusted | Re-do Step 3 above |
npm start fails |
Electron not installed | Run npm install first |
| Port 5000 already in use | Another process on 5000 | lsof -i :5000 and kill it, or change the port in engine.py + index.html |