security: constrain READ_FILE to granted dirs; validate command paths before basename - #22
Merged
Merged
Conversation
… before basename Two low-severity file/command access gaps from the audit: - READ_FILE IPC handler (ipc/content-handlers.ts) ran only validateFilePath (length / '..'), so any absolute path outside the granted directories was readable. Add isPathWithinAllowedDirs (shared/file-access-types.ts) and gate the read on the FileAccessManager's granted directories. - validateCommand (utils/mcp-sanitizer.ts) checked ALLOWED_COMMANDS.has(basename) BEFORE the safe-directory rule, so /tmp/evil/python3 or ./evil/python3 passed just because the basename was allowlisted. The basename allowlist now applies ONLY to bare command names; any path is validated as a path (absolute → must be in a safe dir; relative → rejected). Tests (red before fix): mcp-sanitizer.test.ts (unsafe-dir / relative-path escapes), file-access-types.test.ts (isPathWithinAllowedDirs). Full suite green, tsc clean. Note: builds on the isPathSafe sibling-prefix fix (same branch family). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ersetzt #20 (wurde beim Löschen des #18-Branches automatisch geschlossen; #18 ist inzwischen in main).
Was
Zwei Low-Findings zu Datei-/Command-Zugriff.
Änderungen
ipc/content-handlers.ts): geprüft wurde nurvalidateFilePath(Länge/..) → jeder absolute Pfad ausserhalb der Grants war lesbar. Neu:isPathWithinAllowedDirs(shared/file-access-types.ts) gated den Read gegen dieFileAccessManager-Grants.utils/mcp-sanitizer.ts):ALLOWED_COMMANDS.has(basename)lief vor der Safe-Dir-Regel →/tmp/evil/python3/./evil/python3passierten. Die Allowlist gilt jetzt nur für bare Namen; jeder Pfad wird als Pfad validiert.Tests
Die bestehenden mcp-sanitizer-Tests (validateCommand/Args/Env) bleiben erhalten und grün mit dem Fix; meine Escape-Tests +
isPathWithinAllowedDirs-Tests ergänzt. Volle Suite: 1325 passed,tscclean.Dokumentation
Security-Audit (2026-08-21), Mingly Low-Findings (READ_FILE, mcp-sanitizer).
🤖 Generated with Claude Code