VYPR
Critical severity9.8GHSA Advisory· Published Jun 15, 2026· Updated Jun 15, 2026

Vitest Browser: Exposed Browser Mode API Can Proxy CDP and Overwrite Config Files, Leading to RCE

CVE-2026-53633

Description

Summary

Vitest Browser Mode exposes a cdp() API that forwards raw Chrome DevTools Protocol (CDP) methods over the Vitest browser WebSocket RPC. CDP is not gated by browser.api.allowWrite, browser.api.allowExec, api.allowWrite, or api.allowExec.

As a result, disabling Browser Mode write and exec operations does not prevent a browser API client from using CDP to perform equivalent actions. In a verified reproduction with allowWrite: false and allowExec: false, CDP Page.setDownloadBehavior set the browser download directory to the project root, and CDP Runtime.evaluate downloaded a controlled vite.config.ts. Vitest reloaded the changed config and executed attacker-controlled Node.js code.

When the Browser Mode API is also exposed to the network, this becomes remotely exploitable because the generated browser runner page exposes the API token, active session id, project name, and project root path needed to connect to the browser WebSocket API and select the target download directory.

Impact

This affects Browser Mode projects using a CDP-capable provider, such as Playwright Chromium, when the browser API server is exposed to the network, for example with --browser.api.host=0.0.0.0.

In this mode Vitest warns that write and exec operations are disabled by default, but the generated browser runner page exposes enough metadata for a remote client to authenticate to the browser WebSocket API while an active session exists. This includes the browser API token, active session id, project name, and serialized test config including the project root path. The attacker can then call Vitest's CDP RPC and use Chrome's download controls to overwrite vite.config.ts in the project root. When Vitest reloads the changed config, attacker-controlled Node.js code executes on the host running Vitest.

The same exposed CDP bridge also allows direct browser-session JavaScript execution through Runtime.evaluate. A separate local probe showed that CDP can navigate the browser to a file:// URL and read rendered file contents, but the primary verified impact is config-file overwrite leading to RCE.

Reproduction

For a concrete reproduction, start Browser Mode in watch mode using the official Lit example:

pnpm dlx tiged vitest-dev/vitest/examples/lit vitest-poc
cd vitest-poc
pnpm install

Configure the Browser Mode API to listen on all interfaces while explicitly disabling write and exec operations:

import { playwright } from '@vitest/browser-playwright'
import { defineConfig } from 'vite'

export default defineConfig({
  test: {
    browser: {
      enabled: true,
      provider: playwright(),
      instances: [
        { browser: 'chromium' },
      ],
      api: {
        host: '0.0.0.0',
        allowWrite: false,
        allowExec: false,
      },
    },
  },
})

Then start the test server:

pnpm test

Vitest serves the browser runner HTML and WebSocket API at http://localhost:63315.

While the browser session is active:

  1. Fetch the generated browser runner page:
   http://localhost:63315/__vitest_test__/
   
  1. Extract the embedded browser API token, active session id, project name, and project root:
  • window.VITEST_API_TOKEN
  • __vitest_browser_runner__.sessionId
  • __vitest_browser_runner__.config.name
  • __vitest_browser_runner__.config.root
  1. Connect to the browser API WebSocket as a tester client:
   /__vitest_browser_api__?type=tester&rpcId=&sessionId=&projectName=&method=none&token=
   
  1. Call the sendCdpEvent RPC method with:
   Page.setDownloadBehavior({
     behavior: "allow",
     downloadPath: __vitest_browser_runner__.config.root
   })
   
  1. Call sendCdpEvent again with Runtime.evaluate. The evaluated JavaScript creates a Blob containing a malicious Vite config and clicks an anchor element ``.
  1. Observed result:
  • vite.config.ts is overwritten with attacker-controlled content.
  • Vitest reloads the changed config.
  • The injected Node.js payload runs on the host.

AI Insight

LLM-synthesized narrative grounded in this CVE's description and references.

Affected products

3

Patches

Vulnerability mechanics

Root cause

"Missing authorization checks on CDP RPC methods allowed arbitrary Chrome DevTools Protocol commands even when `allowWrite` and `allowExec` were disabled."

Attack vector

An attacker who can reach the Vitest Browser Mode API server (e.g., when `--browser.api.host=0.0.0.0` is set) fetches the generated browser runner page to extract the embedded API token, session id, project name, and project root. Using these credentials, the attacker connects to the browser WebSocket API and calls `sendCdpEvent` with `Page.setDownloadBehavior` to set the download directory to the project root, then `Runtime.evaluate` to download a malicious `vite.config.ts`. Vitest reloads the changed config, executing attacker-controlled Node.js code on the host.

Affected code

The vulnerability resides in the Browser Mode RPC handler (`packages/browser/src/node/rpc.ts`) where the `sendCdpEvent` and `trackCdpEvent` methods forwarded raw Chrome DevTools Protocol (CDP) calls without checking the `allowWrite` or `allowExec` flags. The generated browser runner page (`__vitest_test__/`) also leaked the API token, session id, project name, and project root, enabling remote attackers to authenticate and issue CDP commands.

What the fix does

The patch introduces `isCdpAllowed()` and `assertCdpAllowed()` functions in `packages/browser/src/node/rpc.ts` that check all four `allowExec` and `allowWrite` flags (both `project.config` and `project.vitest.config` levels) before allowing `sendCdpEvent` or `trackCdpEvent` to proceed. Additionally, the internal V8 coverage module is refactored to use a server-side command (`__vitest_startV8Coverage` / `__vitest_takeV8Coverage`) instead of calling `cdp()` directly from the browser, ensuring coverage collection still works when CDP is blocked. Documentation is updated to warn that CDP is a privileged API gated by these flags.

Preconditions

  • networkBrowser Mode API server must be exposed to the network (e.g., `browser.api.host: '0.0.0.0'`)
  • authAn active browser session must exist so the runner page leaks the API token and session id
  • configThe project must use a CDP-capable provider (e.g., Playwright Chromium)
  • networkAttacker must be able to reach the Vitest WebSocket API and the browser runner page

Generated on Jun 15, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

2

News mentions

0

No linked articles in our index yet.