fix(vfs): reject Windows absolute paths cross-platform#1401
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR hardens path validation in the VFS localfileio package by adding early detection of absolute paths. A new ChangesAbsolute Path Validation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/vfs/localfileio/path_test.go`:
- Around line 37-40: The test currently adds Windows-absolute cases only for
SafeOutputPath; add the same four cases for SafeInputPath as well to cover the
shared safePath behavior. Update the table of test cases in path_test.go so that
for each of the entries {"absolute path windows drive",
`C:\Users\agent\secret.txt`, true}, {"absolute path windows drive slash",
"C:/Users/agent/secret.txt", true}, {"absolute path windows rooted",
`\Users\agent\secret.txt`, true}, {"absolute path windows unc",
`\\server\share\secret.txt`, true} you create equivalent assertions invoking
SafeInputPath (in addition to the existing SafeOutputPath checks) so both
SafeInputPath and SafeOutputPath are validated against the regression in
safePath.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 967361ce-4458-4ecc-8b5d-463a74bb044a
📒 Files selected for processing (2)
internal/vfs/localfileio/path.gointernal/vfs/localfileio/path_test.go
a5118dd to
b891900
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1401 +/- ##
=======================================
Coverage 72.75% 72.75%
=======================================
Files 730 730
Lines 69034 69044 +10
=======================================
+ Hits 50228 50236 +8
- Misses 15034 15035 +1
- Partials 3772 3773 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Background
Path safety validation is intended to reject absolute paths for user-provided input/output paths. The current check only used
filepath.IsAbs, which is platform-specific. On Unix/macOS it does not treat Windows-style absolute paths such asC:\Users\agent\secret.txt,C:/Users/agent/secret.txt,\Users\agent\secret.txt, or\\server\share\secret.txtas absolute, so those values could pass the initial absolute-path rejection and be interpreted as relative paths.Changes
internal/vfs/localfileio.safePath.SafeOutputPathandSafeInputPath.Verification
go test -timeout=2m ./internal/vfs/localfileio -run '^TestSafeOutputPath_RejectsPathTraversalAndDangerousInput$'failed for Windows absolute path cases.go test -count=1 -timeout=2m ./internal/vfs/localfileio -run '^TestSafeOutputPath_RejectsPathTraversalAndDangerousInput$': passedgo test -count=1 -timeout=2m ./internal/vfs/localfileio -run 'TestSafe(Output|Upload)Path_Rejects': passedgo test -count=1 -timeout=3m ./internal/vfs/localfileio: passedgo test -count=1 -timeout=4m ./internal/vfs/... ./internal/validate: passedgo test -count=1 -timeout=2m ./shortcuts/im -run '^TestValidateMediaFlagPath$': passedgofmt -l internal/vfs/localfileio/path.go internal/vfs/localfileio/path_test.go: no outputgit diff --check origin/main...HEAD: passedRisk and rollback
Risk is low and constrained to path validation. The behavior becomes stricter for Windows-style absolute paths on all platforms, matching existing CLI path-safety messaging. Rollback is reverting this PR.
Summary by CodeRabbit