Offline, LLM-free filesystem/URI boundary-confinement auditor for the MCP
roots channel.
cordon replays a captured Model Context Protocol session and grades whether an
MCP server stayed inside the filesystem/URI boundaries the client declared via
roots — the mechanism the spec defines as "the boundaries of where servers
can operate." It decodes evasions, canonicalizes paths, and checks
segment-boundary containment, emitting a severity-weighted score, a letter
grade, and a CI exit-code gate. Pure Python standard library. No network, no
model, no filesystem access — it reasons about a capture, deterministically.
Series note: entries #011–#016 audited the tool-contract, MRT, Tasks, elicitation, sampling and authorization channels.
cordonis the series' first entry on therootscapability — the client→server boundary declaration. Where #016 (deputy) audited the OAuth/transport trust boundary,cordonaudits the filesystem/URI confinement boundary.
The MCP roots spec is a normatively soft boundary: clients MUST declare
roots and validate them against traversal, but servers are only told they
SHOULD "respect root boundaries." That MUST/SHOULD asymmetry is already
exploited in the wild — EscapeRoute (CVE-2025-53109/53110) escaped
Anthropic's own filesystem MCP server through a naive string-prefix check
(/tmp/allow_dir_sensitive slips past a /tmp/allow_dir prefix), and the MCP
Git server (CVE-2025-68143) leaked credentials via unvalidated tool-argument
paths. Existing MCP security tooling is mostly prompt-injection research or
runtime scanners; nobody grades, offline and reproducibly, whether a recorded
session actually stayed confined. cordon is the smallest thing that proves
that gap is auditable: a deterministic, dependency-free grader with a conformant
reference capture (100/A) and a malicious capture carrying ~25 ground-truth
breaches — including a confirmed /etc/passwd read outside the declared root.
| Family | Focus | Rules |
|---|---|---|
| A — declaration | Are the declared roots well-formed? | non-file:// scheme, bare path, non-absolute, empty set, overlap, .. in a root, filesystem-root over-breadth, non-local authority |
| B — containment | Did an access escape the active roots? (flagship) | out-of-root access (CRITICAL), access with no active roots |
| C — traversal/encoding | Evasion in the raw reference | .. dot-segments, percent-encoded traversal, backslash-on-POSIX, NUL/control chars |
| D — normalization | OS-specific bypasses | Unicode look-alike separators, trailing dot/space, device/UNC paths, drive-relative, 8.3 short names |
| E — scheme confusion | Non-file smuggling | non-file scheme (SSRF/exfil), file:// with a network authority |
| F — lifecycle | Dynamic-root correctness | stale (removed) root use, access before roots declared, list_changed not honored, access without the roots capability |
The containment engine (cordon/pathcanon.py) is deliberately lexical — a
passive auditor cannot realpath() a server it did not run — and uses a
segment-boundary prefix test, the exact fix for the EscapeRoute string-prefix
bug (encoded as test_is_within_rejects_sibling_prefix).
Requires Python 3.11+. No third-party runtime dependencies.
# One-command demo: audits both shipped fixtures and self-checks.
python main.py
# Audit any capture; exit code is the CI gate (0 pass / 1 fail / 2 usage error).
python -m cordon fixtures/malicious_capture.json
python -m cordon fixtures/conformant_capture.json --json
python -m cordon my_capture.json --min-score 95 --fail-severity medium
# Tests (pytest only dev dependency).
python -m pytest # 80 tests
# or: make run / make test / make audit-malicious| Flag | Default | Meaning |
|---|---|---|
--json |
off | machine-readable JSON report |
--min-score N |
90 | minimum passing score (0–100) |
--fail-severity S |
high |
lowest severity that fails the gate |
--no-gate |
off | always exit 0 (report only) |
A capture is a transport-agnostic, normalized timeline (a thin adapter can emit
it from real JSON-RPC traffic). Events are ordered by non-decreasing seq:
{
"session": "my-session",
"platform": "posix",
"capability": { "client_declares_roots": true, "supports_list_changed": true },
"events": [
{ "seq": 1, "type": "roots/list_result",
"roots": [ { "uri": "file:///home/dev/project", "name": "project" } ] },
{ "seq": 2, "type": "access", "origin": "resources/read",
"value": "file:///etc/passwd" },
{ "seq": 3, "type": "notifications/roots/list_changed" }
]
}type ∈ roots/list_result, roots/list_request,
notifications/roots/list_changed, access. An access origin ∈
resources/read, resource_template, resource_link, embedded_resource,
tool_argument. platform and capability are inferred from the timeline when
omitted. Malformed captures fail loudly (CaptureError) rather than being
silently skipped.
capture.json ──► capture.py (validate ─► typed model)
│
▼
rules.Auditor ── replays the timeline, maintaining the active
│ root set exactly as a correct server would
┌──────────────┼───────────────┐
▼ ▼ ▼
pathcanon.py rule families findings[]
(canonicalize, A B C D E F
is_within, │
evasion detectors) ▼
audit.py (score, grade, gate) ──► report.py (text | json) ──► cli.py (exit code)
Data flow: parse → validate → replay → detect → score → render → gate. The
auditor is a single left-to-right pass over the timeline; every finding carries a
rule id, severity, the offending seq, evidence, and remediation.
- Dynamic harness (like #011
gauntlet): actually drive a live filesystem MCP server through traversal payloads and observe real reads. Rejected for the prototype: needs a running server, a real (dangerous) filesystem with planted secrets, OS-specific symlink setup, and is non-reproducible in CI. - Passive, lexical capture auditor (chosen): grade a recorded session by
canonicalizing paths and checking containment structurally. Trade-offs:
- Memory/CPU: trivial — one pass, no I/O, no allocation beyond the finding list. Runs in milliseconds on any capture that fits in memory.
- Maintenance: the rule catalog is data + small pure functions; adding a bypass class is one detector + one test. No server matrix to keep alive.
- Cost: lexical analysis cannot resolve real symlinks or case-folding on the actual volume (see limitations); it flags the syntactic risk instead. For an offline, deterministic, CI-friendly gate this is the right altitude — and it still catches the EscapeRoute prefix bug that a real server shipped.
- Lexical, not filesystem-backed.
cordonnever touches disk. It cannot follow a real symlink or observe a case-insensitive volume's true mapping; it instead flags the syntactic constructs that enable such escapes (device paths, short names, trailing dots, Unicode separators, backslash-on-POSIX) even in a POSIX capture, because the server may run cross-platform. - Capture fidelity is the operator's job. Findings are only as complete as the recorded timeline. An adapter that drops accesses will under-report; the loader fails loudly on malformed events but cannot detect missing ones.
file://roots only. Matching the current spec, non-file://roots are flagged (A1) rather than confined.- Relative accesses are resolved against the active roots (a server whose working directory is a declared root). When multiple roots are active, an access contained by any is treated as confined.
- Scoring is a heuristic (CRITICAL −40, HIGH −20, MEDIUM −8, LOW −2, floored at 0). It ranks captures and drives the gate; it is not a calibrated CVSS.
- Spec version pinning is not yet enforced; the checks target the 2025-06-18
rootscontract.
python -m cordon fixtures/malicious_capture.json (abridged):
================================================================
cordon -- MCP roots confinement audit
session : malicious-root-escape
platform: posix capability: declared
================================================================
score : 0/100 grade : F
gate : FAIL (min-score 90, fail-at HIGH)
events: 22 accesses: 18 findings: 32
by severity: CRITICAL:4 HIGH:11 MEDIUM:10 LOW:7
================================================================
[CRITICAL] B1 Access escapes the active root boundary (seq 3, containment)
'/etc/passwd' is outside every active root (/home/dev/project, ...)
evidence : resources/read: file:///etc/passwd
fix : Canonicalize the path and reject it unless it is contained
in an active root (segment-boundary check).
[ HIGH] E1 Non-file scheme where a file was expected (seq 7, scheme)
scheme 'http' on a resources/read access
evidence : resources/read: http://169.254.169.254/latest/meta-data/...
[ HIGH] E2 file:// access with a non-local authority (seq 9, scheme)
file:// authority is 'attacker.com' (UNC/network)
[ HIGH] F1 Access uses a stale (removed) root (seq 22, lifecycle)
access resolves only into removed root 'file:///srv/shared/assets'
... (32 findings total across all six families)
================================================================
FAIL -- boundary breach(es) above threshold
================================================================
The conformant fixture scores 100 / A / PASS with zero findings.
python main.py runs both and self-checks that conformant passes and malicious
fails.
cordon/
pathcanon.py canonicalization + containment engine + evasion detectors
severity.py severity levels, score weights, grading
model.py capture schema, Finding, platform inference
capture.py load + fail-loud validation
rules.py 25-rule catalog + timeline Auditor (state machine)
audit.py scoring / grading / gate decision
report.py text + JSON renderers
cli.py argparse CLI + exit codes
main.py one-command demo / self-check
fixtures/ conformant_capture.json, malicious_capture.json
tests/ 80 tests (pathcanon, rules, capture, audit, cli)
MIT — see LICENSE.