fix(security): path validation bypass in upload and cookie-import commands#920
Open
Hybirdss wants to merge 1 commit intogarrytan:mainfrom
Open
fix(security): path validation bypass in upload and cookie-import commands#920Hybirdss wants to merge 1 commit intogarrytan:mainfrom
Hybirdss wants to merge 1 commit intogarrytan:mainfrom
Conversation
… with path-security module
upload and cookie-import commands used inline path validation (includes('..')
+ manual isAbsolute check) while newer commands (screenshot, download, scrape,
archive) already use the shared validateOutputPath/validateReadPath from
path-security.ts. The inline check is bypassable — path.normalize().includes('..')
misses several traversal vectors that validateReadPath catches via
path.resolve() + fs.realpathSync() + boundary check.
Changes:
- upload: replace 10-line inline validation with validateReadPath(fp)
- cookie-import: replace 8-line inline validation with validateReadPath(filePath)
- Import validateReadPath alongside existing validateOutputPath
- Remove now-unused SAFE_DIRECTORIES and isPathWithin references
Tests:
- upload: verify validateReadPath usage, verify inline checks removed
- cookie-import: new test — verify validateReadPath usage, verify inline checks removed
- 29 pass, 1 pre-existing fail (symlink test, unrelated)
Closes garrytan#707
5 tasks
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
uploadandcookie-importcommands use inline path validation (path.normalize().includes('..')+ manualisAbsolutecheck) while all newer commands already use the sharedvalidateReadPath/validateOutputPathfrompath-security.ts.The inline check is weaker —
path-security.tsdoespath.resolve()→fs.realpathSync()→ boundary check againstSAFE_DIRECTORIES, catching symlink traversal and normalized-path bypass vectors thatincludes('..')misses.Before (inline, bypassable):
After (shared module, 1 line each):
Same
validateReadPaththatevalcommand already uses — resolve, realpath, boundary check, symlink resolution. Single source of truth.What's fixed
upload: 10-line inline validation →validateReadPath(fp)cookie-import: 8-line inline validation →validateReadPath(filePath)SAFE_DIRECTORIESandisPathWithinimports from write-commands.tsContext
path-security.tswas introduced in #907 to consolidate path validation that was "duplicated across 3 files." This PR catches the 4th instance —uploadandcookie-importwere not migrated at that time.Test plan
upload command path validationtests — verifyvalidateReadPathusage, verify inline checks removedcookie-import command path validationtests — verifyvalidateReadPathusage, verify inline checks removedbun test browse/test/path-validation.test.ts— 29 pass, 1 pre-existing fail (symlink test, unrelated to this change)bun test— full suite passes (same 1 pre-existing failure only)Closes #707
Generated with Claude Code