Skip to main content
Glama
README.md
# Integrity Web Gate

**The Safe 3-Tier Web Driver & Execution Firewall MCP for AI Agents, DevOps & Legacy Web UIs.**

Give AI agents (Claude Desktop, Cursor, Antigravity, Codex, custom Python pipelines) fast, structured, SSRF-hardened web and API access — with zero mandatory third-party dependencies, automatic Playwright escalation only when JavaScript requires it, and a transactional `Plan -> Preimage -> GO -> Verify -> Rollback` execution firewall for state-changing writes.

---

## 3-Line Quickstart

```bash
pip install integrity-web-gate          # 100% Python 3.11+ stdlib core (zero mandatory deps)
integrity-web-gate doctor               # Verify Tier-1 HTTP, 25 recipes, Tier-3 Playwright & MCP
python examples/quickstart_60s.py       # Self-contained local 60-second end-to-end demo
```

Optional extras:

```bash
pip install "integrity-web-gate[browser]"   # Tier-3 Playwright Chromium escalation
pip install "integrity-web-gate[h2]"        # Optional HTTP/2 framing support
pip install "integrity-web-gate[dev]"       # pytest development suite
```

### MCP Client Configuration (Claude Desktop / Cursor / Antigravity)

Add `integrity-web-gate-mcp` to your MCP server config (`claude_desktop_config.json`, `.cursor/mcp.json`, or Antigravity MCP config):

```json
{
  "mcpServers": {
    "integrity-web-gate": {
      "command": "integrity-web-gate-mcp",
      "args": []
    }
  }
}
```

Exposes 9 hardened JSON-RPC 2.0 stdio tools: `web_probe`, `web_fetch`, `web_extract`, `web_plan_write`, `web_apply_write`, `web_record_cassette`, `web_replay_cassette`, `web_learn_recipe`, and `web_fleet_scan`.

---

## Real Local Benchmarks

Reproducible, zero-mock local benchmark (`python benchmarks/bench_http_vs_playwright.py` on Python 3.12, Windows, `127.0.0.1:0` ephemeral server; raw data in [`benchmarks/latest_results.json`](benchmarks/latest_results.json)):

| Workload | Latency / Throughput | Payload Size | Est. LLM Tokens (`chars/4`) | Notes |
| :--- | :---: | :---: | :---: | :--- |
| **Tier-1 Sync HTTP + Markdown Extract** (`SwissArmyDriver`) | **7.37 ms avg** (p50 `5.79 ms`, p95 `23.05 ms`) | 2,737 B | **684 tokens** | **81.9% fewer tokens** than raw HTML |
| **Tier-1 Sync HTTP JSON API** (`UniversalTransport`) | **1.04 ms** | 104 B | **26 tokens** | Keep-Alive stdlib socket engine |
| **Tier-1 Async Fleet** (`AsyncFleetRunner`, 200 reqs @ 40 conc.) | **127.61 ms total (`1,567.3 req/s`)** | 200/200 OK | — | p50 `31.0 ms`, p95 `32.0 ms`, 0 failures |
| **Tier-3 Playwright Chromium** (Cold launch + load) | 566.95 ms | 15,100 B | 3,775 tokens | Full headless Chromium DOM |
| **Tier-3 Playwright Chromium** (Warm reload avg) | 24.88 ms (p50 `22.54 ms`) | 15,100 B | 3,775 tokens | **3.4x slower** than Tier-1 warm |
| **Tier-3 Login -> `handoff_to_http()` -> Tier-1 `/api/me`** | **10.70 ms** (after `325.81 ms` SPA login) | 1 cookie transferred | — | Browser auth -> fast HTTP session |

All 4 inline security gates verified during benchmark execution:
- `169.254.169.254` cloud metadata SSRF: **BLOCKED** (`SSRFBlockedError`)
- `Authorization` & `Set-Cookie` headers: **SCRUBBED** (`SecretScrubber`)
- `apply_write` without Owner GO token: **REFUSED** (`GoRequiredError`)
- Cloudflare Turnstile / CAPTCHA page: **FAIL-CLOSED** (`ChallengeBlockedError`)

---

## 3-Tier Architecture

```
                         +------------------------------------+
                         |  AI Agent / CLI / MCP Stdio Client |
                         +-----------------+------------------+
                                           |
                    +----------------------v----------------------+
                    |   Execution & SSRF Firewall (Security Gate) |
                    |  DNS-once IP Pinning | SecretScrubber | GO  |
                    +------+---------------+---------------+------+
                           |               |               |
         +-----------------+     +---------+---------+     +-------------------+
         v                       v                   v                         v
+-----------------+    +-------------------+   +-------------------+   +---------------+
| Tier 1: Stdlib  |    | Tier 2: 25 JSON   |   | Tier 3: Optional  |   | Compliant     |
| HTTP/1.1 + Async|    | Declarative       |   | Playwright        |   | Human-Handoff |
| Fleet Engine    |<-->| Recipes & Learner |<->| Chromium Adapter  |-->| (SSO / MFA /  |
| (Zero Deps)     |    | (Zero eval/exec)  |   | (Cookie Handoff)  |   |  CAPTCHA)     |
+-----------------+    +-------------------+   +-------------------+   +---------------+
```

