fix: validate projectPath in MCP tool handler to prevent sensitive directory access#230
Merged
colbymchenry merged 2 commits intoMay 22, 2026
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a safety check to validate projectPath before locating/opening a CodeGraph project.
Changes:
- Import
validateProjectPathfrom../utils. - Validate
projectPathand throw on invalid paths before walking up directories to find.codegraph/.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
534
to
+542
| if (this.projectCache.has(projectPath)) { | ||
| return this.projectCache.get(projectPath)!; | ||
| } | ||
|
|
||
| // Validate the path is safe before opening | ||
| const pathError = validateProjectPath(projectPath); | ||
| if (pathError) { | ||
| throw new Error(pathError); | ||
| } |
e0c4871 to
54d17eb
Compare
colbymchenry
added a commit
to eddiekudo/codegraph
that referenced
this pull request
May 22, 2026
colbymchenry#230's validateProjectPath ran on the raw path incl. a statSync existence check, which rejected the nested/not-yet-created sub-paths that issue colbymchenry#238 expects to resolve UP to the default project. Guard with existsSync so a direct sensitive dir (e.g. /etc, C:\Windows) is still refused while sub-paths walk up. Adds MCP-handler rejection tests (POSIX + Windows-gated).
…nsitive directories
colbymchenry#230's validateProjectPath ran on the raw path incl. a statSync existence check, which rejected the nested/not-yet-created sub-paths that issue colbymchenry#238 expects to resolve UP to the default project. Guard with existsSync so a direct sensitive dir (e.g. /etc, C:\Windows) is still refused while sub-paths walk up. Adds MCP-handler rejection tests (POSIX + Windows-gated).
54d17eb to
1284357
Compare
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.
Summary
The
projectPathparameter accepted by all MCP tools passes throughgetCodeGraph()without callingvalidateProjectPath(), allowing cross-project queries to target sensitive system directories (/,/etc,~/.ssh,~/.aws,C:\Windows, etc.).This adds the existing
validateProjectPath()check insideToolHandler.getCodeGraph()before any filesystem traversal occurs.What changed
validateProjectPathfrom../utilsinsrc/mcp/tools.tsvalidateProjectPath(projectPath)after the cache check and beforefindNearestCodeGraphRoot()Why
validateProjectPath()already exists and blocks sensitive paths, but was not wired into the MCP tool handler's cross-project code path. A malicious or compromised MCP client could passprojectPathpointing to sensitive directories.Testing
--noEmit