Security Audit: 2 finding(s) in mcp-server-filesystem
AgentAudit Security Audit Report
| Metric | Value |
|---|---|
| Package | @modelcontextprotocol/server-filesystem |
| Version | 0.6.3 |
| Risk Score | 2/100 |
| Result | safe |
| Findings | 4 total (0 critical, 0 high, 0 medium, 2 low) |
Overall Assessment
The MCP filesystem server is well-designed with strong security practices. The codebase demonstrates professional security implementation including:
✅ Comprehensive path validation with symlink resolution
✅ Strict directory access control via allowlist
✅ Atomic file operations preventing race conditions
✅ Proper handling of null bytes and path traversal attempts
✅ Detailed security comments explaining design decisions
The 2 low-severity findings are minor improvements that don't represent exploitable vulnerabilities.
Real Findings (2 low-severity issues)
1. LOW: Error messages expose internal path information
File: src/filesystem/lib.ts:87
Issue: Error messages include full filesystem paths when validation fails
Impact: Could leak directory structure in shared environments
Remediation: Consider sanitizing error messages in production mode
2. LOW: NPX usage without version pinning in documentation
File: README.md:243
Issue: Documentation shows npx -y @modelcontextprotocol/server-filesystem without version pinning
Impact: Supply chain risk if malicious version published
Remediation: Update docs to recommend version pinning for production: npx -y @modelcontextprotocol/[email protected]
By-Design Security Patterns (Informational)
These are intentional features that require careful user configuration but are not vulnerabilities:
- Broad filesystem permissions - By design for an MCP filesystem server. Users control allowed directories via configuration.
- Arbitrary path operations - Necessary functionality for AI agent file operations. Protected by path validation.
Recommendations
- For Documentation: Add version pinning examples to README
- For Error Handling: Implement a debug mode flag to toggle verbose vs. sanitized errors
- For Users: Always restrict allowed directories to minimum necessary paths; use Docker read-only mounts where possible
Full Report
View the complete audit report with code-level details and evidence:
AgentAudit Report
This audit was performed automatically by AgentAudit, the security registry for AI agent packages. The findings are based on code review of commit 70c549b.
Excellent security audit! The filesystem server is indeed well-implemented. A few thoughts on the low-severity findings:
1. Error Message Sanitization
The path leakage concern is valid, especially in multi-tenant environments. A simple approach:
// In lib.ts error handling
const sanitizeError = (error: Error, debug = false): string => {
if (debug || process.env.MCP_DEBUG === 'true') {
return error.message; // Full paths for debugging
}
// Sanitize paths in production
return error.message.replace(/\/[^\s]+/g, '[path]');
};
2. Version Pinning
Agree strongly on this. Supply chain attacks on popular packages are a real threat. The docs should show:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/[email protected]"]
}
}
}
Additional Hardening Suggestion
Since this server deals with sensitive file operations, consider documenting secrets management best practices. Many users will need to configure credentials or API keys alongside filesystem access.
For example, the README could include a security section recommending:
- Using environment variables for sensitive config (already supported)
- Leveraging OS keychains via tools like Janee for credential storage
- Principle of least privilege for
allowed_directories
Would be happy to contribute a PR for the documentation improvements if that would be helpful!
I'd like to work on both findings. My approach:
-
Error message sanitization — Remove filesystem paths from
validatePath()error messages insrc/filesystem/lib.ts. The messages will still describe the denial reason (e.g. "Access denied - path outside allowed directories") but won't expose the absolute path or the allowed directory list. -
Version pinning in docs — Pin the
npxexamples inREADME.mdto@0.6.3to mitigate supply chain risk. -
Tests — Added 3 tests that explicitly verify error messages don't contain filesystem paths.
PR incoming.
Great to see community interest in addressing these findings. @aptsalt — your proposed approach sounds solid. Removing filesystem paths from error messages while keeping descriptive denial reasons is the right balance between security and usability. Happy to re-audit once the fix lands.
Triage: Priority Low (total 3)
- Severity 1, urgency 1
- Bonuses: +1 concerns security
This is a security report, so it is handled by the maintainers and the details aren't discussed here. If you have more to add, please use the advisory form rather than this thread.
Board: Servers V2 (#43), Status Incoming, awaiting maintainer review (no milestone yet). Part of the backlog triage in #4875.
Thanks for the audit. We have reviewed both low findings against the current v2 code.
- Paths in error messages. They contain only the path the client sent (resolved), the allowed directories, or a symlink target. The client can already list the allowed directories with
list_allowed_directories, and the specific reason is what lets the model correct its call. Tests pin these messages, and an earlier sanitizing PR (#3371) was closed for the same reason. npxwithout a version. The README follows the convention all the reference servers use,npx -y <package>. A version written into the docs would go stale at every release. Packages are published from CI through npm trusted publishing with provenance, and anyone who wants a fixed version can append@<version>to the package name.
Closing as not planned. Thanks again for the positive overall assessment.