Skip to content

About

deputy — offline, LLM-free confused-deputy & conformance auditor for captured MCP authorization (OAuth 2.1) flows. 29-rule catalog, scored CI gate, pure stdlib.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Development Experiment 016 — deputy

deputy is an offline, LLM‑free authorization‑flow safety & conformance auditor for the Model Context Protocol. It ingests a captured MCP OAuth 2.1 handshake and grades it against a 29‑rule catalog derived directly from the MCP Authorization specification (2025-11-25) and its companion Security Best Practices document — with a sharp focus on the confused‑deputy / token‑passthrough vulnerability class that dominated MCP security disclosures in 2026 (CVE‑2025‑6514 in mcp-remote, CVSS 9.6; repeated "one‑click account takeover" write‑ups).

It emits a scored report and a stable CI exit code. It needs no network, no API keys, and no model — just the standard library.


Thesis

Every prior entry in this series audits an MCP message channel (tools, elicitation, sampling, tasks, MRT). But the channel attackers actually monetized in 2026 is the one underneath the messages: OAuth authorization. The spec's own text is unusually emphatic here — "MCP servers MUST NOT accept any tokens that were not explicitly issued for the MCP server", "the MCP server MUST NOT pass through the token it received from the MCP client" — precisely because a single audience‑validation slip turns an MCP server into a confused deputy: a stolen or mis‑audienced token gets honored and then forwarded downstream, converting the server into an exfiltration proxy.

Those are structural properties of a captured flow. You do not need an LLM to see that a token's aud claim names a different service than the server that accepted it, or that the exact token bytes a client presented reappear on a request to a third‑party API. deputy proves that the smallest useful thing here is a passive log auditor: replay the captured handshake against the normative MUST/MUST‑NOT catalog and fail CI when the flow is exploitable as captured.

What it checks — the 29‑rule catalog

Family Focus Rules
A Discovery & Metadata (RFC 9728 / RFC 8414) A1–A6
B PKCE & Authorization Code (OAuth 2.1 §7.5) B1–B6
C Resource Indicators & Audience (RFC 8707) — confused‑deputy core C1–C7
D Token Transport & Hygiene (OAuth 2.1 §5) D1–D5
E Redirect & Transport Security (OAuth 2.1 §1.5) E1–E4
F SSRF & Metadata Hygiene (Security Best Practices) F1

