Skip to content

security: constrain READ_FILE to granted dirs; validate command paths before basename - #22

Merged
Baldri merged 1 commit into
mainfrom
claude/session/fix/mingly-readfile-mcp-v2
Aug 22, 2026
Merged

security: constrain READ_FILE to granted dirs; validate command paths before basename#22
Baldri merged 1 commit into
mainfrom
claude/session/fix/mingly-readfile-mcp-v2

Conversation

@Baldri

@Baldri Baldri commented Aug 22, 2026

Copy link
Copy Markdown
Owner

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

  • READ_FILE (ipc/content-handlers.ts): geprüft wurde nur validateFilePath (Länge/..) → jeder absolute Pfad ausserhalb der Grants war lesbar. Neu: isPathWithinAllowedDirs (shared/file-access-types.ts) gated den Read gegen die FileAccessManager-Grants.
  • mcp-sanitizer (utils/mcp-sanitizer.ts): ALLOWED_COMMANDS.has(basename) lief vor der Safe-Dir-Regel → /tmp/evil/python3 / ./evil/python3 passierten. 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, tsc clean.

Dokumentation

Security-Audit (2026-08-21), Mingly Low-Findings (READ_FILE, mcp-sanitizer).

🤖 Generated with Claude Code

… 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>
@Baldri
Baldri merged commit 53ffcdd into main Aug 22, 2026
6 checks passed
@Baldri
Baldri deleted the claude/session/fix/mingly-readfile-mcp-v2 branch August 22, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant