fix(security): add symlink resolution to meta-commands validateOutputPath#838
Open
Ziadstr wants to merge 1 commit intogarrytan:mainfrom
Open
fix(security): add symlink resolution to meta-commands validateOutputPath#838Ziadstr wants to merge 1 commit intogarrytan:mainfrom
Ziadstr wants to merge 1 commit intogarrytan:mainfrom
Conversation
…Path meta-commands.ts validateOutputPath only performed lexical path.resolve checking, while write-commands.ts had a full symlink resolution step added in the security audit round 2. A symlink inside /tmp pointing to /etc would pass the meta-commands validation but be blocked by write-commands. This brings meta-commands.ts validateOutputPath to parity with write-commands.ts: resolve the real path of the nearest existing ancestor directory and re-validate against safe directories. Adds a regression test for symlink bypass in validateOutputPath. Fixes garrytan#707
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
meta-commands.ts:validateOutputPathonly performed lexicalpath.resolvechecking, whilewrite-commands.ts:validateOutputPathhad a full symlink resolution step added in PR #640 (security audit round 2). A symlink inside/tmppointing outside the safe zone would passmeta-commandsvalidation but be blocked bywrite-commands.This brings
meta-commands.ts:validateOutputPathto parity withwrite-commands.ts:validateOutputPath.The vulnerability
Commands using
meta-commands.validateOutputPath(screenshot, pdf, responsive) would allow writing to paths outside the safe zone via symlinks.Fix
Added symlink resolution (identical to the existing
write-commands.tsimplementation):fs.realpathSyncTesting
Added regression test: creates a symlink inside
/tmppointing to/etc, verifiesvalidateOutputPathblocksjoin(linkPath, 'passwd').Follows the exact same test pattern as the existing
validateReadPathsymlink test (line 67-75 ofpath-validation.test.ts).Fixes #707