Summary
Vitest Browser Mode exposed a Chrome DevTools Protocol API that forwarded powerful debug commands without enforcing the intended write and execute permissions.
A remote client with access to the browser API metadata could use these CDP methods to overwrite vite.config.ts and run attacker-controlled Node.js code during tests.
Affected context
This vulnerability appears in Vitest deployments using Browser Mode where the cdp() API is reachable by remote clients, such as interactive test dashboards or automation tools.
Risk increases when browser debugging endpoints or API metadata are exposed over the network, especially if they lack strict authentication or authorization.
In these contexts, CDP methods like Page.setDownloadBehavior and Runtime.evaluate can be invoked from outside the trusted test runner, turning a debugging surface into a code execution vector.
Exploit preconditions
- Attack surface: Vitest Browser Mode's
cdp()API and any exposed browser debugging endpoint. - Required access: Ability to connect to the Vitest browser API or obtain exposed CDP metadata; this may be possible in shared CI systems, remote developer environments, or misconfigured tunnels.
- Trigger point: Issuing Chrome DevTools Protocol commands (e.g.,
Page.setDownloadBehaviorandRuntime.evaluate) through the unguardedcdp()interface. - Why exploitation is possible: The
cdp()API forwarded raw CDP methods without enforcingallowWriteorallowExecgates, effectively granting write and execution capabilities to any client that could call the API.
Why this happens
The underlying bug is an authorization gap in a powerful debugging interface: an API intended for controlled browser inspection was exposed with overly permissive access.
By forwarding raw CDP methods without checking write or execution flags, Vitest created a situation where untrusted callers could perform state-changing and code-executing operations.
This maps to CWE-749: Exposed Dangerous Method or Function, because sensitive CDP capabilities were made accessible without proper restriction, and to CWE-862: Missing Authorization, as there was no effective permission check controlling who could invoke these methods.
Potential impact
- Remote execution of arbitrary Node.js code in the test runner process.
- Overwriting or corrupting project configuration files such as
vite.config.ts. - Modification of test behavior to hide failures or implant malicious logic.
- Lateral movement from a test environment into connected development or build systems.
- Potential supply-chain impact if compromised tests or configs are committed and propagated.
General mitigation guidance
Effective mitigation focuses on tightening access control around debugging and browser integration APIs and reducing their default capabilities.
Common defensive patterns include:
- Gating any write or execution-capable methods behind explicit authorization checks and feature flags.
- Restricting exposed CDP or debug endpoints to localhost-only or trusted networks and requiring authentication for remote access.
- Designing browser integration APIs with clear separation between read-only inspection operations and state-changing or execution operations.
- Running test infrastructure with least privilege and isolating it from critical project files wherever practical.
- Treating any remote-controllable debug or test interface as a potential execution channel and documenting its intended trust boundaries.
How teams detect issues like this
Organizations can surface similar issues by:
- Applying static analysis and architectural reviews to identify APIs that forward or proxy powerful lower-level protocols (like CDP) without authorization checks.
- Reviewing test and debug infrastructure for endpoints that expose file write or code execution capabilities, especially in browser automation or devtools integrations.
- Enforcing security policies that require authentication and authorization for remote debug or test APIs, and verifying these controls in CI pipelines.
- Using automated application security testing tools to scan for dangerous methods, such as dynamic evaluation, file writes, or configuration manipulation, behind externally reachable interfaces.