The two flagship checks are C6 (server returned a success response to a token whose aud is not itself — audience‑validation failure) and C7 (the client's inbound token is forwarded verbatim to a downstream API — token passthrough). Together they are the confirmed, money‑moving exploit in the malicious fixture. Run deputy --list-rules for the full catalog with spec citations.

How to run

Requires Python 3.10+. No third‑party dependencies.

# audit a capture (text report), exit code reflects the verdict
python -m deputy fixtures/reference_capture.json      # -> PASS, exit 0
python -m deputy fixtures/malicious_capture.json      # -> FAIL, exit 1

# machine-readable output for CI dashboards
python -m deputy --format json fixtures/malicious_capture.json

# read the whole rule catalog
python -m deputy --list-rules

# raise the bar (default passing threshold is 80; CRITICAL always fails)
python -m deputy --threshold 95 mycapture.json

make run runs the reference audit; make test runs the suite; make demo shows both fixtures. On Windows without make, use the python -m deputy … commands above directly.

Exit codes (stable for CI)

Code Meaning
0 Audit passed — score ≥ threshold and no CRITICAL findings
1 Audit failed — below threshold, or at least one CRITICAL finding
2 Usage / input error — bad arguments, unreadable or malformed capture

The capture format

A capture is a small JSON document describing one end‑to‑end flow as an ordered list of HTTP exchanges — think of it as a HAR file specialized to the MCP auth handshake. You produce it however you like (a client middleware, an mitm proxy, a hand‑written fixture). Shape:

{
  "mcp_server": { "canonical_uri": "https://mcp.example.com/mcp" },
  "meta": { "audit_time_epoch": 1700000000 },        // "now" for expiry checks
  "exchanges": [
    { "id": "e1", "type": "resource_request",         // MCP client -> MCP server
      "request": { "method": "POST", "url": "..." },
      "response": { "status": 401, "headers": { "WWW-Authenticate": "Bearer resource_metadata=\"...\"" } } },
    { "id": "e2", "type": "prm_discovery",  "response": { "status": 200, "json": { /* RFC 9728 PRM */ } } },
    { "id": "e3", "type": "as_metadata",    "response": { "status": 200, "json": { /* RFC 8414 */ } } },
    { "id": "e4", "type": "authorization_request", "request": { "url": "https://as/authorize?..." } },
    { "id": "e5", "type": "token_request",  "request": { "body": { /* grant, code_verifier, resource */ } },
                                            "response": { "status": 200, "json": { "access_token": "..." } } },
    { "id": "e6", "type": "resource_request", "request": { "headers": { "Authorization": "Bearer ..." } } },
    { "id": "e7", "type": "downstream_request", "request": { "url": "https://api.third-party/...", "headers": { "Authorization": "Bearer ..." } } }
  ]
}

Tokens are read as JWTs when they look like one (three base64url segments; signatures are not verified — the auditor only reads claims like aud/exp/scope). Opaque tokens can be described in an optional top‑level token_directory mapping the token string to a claims object.

Architecture

capture.json ─▶ model.parse_capture ─▶ Capture ─▶ rules.RuleContext ─┐
                                                                      ├─▶ 29 rule fns ─▶ [Finding]
                       ┌──────────────────────────────────────────────┘
                       ▼
              analyzer.audit  ──▶  AuditReport (score, grade, pass/fail)  ──▶  report.to_text / to_json  ──▶  cli exit code
  • model.py — strict schema + parser (raises CaptureError with a precise message; never half‑parses).
  • canonical.py — RFC 8707 canonical‑URI equality, loopback detection, and IP‑range classification (ipaddress‑backed, no DNS).
  • jwt.py — unverified JWT payload decode + a deterministic test‑only encoder used to build fixtures.
  • rules.py — the RuleContext (one pass to pre‑extract PRM, AS metadata, authorize params, token req/resp, inbound tokens) and the 29 rule functions. Metadata (title, severity, normative keyword, spec citation) lives in RULE_META so it can be listed and rendered independently.
  • analyzer.py — severity‑weighted scoring, grading, and the pass gate.
  • report.py / cli.py — text/JSON rendering and the exit‑code contract.

Design trade‑offs

Passive log auditor vs. live probe. We audit a captured flow rather than driving a live OAuth handshake. A live prober would catch server‑side dynamics we can't (real token‑introspection behavior, timing), but it needs credentials, a running server, and network egress — none of which belong in a fast, deterministic CI gate. A passive auditor is reproducible, offline, and reviewable; the cost is that it only sees what the capture recorded. This mirrors the series' passive‑verifier lineage (Experiment 013) and is the right altitude for a pre‑merge check.

Unverified JWT decode vs. full validation. deputy reads token claims without verifying signatures. The rules it enforces (audience binding, passthrough, expiry‑vs‑acceptance) are about what a token claims and how it is used, not whether it is cryptographically valid — and we hold no keys. Decoding without verifying keeps the tool dependency‑free (no cryptography/JWKS) and can never itself make a trust decision. The jwt.py module says so in the loudest terms.

Static severity weights vs. configurable policy. Scoring uses fixed penalties (CRITICAL 25 / HIGH 12 / MEDIUM 6 / LOW 2) plus a hard "any CRITICAL ⇒ fail" gate. This is opinionated but predictable; the --threshold flag is the one knob. A fully configurable policy engine was considered and rejected as over‑engineering for a prototype.

Sample run

Reference (conformant) capture:

========================================================================
  deputy - MCP authorization confused-deputy auditor
========================================================================
  Server : https://mcp.example.com/mcp
  Score  : 100/100   Grade: A   Result: PASS (threshold 80, no CRITICAL allowed)
  Findings: 0  (CRITICAL 0, HIGH 0, MEDIUM 0, LOW 0)
========================================================================
  No findings. The captured flow conforms to the audited rules.
========================================================================

Malicious (confused‑deputy proxy) capture — the two flagship findings:

  Score  : 0/100   Grade: F   Result: FAIL (threshold 80, no CRITICAL allowed)
  Findings: 20  (CRITICAL 5, HIGH 10, MEDIUM 3, LOW 2)

[CRIT] C6 [MUST] Server accepted a token issued for a different audience
        family C  |  exchange: e6-resource
        AUDIENCE VALIDATION FAILURE: the server returned a success response to a token
        whose audience is ['https://drive.googleapis.example'], not this server
        ('https://mcp.evil-proxy.example/mcp'). ... the first half of a confused-deputy compromise.

[CRIT] C7 [MUST NOT] Token passthrough: client token forwarded to a downstream API
        family C  |  exchange: e7-exfil-downstream
        TOKEN PASSTHROUGH: the token the MCP client presented to the server is being
        forwarded verbatim to downstream API 'https://drive.googleapis.example/drive/v3/files'.
        The MCP server MUST NOT pass through the client's token -- this turns the server into
        an exfiltration proxy and breaks every downstream audit trail.

(Full 20‑finding report: python -m deputy fixtures/malicious_capture.json.)

Assumptions & limitations

  • Passive only. deputy reasons over the capture you give it; it does not fetch anything. Rules that need a fact absent from the capture (e.g. no token_request recorded) simply do not fire — absence is not evidence.
  • Signatures are not verified. By design (see trade‑offs). Do not treat deputy as a token validator; it audits conformance and usage, not cryptographic validity.
  • JWT or described tokens. Audience/expiry rules need readable claims: a JWT, or an entry in token_directory. Opaque tokens with no directory entry are skipped by claim‑based rules (their transport/passthrough rules still apply, since C7 compares raw token bytes).
  • audit_time_epoch in meta drives the expired‑token‑accepted check (D3). Omit it and D3 is skipped rather than guessing.
  • Expiry rules for expiry are the only time‑sensitive ones; everything else is time‑independent.
  • Scope of the catalog. 29 rules cover the authorization spec's normative surface plus the highest‑signal Security‑Best‑Practices attacks (confused deputy, token passthrough, SSRF, scope minimization, insecure transport, dangerous URL schemes). It is not a full OAuth 2.1 conformance suite; it is the MCP‑relevant, security‑critical subset.
  • Fixtures are generated deterministically by fixtures/build.py (which embeds the RFC 7636 Appendix B PKCE test vector). Re‑running it must not change the committed JSON.

Project layout

deputy/          canonical.py  jwt.py  model.py  finding.py  rules.py  analyzer.py  report.py  cli.py
fixtures/        build.py  reference_capture.json  malicious_capture.json
tests/           test_canonical.py  test_jwt.py  test_model.py  test_rules.py  test_analyzer_cli.py

License

MIT — see LICENSE.

About

deputy — offline, LLM-free confused-deputy & conformance auditor for captured MCP authorization (OAuth 2.1) flows. 29-rule catalog, scored CI gate, pure stdlib.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages