Skip to content

Fix arbitrary file write via dangling symlink escaping workspace root - #2565

Closed
prasanna8585 wants to merge 1 commit into
ChromeDevTools:mainfrom
prasanna8585:fix/dangling-symlink-root-escape
Closed

prasanna8585 wants to merge 1 commit into
ChromeDevTools:mainfrom
prasanna8585:fix/dangling-symlink-root-escape

Conversation

@prasanna8585

Copy link
Copy Markdown

Summary

resolveCanonicalPath() treated a dangling symlink (target does not exist) the same as a plain non-existent path - it fell back to the nearest existing ancestor + the symlink's own basename, instead of resolving to where the symlink actually points.

Impact

A dangling symlink placed inside an allowed workspace root, pointing outside of it, was treated by validatePath()/ensureExtension() as safely inside the root. takeHeapSnapshot (Puppeteer's captureHeapSnapshot, which uses plain fs.createWriteStream with no O_NOFOLLOW) and startScreencast (spawns ffmpeg, which also follows symlinks by default) would then write their output through the symlink to the attacker-chosen location outside the sandboxed root - e.g. a malicious/untrusted repository checked out for automated browser testing could contain a symlink like snapshot.heapsnapshot -> ~/.ssh/authorized_keys and have a routine heap-snapshot tool call overwrite it.

This is the same bug class already fixed for the screenshot path in #2269 (which added O_NOFOLLOW to the internal #writeFile helper) - heap snapshots and screencasts don't go through that helper, since their actual file I/O is delegated to Puppeteer-core/ffmpeg.

Fix

resolveCanonicalPath now detects when the unresolvable path (or an ancestor of it) is itself a symlink, and recursively resolves to its actual target (handling chained symlinks), with cycle detection to prevent infinite recursion on a symlink loop.

Testing

  • Added unit tests in tests/utils/files.test.ts: dangling symlink resolves to its real outside target, chained dangling symlinks resolve to the ultimate target, symlink cycles throw instead of hanging.
  • Added an end-to-end test in tests/roots.test.ts confirming validatePath/ensureExtension reject a dangling symlink pointing outside the root, and that the outside target is never created.
  • All tests, including the Chrome-dependent roots.test.ts suite, were run and passed locally with a real Chrome install.
  • Confirmed via revert-and-retest that the new tests correctly fail against the unfixed code (not tautological).

resolveCanonicalPath() previously treated a dangling symlink (one whose
target does not exist) the same as a plain non-existent path: it fell
back to the nearest existing ancestor directory + the symlink's own
basename, rather than resolving to where the symlink actually points.

This meant a dangling symlink placed inside an allowed workspace root,
pointing outside of it (e.g. to ~/.ssh/authorized_keys), was treated
by validatePath()/ensureExtension() as if it were safely inside the
root. Tools whose actual file I/O is delegated to third-party code
that follows symlinks with no O_NOFOLLOW protection - takeHeapSnapshot
(via Puppeteer's captureHeapSnapshot, which uses plain
fs.createWriteStream) and startScreencast (via a spawned ffmpeg
process) - would then write their output through the symlink to the
attacker-chosen location outside the sandboxed root.

Fixes resolveCanonicalPath to detect when the unresolvable path (or an
ancestor of it) is itself a symlink, and recursively resolve to its
actual target (including chained symlinks), with cycle detection to
avoid infinite recursion on a symlink loop.

Adds regression tests for: a dangling symlink resolving to its real
(outside) target, a chained dangling symlink, symlink-cycle detection,
and an end-to-end test confirming validatePath/ensureExtension reject
such paths. All tests, including the Chrome-dependent end-to-end test,
were run and confirmed locally.
@OrKoN

OrKoN commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants