Skip to content

fix: accept POSIX root URIs from WSL2 clients on a Windows server - #3380

Open
jaeminbird wants to merge 4 commits into
ChromeDevTools:mainfrom
jaeminbird:fix-wsl-posix-roots
Open

jaeminbird wants to merge 4 commits into
ChromeDevTools:mainfrom
jaeminbird:fix-wsl-posix-roots

Conversation

@jaeminbird

@jaeminbird jaeminbird commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

A WSL2 client that launches the server on the Windows side advertises roots like file:///home/user/project. On Windows fileURLToPath throws File URL path must be absolute, the root is dropped, and every path inside it is denied (#2839).

New fileUrlToPathWithPosixFallback() in src/utils/files.ts reads a file URL with no host and no drive letter as POSIX; path.resolve then maps it onto the server's \\wsl.localhost\<distro> cwd, the same canonical form validatePath gives the file. Drive-letter and UNC URLs are unchanged.

User-visible changes on Windows:

  • Roots without a drive letter are accepted instead of dropped. If the server's cwd is a normal drive rather than UNC, file:///home/user resolves to <current drive>:\home\user.
  • file: tool arguments without a drive letter (ToolHandler.validateAndResolvePathOrUrl) are read as POSIX paths instead of rejected.

Validation (Windows 11, Node 24.18):

  • New roots and ToolHandler tests fail on main, pass here. npm run test passes except a symlink test (no privilege here); Linux (docker): new tests pass.
  • Manual WSL2 repro from the issue: client in WSL runs node.exe, take_screenshot to /home/clab/cdm-wsl-test/shot.png. main denies it, this branch writes the file.

Fixes #2839. Picks up #2840, closed for a missing CLA.

@samiyac

samiyac commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

@Lightning00Blade can you PTAL since you previously reviewed #2840 ? Thanks!

Comment thread src/utils/files.ts Resolved

@Lightning00Blade Lightning00Blade left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  1. Manual check in WSL2. No automated test checks that path.resolve maps the POSIX root to \wsl.localhost<distro>... against a UNC working directory,
    because that only happens on a real Windows host started from WSL. Could you confirm you ran the repro from the issue? That means a WSL2 client launching
    Windows node.exe, then take_screenshot with filePath: "/home///shot.png", which should now succeed.
  2. PR description. Please list both user-visible changes:
    • file:// tool arguments without a drive letter (in ToolHandler.validateAndResolvePathOrUrl) are now read as POSIX paths on Windows. Before, they were
    rejected.
    • If the server's working directory is a normal drive rather than a UNC path, a POSIX root such as file:///home/user now resolves to :\home\user. Before, the root was dropped. This is rare, but worth stating.

@Lightning00Blade Lightning00Blade added the full-ci Run tests on Windows and macOS for this PR label Nov 9, 2026
@jaeminbird

Copy link
Copy Markdown
Contributor Author

@Lightning00Blade Ran the issue's repro on Windows 11 + WSL2 (Node 24.18, headless --isolated Chrome). A minimal MCP stdio client in WSL, run as a normal user from /home/clab/cdm-wsl-test, launches node.exe <build>\src\bin\chrome-devtools-mcp.js --headless --isolated (resolved via WSL interop to /mnt/c/Program Files/nodejs/node.exe), advertises root file:///home/clab/cdm-wsl-test, then calls take_screenshot with filePath: "/home/clab/cdm-wsl-test/shot.png".

main (81a0379):

[MCP Context] Could not resolve configured root "file:///home/clab/cdm-wsl-test": "File URL path must be absolute"
Error: Access denied: path "/home/clab/cdm-wsl-test/shot.png" (canonical: "\\wsl.localhost\Containerlab\home\clab\cdm-wsl-test\shot.png") is not within any of the configured workspace roots.
$ ls -l /home/clab/cdm-wsl-test/shot.png
ls: cannot access '/home/clab/cdm-wsl-test/shot.png': No such file or directory

This branch (a42fd23):

Saved screenshot to \\wsl.localhost\Containerlab\home\clab\cdm-wsl-test\shot.png.
$ ls -l /home/clab/cdm-wsl-test/shot.png
-rw-r--r-- 1 root root 64187 Nov  9 20:53 /home/clab/cdm-wsl-test/shot.png

Also checked the drive-cwd case: with cwd C:\, file:///home/user resolves to C:\home\user. The description now lists both user-visible changes.

A WSL2 client that starts the server on the Windows side advertises roots
like file:///home/user/project. fileURLToPath rejects those on Windows, so
the roots were dropped and every path inside them was denied. Read file URLs
with no host and no drive letter as POSIX paths; path.resolve then maps them
onto the server's \\wsl.localhost working directory.

Fixes ChromeDevTools#2839
@Lightning00Blade
Lightning00Blade added this pull request to the merge queue Nov 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run tests on Windows and macOS for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client roots from a WSL2 client are dropped by a Windows-side server (fileURLToPath ERR_INVALID_FILE_URL_PATH)

3 participants