Skip to content

fix: allow a drive/filesystem root as the project root#338

Open
JavierusTk wants to merge 1 commit into
colbymchenry:mainfrom
JavierusTk:fix/drive-root-path-validation
Open

fix: allow a drive/filesystem root as the project root#338
JavierusTk wants to merge 1 commit into
colbymchenry:mainfrom
JavierusTk:fix/drive-root-path-validation

Conversation

@JavierusTk
Copy link
Copy Markdown

Problem

codegraph init W:\ (or any drive root) fails immediately — every file
is 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

validatePathWithinRoot and isPathWithinRoot (src/utils.ts) build the
containment prefix as normalizedRoot + path.sep. A drive root (W:\,
C:\) or POSIX root (/) already ends with a separator, so the prefix
becomes W:\\ / //, which no real path starts with. Every file under a
drive-root project is therefore rejected as a path-traversal escape. In
the batch reader (src/extraction/index.ts) that surfaces as a
read_error ("files could not be read").

Fix

Add a rootPrefix() helper that appends a separator only when one is
missing, and route all three containment checks through it
(validatePathWithinRoot, isPathWithinRoot, and the realpath branch of
isPathWithinRootReal). Behavior is byte-identical for non-drive-root
paths.

Tests

New containment-check suite in __tests__/security.test.ts covering
drive/filesystem roots (win32- and POSIX-gated), normal nested roots,
traversal escapes, and sibling-prefix paths (cg-root vs cg-root-evil).

🤖 Generated with Claude Code

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)
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