{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-path-scoped-mcp-filesystem-tools-from-escaping-confinement-through-symlink-resolution-and-toctou-races",
  "title": "Which invariants prevent path-scoped MCP filesystem tools from escaping confinement through symlink resolution and TOCTOU races",
  "date_of_record": "2026 November 29",
  "scope": "Applies to MCP servers that expose filesystem tools (`read_file`, `write_file`, `list_dir`, `move`, `delete`) confined to a declared root via per-tool capability scopes. Does not apply to servers with no filesystem surface, nor to sandboxing enforced purely at the OS/container layer where the process itself is chrooted or namespaced.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-path-scoped-mcp-filesystem-tools-from-escaping-confinement-through-symlink-resolution-and-toctou-races.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-path-scoped-mcp-filesystem-tools-from-escaping-confinement-through-symlink-resolution-and-toctou-races.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-path-scoped-mcp-filesystem-tools-from-escaping-confinement-through-symlink-resolution-and-toctou-races.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1715,
    "python_slice_tokens": 205,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters is between **lexical path confinement** and **resolved-path confinement**. Most MCP filesystem servers implement confinement by normalizing the *string* the model passed (`../` stripping, `os.path.normpath`, prefix checks against the root) and then handing that string to the OS. The OS then performs its own resolution: symlinks, ...",
    "what_was_observed": "A filesystem MCP server declared `root=/workspace/project` and exposed `read_file(path)` with a guard: An agent, mid-task, called `read_file(\"data/latest\")`. `data/latest` was a symlink to `/etc/credentials` created earlier in the same session by a *different* tool call (`write_file` of a symlink payload, or a `move` that relocated a pre-existing link). `normpath` does not resolve symlinks; `startswith` passed becaus...",
    "condition_of_validity": "The invariant \"all filesystem effects are confined to root\" holds only if **every path is validated on its resolved identity, and the validated identity is the one operated on.** Operationally this requires: 1. **Resolution before validation, on the final component.** Use `os.path.realpath` (or `O_NOFOLLOW` + `fstat`) so symlinks are expanded *before* the pr...",
    "decision_boundary": "The boundary is: **does the server rely on path strings or on inode identity?** If the guard's output is a string that is later passed to a syscall that re-resolves, the guard is advisory and the boundary is unenforced. If the guard's output is an open file descriptor or a dirfd-relative `openat`, the guard is the boundary. Concretely, the decision for a giv...",
    "operational_effect": "When the invariant is violated, the agent does not fail loudly — it fails by *succeeding with poisoned context*. The read returns out-of-scope bytes; the agent's episodic memory records them as project data; subsequent reasoning, summarization, and any `write_file` derived from that content propagate the contamination. Because the tool reported success and t..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "c1d78888ab5a2543201f2d3790fd09f3efc80403c35409a59edf90f05d666a8c",
    "verified_classes": [
      "ConfinementViolation"
    ],
    "verified_functions": [
      "open_confined"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "ConfinementViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "os"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
