fix(browser): disable client cdp API when allowWrite/allowExec: false#10444
Conversation
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
| send: cdp.send.bind(cdp), | ||
| on: cdp.on.bind(cdp), | ||
| off: cdp.off.bind(cdp), | ||
| once: cdp.once.bind(cdp), |
There was a problem hiding this comment.
We had weird ambient type from packages/coverage-v8/src/browser.ts and affected this part somehow. Did a quick ugly fix.
| import type { BrowserCommand } from 'vitest/node' | ||
| import type { BrowserServerCDPHandler } from '../cdp' | ||
|
|
||
| export const _startV8Coverage: BrowserCommand<[]> = async (context) => { | ||
| const session: BrowserServerCDPHandler = await context.__ensureCDPHandler() | ||
| await session.send('Profiler.enable') | ||
| await session.send('Profiler.startPreciseCoverage', { | ||
| callCount: true, | ||
| detailed: true, | ||
| }) | ||
| } | ||
|
|
||
| export const _takeV8Coverage: BrowserCommand<[]> = async (context) => { | ||
| const session: BrowserServerCDPHandler = await context.__ensureCDPHandler() | ||
| return session.send('Profiler.takePreciseCoverage') | ||
| } |
There was a problem hiding this comment.
This now restricts exposure to only these cdp commands. This would still expose runtime test code information, but it's just as bad as what readFile command or Vite's already exposes based on server.fs, so it should be fine.
Co-authored-by: Codex <noreply@openai.com>
@vitest/browser
@vitest/browser-playwright
@vitest/browser-preview
@vitest/browser-webdriverio
@vitest/coverage-istanbul
@vitest/coverage-v8
@vitest/expect
@vitest/mocker
@vitest/pretty-format
@vitest/runner
@vitest/snapshot
@vitest/spy
@vitest/ui
@vitest/utils
vitest
@vitest/web-worker
commit: |
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
Pull request overview
This PR hardens browser-mode CDP access by blocking the public client cdp() API when write or exec permissions are disabled, while keeping internal V8 browser coverage functional through server-side commands.
Changes:
- Adds CDP permission checks to browser RPC handlers.
- Moves V8 browser coverage CDP calls behind internal browser commands.
- Updates tests and documentation for the new CDP permission behavior.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
packages/browser/src/node/rpc.ts |
Adds CDP permission gating and exposes an internal cached CDP handler to server commands. |
packages/browser/src/node/commands/coverage.ts |
Adds internal commands for starting and taking V8 coverage via CDP. |
packages/browser/src/node/commands/index.ts |
Registers the new internal V8 coverage commands. |
packages/coverage-v8/src/browser.ts |
Uses internal commands instead of the public browser cdp() API. |
packages/vitest/src/node/types/browser.ts |
Documents the internal cached CDP handler on browser command context. |
packages/browser-playwright/src/playwright.ts |
Simplifies Playwright CDP session method forwarding. |
test/browser/specs/errors.test.ts |
Adds coverage for public cdp() failure when browser API permissions are disabled. |
test/coverage-test/test/browser-api-permissions.browser.test.ts |
Verifies browser V8 coverage still works with API write/exec disabled. |
docs/config/browser/api.md |
Documents that browser API permissions gate privileged CDP access. |
docs/api/browser/context.md |
Adds CDP permission warning to browser context docs. |
docs/api/browser/commands.md |
Adds CDP permission warning to browser commands docs. |
| import type { BrowserServerCDPHandler } from '../cdp' | ||
|
|
||
| export const _startV8Coverage: BrowserCommand<[]> = async (context) => { | ||
| const session: BrowserServerCDPHandler = await context.__ensureCDPHandler() |
There was a problem hiding this comment.
I think this could even be a public API to be honest (in v5). Not blocking though
Description
cdpAPI whenallowWrite/allowExec: false[backport to v4] #10450cdpAPI whenallowWrite/allowExec: false[backport to v3] #10456Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.