Repository navigation
vfs: prevent RealFSProvider sandbox escape via symlinks - #67971
Open
pipobscure wants to merge 1 commit into
Open
pipobscure wants to merge 1 commit into
pipobscure wants to merge 1 commit into
Conversation
The containment check in RealFSProvider#resolvePath was thrown inside the try block wrapping fs.realpathSync(). Because the rejection carried an ENOENT code, the `if (err?.code !== 'ENOENT') throw err` catch mistook it for "path does not exist yet" and returned the raw, symlink-containing path, which the caller then opened — following the symlink out of the root. #verifyAncestorInRoot had the same self-swallowing flaw, making it a no-op. As a result readFile/stat/open/write on a symlink pointing outside the root read and wrote real files outside the sandbox. Move the containment checks outside the try/catch so a rejection can no longer be swallowed by the ENOENT handler, and compare against a canonicalized root (#realRoot) so the checks are sound even when the root path itself contains symlinked components (e.g. /tmp -> /private/tmp). Add regression tests covering read/stat/open/write and new-file creation through symlinks that resolve outside the provider root. Signed-off-by: Vinz Spring <vjvsp@yahoo.de>
pipobscure
requested review from
mcollina and
trivikr
and removed request for
trivikr
December 2, 2026 15:24
Collaborator
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #67971 +/- ##
==========================================
- Coverage 90.56% 90.56% -0.01%
==========================================
Files 802 802
Lines 286851 286878 +27
Branches 55396 55398 +2
==========================================
+ Hits 259788 259804 +16
- Misses 17147 17161 +14
+ Partials 9916 9913 -3
🚀 New features to boost your workflow:
|
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.
Taking over #64409 since it seems it's abandoned by the original author and is something we do want to fix.