Skip to content

fix: check fs access in builtin commands - #1

Merged
sheremet-va merged 4 commits into
mainfrom
fix/command-write-gate
Jun 30, 2026
Merged

fix: check fs access in builtin commands#1
sheremet-va merged 4 commits into
mainfrom
fix/command-write-gate

Conversation

@hi-ogawa

Copy link
Copy Markdown
Contributor

The `takeScreenshot` (write) and `upload` (read) commands resolved
client-controlled paths without checking the `allowWrite` permission gate
or Vite's `server.fs` access rules. Add vendored
`assertBrowserApiWrite`/`assertBrowserFileAccess` helpers and apply them so
these commands respect the same protections as the built-in file commands.

Co-authored-by: OpenCode (claude-opus-4-8) <noreply@opencode.ai>
@hi-ogawa hi-ogawa changed the title fix(browser): check fs access in builtin commands fix: check fs access in builtin commands Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Dumped the copy of packages/browser/src/node/utils.ts from vitest-dev/vitest#10674

@hi-ogawa
hi-ogawa marked this pull request as ready for review June 30, 2026 08:44
@sheremet-va

Copy link
Copy Markdown
Member

I feel like we need a better commands API so we can just hook into something like commands.on('before:upload', () => assert

Comment thread src/commands/permissions.ts Outdated
}

export function assertBrowserApiWrite(project: TestProject, path: string): void {
if (!project.config.browser.api.allowWrite || !project.vitest.config.api.allowWrite) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My config PR removes config.browser.api - if we don't want to open a new PR here after vitest-dev/vitest#10554 is merged, we can at least do browser.api?.allowWrite

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point.

Suggested change
if (!project.config.browser.api.allowWrite || !project.vitest.config.api.allowWrite) {
// `browser.api` is gone since https://github.com/vitest-dev/vitest/pull/10554
if (!(project.config.browser.api && project.config.browser.api.allowWrite) || !project.vitest.config.api.allowWrite) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh wait, this is actually wrong !(project.config.browser.api && project.config.browser.api.allowWrite).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oh, right

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is correct now, no?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, wait, you should also check for project.config.api, not just project.vitest.config.api. Maybe we should merge the config PR first 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to this. So many configs lol

  const browserApiAllowWrite = project.config.browser.api
    ? project.config.browser.api.allowWrite
    : project.config.api.allowWrite
  if (!browserApiAllowWrite || !project.vitest.config.api.allowWrite) {

hi-ogawa and others added 2 commits June 30, 2026 18:37
`browser.api` is being unified into the main `api` config in
vitest-dev/vitest#10554. Fall back to `api.allowWrite` when
`browser.api` is absent so the gate works before and after that change.

Co-authored-by: OpenCode (claude-opus-4-8) <noreply@opencode.ai>
…/command-write-gate

# Conflicts:
#	src/commands/permissions.ts
@sheremet-va
sheremet-va merged commit 7d13c59 into main Jun 30, 2026
3 checks passed
@sheremet-va
sheremet-va deleted the fix/command-write-gate branch June 30, 2026 09:49
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