fix: symlink sandbox bypass in isWithinPath (security) — v0.12.10#74
Merged
Conversation
The Pi extension's tool-call sandbox used lexical path comparison (resolve()) without resolving symlinks. A sub-agent could create a symlink inside .codecarto/ pointing to a file outside the allowed root (e.g. ~/.ssh/id_rsa) and write through it -- the isWithinPath guard would pass because it only checked the lexical path, not the resolved target. Fix: added isWithinPathResolved which uses realpath before comparison. Updated the Pi tool_call hook to use isWithinPathResolved instead of isWithinPath. The MCP server was not affected (it does not use isWithinPath). Regression tests: - Documents the vulnerability (lexical check returns true for symlink) - Verifies the fix (resolved check returns false for symlink) - Verifies legitimate paths still pass - Verifies the root itself passes Discovered during the v0.12.9 self-analysis case study, independently confirmed via reproduction, and fixed with regression coverage. 268/268 tests pass (264 original + 4 new).
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.
Security fix
The Pi extension's tool-call sandbox used lexical path comparison () without resolving symlinks. A sub-agent could create a symlink inside pointing to a file outside the allowed root and write through it — the guard would pass because it only checked the lexical path.
Fix
Discovery
Found during the v0.12.9 self-analysis case study. The semantic defect scan (Pass 4: Security & Trust) identified it. Independent reproduction confirmed: a symlink inside an allowed directory pointing outside passes the lexical check but fails the resolved check.
Validation