fix: allow a drive/filesystem root as the project root#338
Open
JavierusTk wants to merge 1 commit into
Open
Conversation
validatePathWithinRoot and isPathWithinRoot built the containment
prefix with `normalizedRoot + path.sep`. A drive root ("W:\", "C:\")
or POSIX root ("/") already ends with a separator, so the prefix
became "W:\\" / "//" — which no real path starts with. Every file
under a drive-root project was rejected as a traversal escape, so
`codegraph init W:\` failed with "all N files could not be read".
Add a rootPrefix() helper that appends a separator only when one is
missing, and route all three containment checks through it
(validatePathWithinRoot, isPathWithinRoot, isPathWithinRootReal).
Behavior is byte-identical for non-drive-root paths.
Add containment-check tests covering drive/filesystem roots, normal
nested roots, traversal escapes, and sibling-prefix paths.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.
Problem
codegraph init W:\(or any drive root) fails immediately — every fileis reported as "could not be read". With a large tree the CLI ends with
e.g.
Indexing failed - all 34,498 files had errors.Cause
validatePathWithinRootandisPathWithinRoot(src/utils.ts) build thecontainment prefix as
normalizedRoot + path.sep. A drive root (W:\,C:\) or POSIX root (/) already ends with a separator, so the prefixbecomes
W:\\///, which no real path starts with. Every file under adrive-root project is therefore rejected as a path-traversal escape. In
the batch reader (
src/extraction/index.ts) that surfaces as aread_error("files could not be read").Fix
Add a
rootPrefix()helper that appends a separator only when one ismissing, and route all three containment checks through it
(
validatePathWithinRoot,isPathWithinRoot, and the realpath branch ofisPathWithinRootReal). Behavior is byte-identical for non-drive-rootpaths.
Tests
New containment-check suite in
__tests__/security.test.tscoveringdrive/filesystem roots (win32- and POSIX-gated), normal nested roots,
traversal escapes, and sibling-prefix paths (
cg-rootvscg-root-evil).🤖 Generated with Claude Code