1. **Tier 1 — Stdlib HTTP/TLS & Async Fleet**: Pure Python 3.11+ socket/TLS transport (`UniversalTransport`) and `asyncio` concurrent runner (`AsyncFleetRunner`) with Keep-Alive pooling, HTTP/0.9 legacy fallback, RSA/Digest/CSRF/Form auth strategies, and offline scrubbed cassette record/replay.
2. **Tier 2 — Declarative Recipe Engine & Auto-Learner**: 25 validated JSON recipes (strictly zero `eval`/`exec`/`import`) plus `RecipeLearner` (`webdrv learn`) to auto-generate declarative recipes from live endpoints.
3. **Tier 3 — Browser Escalation & Cookie Handoff**: Optional Playwright Chromium adapter (`BrowserEscalationAdapter`) for JS-heavy SPAs with bidirectional session transfer (`handoff_to_http()` / `escalate_from_http()`) so agents authenticate once in Chromium and drop straight back to Tier-1 HTTP speed.
4. **Compliant Human-Handoff**: When a target presents MFA, SSO, or anti-bot challenges, `HumanHandoffCoordinator` pauses fail-closed and opens a local headed session for a human operator to complete sign-in — never attempting CAPTCHA bypass.

---

## Security Model

Hardened across 33 adversarial Red Team findings:

- **DNS-Once IP Pinning & SSRF Firewall**: Resolves DNS once, validates all IPs against loopback/RFC1918/link-local/cloud-metadata (`169.254.169.254`, IPv4-mapped IPv6 `::ffff:127.0.0.1`, NAT64, 6to4, Teredo), and pins the validated socket IP to prevent DNS rebinding and redirect-to-internal attacks.
- **Keep-Alive Anti-Smuggling**: Strict `Content-Length` / `Transfer-Encoding` validation, header byte caps, response size caps, and automatic connection reset on malformed framing.
- **SecretScrubber**: Automatically redacts `Authorization`, `Cookie`, `Set-Cookie`, Bearer/JWT tokens, passwords, and API keys from logs, MCP responses, telemetry, and recorded cassettes.
- **Fail-Closed CAPTCHA & Anti-Bot Policy**: Detects Cloudflare Turnstile, reCAPTCHA, hCaptcha, and login lockouts (`LockoutBreaker`) and aborts with exit code `6` (`ChallengeBlockedError`) rather than brute-forcing or bypassing.
- **Transactional Write Firewall (`Plan -> Preimage -> GO -> Verify -> Rollback`)**: Every mutating write captures a live SHA-256 preimage, checks drift under a per-target `DeviceLock`, enforces an explicit `owner_go` approval token (`GoVerifier`), verifies post-write state, and writes an executable `rollback_plan.json`.

---

## 25 Built-In Declarative Recipes + `webdrv learn`

Shipped inside the package (`integrity-web-gate recipes`):

- **APIs & Web Standards**: `generic_json_api`, `generic_form_csrf`, `graphql_endpoint`, `openapi_swagger`, `html_article_docs`, `html_data_table`, `rss_atom_feed`, `sitemap_xml`, `statuspage_health`, `github_public_repo`
- **DevOps & Cloud Control Planes**: `prometheus_metrics`, `grafana_api`, `traefik_dashboard`, `portainer_api`, `proxmox_ve`, `jenkins_web`, `wordpress_admin`
- **Network & Legacy Embedded Web UIs**: `mikrotik_webfig`, `tplink_smart_switch`, `zyxel_web_switch`, `bdcom_web_olt`, `hikvision_isapi`, `des1210_iss`, `des1228_classic`, `des3028_rompager`

Generate a custom recipe for any internal panel in one command:

```bash
webdrv learn http://127.0.0.1:8080 --name my_panel --out my_panel.json --allow-loopback
```

---

## Honest Comparison

| Capability | Integrity Web Gate | Playwright MCP | `httpx` / `requests` | Netmiko | Firecrawl |
| :--- | :---: | :---: | :---: | :---: | :---: |
| Mandatory dependencies | **0 (stdlib)** | Node + Chromium | 4–8 packages | Paramiko/TextFSM | Cloud API / Docker |
| SSRF / DNS-rebinding firewall | **Built-in** | Manual | None | N/A | Managed SaaS |
| Transactional write `Plan -> GO -> Rollback` | **Built-in** | None | None | Manual | Read-only |
| Token-efficient Markdown/JSON extraction | **81.9% smaller** | Raw DOM/a11y | Raw HTML | CLI text | Markdown |
| Tier-1 -> Tier-3 Cookie Handoff | **Built-in** | Browser-only | HTTP-only | SSH-only | Managed |
| Legacy embedded HTTP/0.9 & switch Web UIs | **Built-in** | Fragile | Breaks on HTTP/0.9 | SSH/Telnet | No |
| Native stdio MCP server | **Built-in (9 tools)** | Built-in | No | No | Separate MCP |

---

## License

MIT License — see [`LICENSE`](LICENSE).

TDQS

A3.5/5.0

Scored across 9 tools

Disambiguation4/5

Each tool has a fairly distinct role: read-only fetch, extraction, fleet scanning, recipe learning, probing, cassette record/replay, and plan/apply write. The closest boundaries are web_probe vs web_learn_recipe (fingerprint existing recipes vs generate a new one) and web_fetch vs web_extract (raw fetch vs structured extraction), but descriptions clarify these adequately.

Naming Consistency4/5

All nine tools share a consistent web_ prefix and snake_case, with mostly verb_noun structure (web_fetch, web_extract, web_probe, web_learn_recipe, web_fleet_scan, web_record_cassette, web_replay_cassette). The write pair web_plan_write and web_apply_write slightly deviates with a noun_verb ordering, but remains predictable.

Tool Count5/5

Nine tools is well within the ideal 3-15 range and each tool occupies a distinct niche in the read/extract/test/plan/write lifecycle. No tool feels redundant or trivially padding the surface.

Completeness4/5

The surface covers read-only fetching, extraction, fleet scanning, recipe discovery/learning, offline record/replay, and a guarded plan/apply write lifecycle, which is strong lifecycle coverage. Minor gaps exist around explicitly managing or listing plans/recipes or audit artifacts, but core workflows are workable.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues