Repository navigation
Fix arbitrary file write via dangling symlink escaping workspace root - #2565
Closed
prasanna8585 wants to merge 1 commit into
Closed
prasanna8585 wants to merge 1 commit into
prasanna8585 wants to merge 1 commit into
Conversation
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.
Collaborator
|
This appears to be a duplicate of https://github.com/ChromeDevTools/chrome-devtools-mcp/pull/2457/changes |
zjdCander
pushed a commit
to zjdCander/chrome-devtools-mcp
that referenced
this pull request
Aug 19, 2026
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
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'scaptureHeapSnapshot, which uses plainfs.createWriteStreamwith noO_NOFOLLOW) andstartScreencast(spawnsffmpeg, 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 likesnapshot.heapsnapshot -> ~/.ssh/authorized_keysand 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_NOFOLLOWto the internal#writeFilehelper) - heap snapshots and screencasts don't go through that helper, since their actual file I/O is delegated to Puppeteer-core/ffmpeg.Fix
resolveCanonicalPathnow 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
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.tests/roots.test.tsconfirmingvalidatePath/ensureExtensionreject a dangling symlink pointing outside the root, and that the outside target is never created.roots.test.tssuite, were run and passed locally with a real Chrome install.