Skip to content

fix(browser): check fs access in builtin commands [backport to v4]#10680

Merged
sheremet-va merged 6 commits into
vitest-dev:v4from
hi-ogawa:fix/browser-command-write-gate-v4
Jul 1, 2026
Merged

fix(browser): check fs access in builtin commands [backport to v4]#10680
sheremet-va merged 6 commits into
vitest-dev:v4from
hi-ogawa:fix/browser-command-write-gate-v4

Conversation

@hi-ogawa

@hi-ogawa hi-ogawa commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Description

This is mostly same diff as original.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

hi-ogawa and others added 3 commits June 30, 2026 11:47
…cess [backport to v4]

Provider commands dispatched through `triggerCommand` (takeScreenshot,
stopChunkTrace, deleteTracing, screenshotMatcher writes, and file upload)
bypassed the `allowWrite` permission gate and Vite's `server.fs` path
validation. Add shared `assertBrowserApiWrite`/`assertBrowserFileAccess`
helpers, apply them to those commands, reuse them from the `fs` commands,
and cover the gates with browser tests.

Co-authored-by: OpenCode (claude-opus-4-8) <[email protected]>
These tests run against a single project, so keying the error tree by
project name made the snapshot provider-dependent (chromium vs chrome).
Use `errorTree()` without `project` for provider-agnostic snapshots.

Co-authored-by: OpenCode (claude-opus-4-8) <[email protected]>
…rt to v4]

`annotateTraces` recorded a client-supplied trace path as an attachment
without any gate, and `onTaskArtifactRecord` only stripped attachments when
`allowWrite` was false — neither confined the path. Since attachments are
copied into `attachmentsDir`, an arbitrary path (e.g. `/etc/passwd`) could
be disclosed. Gate `annotateTraces` like the other trace commands and add
`checkFileAccess` for attachment paths in `onTaskArtifactRecord`.

Co-authored-by: OpenCode (claude-opus-4-8) <[email protected]>
@hi-ogawa
hi-ogawa marked this pull request as ready for review June 30, 2026 08:41
sheremet-va
sheremet-va previously approved these changes Jun 30, 2026
@sheremet-va

Copy link
Copy Markdown
Member

playwright test on windows is failing, is this expected?

 FAIL  specs/errors.test.ts > cannot use fs commands if write is disabled
AssertionError: expected [] to have a length of 6 but got +0

- Expected
+ Received

- 6
+ 0

 ❯ specs/errors.test.ts:125:18
    123|
    124|   const errors = stderr.split('\n').filter(line => line.includes('Cann…
    125|   expect(errors).toHaveLength(2 * instances.length)
       |                  ^
    126|
    127|   expect(stderr).toContain(

hi-ogawa and others added 2 commits July 1, 2026 12:21
…port to v4]

`path.resolve(root, "/test-file.txt")` prepends the current drive and
uses backslashes on Windows, which changed the "Cannot modify file"
message and broke the cross-platform command-permission test. Restore
the upstream ordering so the raw client path is passed to the write
check while the resolved path is still used for the fs-access check.

Co-authored-by: OpenCode (claude-opus-4-8) <[email protected]>
@sheremet-va

Copy link
Copy Markdown
Member

I think rolldown failure is an actual bug, but not from your changes 🤔

@sheremet-va
sheremet-va merged commit 5c18dd2 into vitest-dev:v4 Jul 1, 2026
12 of 15 checks passed
@hi-ogawa
hi-ogawa deleted the fix/browser-command-write-gate-v4 branch July 1, 2026 07:03
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