Skip to content

fix: accept workspace roots that already end with a path separator - #2809

Closed
wyf0931 wants to merge 1 commit into
ChromeDevTools:mainfrom
wyf0931:fix/workspace-root-separator
Closed

wyf0931 wants to merge 1 commit into
ChromeDevTools:mainfrom
wyf0931:fix/workspace-root-separator

Conversation

@wyf0931

@wyf0931 wyf0931 commented Sep 23, 2026 •

Copy link
Copy Markdown

Summary

Fixes #2808.

--workspace=/ is the replacement the --allow-unrestricted-paths deprecation notice points to, but it currently denies every path.

McpContext.validatePath() built its allowed prefix as canonicalRoot + path.sep. For the filesystem root that doubles the separator — / becomes // on POSIX and C:\ becomes C:\\ on Windows — so no path below the root ever matched, and every file-writing tool failed with Access denied: ... is not within any of the configured workspace roots.

Change

  • src/McpContext.ts: append the separator only when the canonical root does not already end with one.
  • tests/roots.test.ts: regression test that uses the filesystem root as the workspace root.

The check keeps its existing semantics for narrower roots, and equality with the root itself still matches.

Verification

  • The new test fails on main with Access denied and passes with the change.
  • npm run test tests/roots.test.ts — all tests pass.
  • Verified against a real server process: --workspace=/ now saves a screenshot outside the temp directory, while --workspace=/tmp still rejects the same path, so the guardrail is unchanged for non-root roots.
  • npm run check-format — clean.
  • Full npm run test reports only the failures that already exist on main and are unrelated to this change (cli args parsing config expectations, and the "Page is too large" screenshot case). I ran the suite with and without this change and the results are identical.

@google-cla

google-cla Bot commented Sep 23, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@wyf0931
wyf0931 force-pushed the fix/workspace-root-separator branch from 2ee2e1f to ef1b103 Compare September 23, 2026 06:57
@OrKoN
OrKoN enabled auto-merge September 23, 2026 07:03
@OrKoN
OrKoN disabled auto-merge September 23, 2026 07:21

@OrKoN OrKoN 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.

it looks like there are failures on Windows.

@0xdhx

0xdhx commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

The Windows failures look like they come from the new test rather than the fix. On the Windows runners the checkout is under D:\a\chrome-devtools-mcp\…, so path.parse(process.cwd()).root is D:\, while os.homedir() is C:\Users\runneradmin. The path under test is then on a different drive from the root, and the check correctly denies it:

Error: Access denied: path C:\Users\runneradmin\a_very_unlikely_path_name_filesystem_root (canonical: C:\Users\runneradmin\a_very_unlikely_path_name_filesystem_root) is not within any of the configured workspace roots.

Taking the root from the path under test keeps both on the same drive:

const outsidePath = path.resolve(
  os.homedir(),
  'a_very_unlikely_path_name_filesystem_root',
);
const filesystemRoot = path.parse(outsidePath).root;

I checked the containment logic on a Windows machine (Node 25): with the root C:\ derived this way, the check with this PR's change allows the path and the check without it denies it, so the test still catches the regression. With a D:\ root it denies the path, which matches the CI failure.

The macOS / Node 24 failure is McpContext.test.js failing at the file level after about 82 s with no individual test failing, and the other two macOS legs pass, so it looks unrelated.

`validatePath()` matched a path against a canonical root by testing
`canonicalPath.startsWith(canonicalRoot + path.sep)`. When the root is the
filesystem root, appending the separator turns `/` into `//` (`C:\` into
`C:\\` on Windows), so no path below the root ever matched and every
file-writing tool was denied.

This affected `--workspace=/`, which the `--allow-unrestricted-paths`
deprecation notice recommends as its replacement.

Only append the separator when the root does not already end with one.
@OrKoN
OrKoN force-pushed the fix/workspace-root-separator branch from ef1b103 to 20de10f Compare September 28, 2026 06:15
@OrKoN

OrKoN commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

@OrKoN, friendly reminder: this PR has new commits since your last review and has been waiting for 16 day(s) (automated reminder)

@OrKoN OrKoN 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.

please check the test failures

@OrKoN

OrKoN commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Closing as stale

@OrKoN OrKoN closed this Oct 20, 2026
zjdCander pushed a commit to zjdCander/chrome-devtools-mcp that referenced this pull request Oct 22, 2026
…ls#3277)

Fixes ChromeDevTools#2808

`validatePath()` builds the allowed prefix as `canonicalRoot +
path.sep`. A filesystem root (`/`, or `C:\` on Windows) already ends
with the separator, so the prefix becomes `//` (or `C:\\`) and no path
below it matches. This makes `--workspace=/`, which the
`--allowUnrestrictedPaths` deprecation notice recommends, reject every
file write with `Access denied`.

The fix appends the separator only when the root doesn't already end
with one. Narrower roots behave as before.

The new test in `tests/roots.test.ts` sets the workspace root to the
filesystem root of the path under test, so it is on the same drive on
Windows (that drive mismatch is why the CI failed on the earlier, stale
attempt in ChromeDevTools#2809). It fails on `main` with `Access denied` and passes
with the fix. `tests/roots.test.ts` passes locally.

---
AI-assistance note: I prepared this change with help from an AI coding
assistant, then reviewed it and ran the tests myself.
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.

Workspace root of / denies every path because the separator is appended twice

3 participants