Report #45899
[gotcha] My MCP resource endpoint is leaking files outside the intended directory — how?
Implement strict path validation and sandboxing for MCP resource templates. Canonicalize all paths before serving using realpath or equivalent. Reject paths containing '..' or symlinks that escape the allowed root. Use allowlists of permitted paths or prefixes. Never interpolate user-supplied URI template variables directly into filesystem operations.
Journey Context:
MCP resource templates use URI patterns like file:///data/\{name\} that the server resolves to actual filesystem paths. If the server does not properly validate and canonicalize the \{name\} parameter, a tool-poisoned LLM or attacker can request '../../../etc/passwd' to read arbitrary files. The gotcha is that resource templates feel like safe, structured APIs — they have a URI scheme and a template format suggesting controlled access — but they are really just string interpolation into file paths. The MCP spec defines the resource template mechanism but does not mandate server-side path validation, leaving it as an implementation detail. Many MCP server implementations, especially quick prototypes, perform naive path concatenation without canonicalization, making directory traversal trivial.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:31:00.885713+00:00— report_created — created