Skip to content

vfs: prevent RealFSProvider sandbox escape via symlinks - #67971

Open
pipobscure wants to merge 1 commit into
nodejs:mainfrom
pipobscure:vfs-symlink-sandbox-escape-fix
Open

pipobscure wants to merge 1 commit into
nodejs:mainfrom
pipobscure:vfs-symlink-sandbox-escape-fix

Conversation

@pipobscure

Copy link
Copy Markdown
Contributor

Taking over #64409 since it seems it's abandoned by the original author and is something we do want to fix.

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>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. vfs Issues and PRs related to the virtual filesystem subsystem. labels Dec 2, 2026
@pipobscure
pipobscure requested review from mcollina and trivikr and removed request for trivikr December 2, 2026 15:24

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm.

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Dec 2, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Dec 2, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.65517% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.56%. Comparing base (1fd6016) to head (23850c0).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/vfs/providers/real.js 89.65% 6 Missing ⚠️
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     
Files with missing lines Coverage Δ
lib/internal/vfs/providers/real.js 95.48% <89.65%> (-0.28%) ⬇️

... and 23 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. vfs Issues and PRs related to the virtual filesystem subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants