mcp-sanitizer: Path Traversal via Improper Home Directory Validation
The mcp-sanitizer library v1.3.3 permits path traversal by whitelisting /home/ and /Users/ in its validation logic, allowing unauthenticated attackers to read sensitive user configuration files.
Triage facts
Revision 1- Applicability
- mcp-sanitizer (v1.3.3)
- Evidence
- Unknown
- Severity
- High
- Action
- Elevated
- Sources
- 1 public source
- Freshness
- Revision 1Oct 29, 00:17 UTC
- Source quality
- A6Very likely
The mcp-sanitizer library v1.3.3 contains a critical path traversal vulnerability (CWE-22) in its validateFilePath function within src/utils/validation-utils.js. The library implementation includes an overly permissive allowlist for absolute file paths, explicitly permitting any path starting with /home/ or /Users/. Consequently, security validation fails to block access to highly sensitive files such as SSH keys, AWS credentials, and Kubernetes configurations.
Attack Chain
- Attacker sends a POST request to an MCP-enabled application using the
mcp-sanitizermiddleware. - The application passes an attacker-supplied
file_pathtosanitizer.sanitize(). - The
validateFilePathfunction normalizes the input and performs an allowlist check. - Because the malicious path (e.g.,
/home/victim/.ssh/id_rsa) matches the hardcoded/home/prefix, the validator returnsblocked=false. - The library returns the path to the consumer application as a "trusted" sanitized value.
- The consumer application, trusting the sanitizer's output, performs a filesystem read operation (e.g.,
fs.readFile) on the attacker-controlled path. - The application returns the contents of the sensitive file to the attacker in the HTTP response.
Impact
Successful exploitation allows unauthenticated remote attackers to exfiltrate sensitive user-home directory files, including SSH private keys, cloud provider credentials, and application tokens. This results in complete confidentiality loss for the affected user's data and potential lateral movement into cloud infrastructure or remote systems.
Recommendation
- Update any application utilizing
mcp-sanitizerto implement strict path validation that excludes sensitive home directory sub-paths, even if the library is not updated. - Implement a secondary layer of path validation in the application logic that explicitly denies access to
.ssh,.aws,.gnupg,.kube,.config, and.envfiles regardless of the sanitizer output. - Audit all MCP server implementations for dependencies on
mcp-sanitizerand restrict access to the/toolendpoint to authenticated and authorized users only.
Immediate actions
Audit applications using mcp-sanitizer for file access functionality
Threat Hunt
Search web server logs for suspicious POST requests to tool endpoints with paths containing home directory fragments
Data: Web server access logs, Application-level tool execution logs
Mitigations
Implement application-side filtering to block access to sensitive home directory sub-paths
CWE-22