Files
modelcontextprotocol--pytho…/tests/shared
Max Isbey e5ecf50e64 feat: add filesystem path safety primitives
Adds `mcp.shared.path_security` with three standalone utilities for
defending against path-traversal attacks when URI template parameters
flow into filesystem operations:

- `contains_path_traversal()` — base-free component-level check for
  `..` escapes, handles both `/` and `\` separators
- `is_absolute_path()` — detects POSIX, Windows drive, and UNC
  absolute paths (which silently discard the base in `Path` joins)
- `safe_join()` — resolve-and-verify within a sandbox root; catches
  `..`, absolute injection, and symlink escapes

These are pure functions usable from both MCPServer and lowlevel
server implementations. `PathEscapeError(ValueError)` is raised by
`safe_join` on violation.
2026-03-26 17:42:18 +00:00
..