Executive brief
Vitest's browser testing mode is a development tool that runs tests in a real browser environment via a local web server. The server fails to sanitize the `otelCarrier` query parameter before embedding it in an inline JavaScript block, allowing an attacker to inject arbitrary code that executes in the browser with access to authentication tokens and configuration files. An attacker who can trick a developer into clicking a malicious link while Vitest is running can compromise the local test environment and potentially execute code on the developer's machine.
Technical details
The vulnerability is a reflected cross-site scripting (XSS) flaw in Vitest's browser mode orchestrator. The `otelCarrier` query parameter is extracted from the request URL (in serverOrchestrator.ts line 48) and directly interpolated into an inline module script block (esm-client-injector.js line 41) without sanitization or escaping. Because the parameter is embedded as JavaScript source code rather than a data value, an attacker can craft a URL with arbitrary JavaScript payload in the `otelCarrier` parameter. When a victim visits the crafted URL in their browser while the Vitest server is running, the injected code executes in the server's origin. The proof-of-concept demonstrates both simple XSS (triggering an alert) and chained RCE: the injected script can steal `VITEST_API_TOKEN` (embedded on the same page), use it to authenticate to the WebSocket API, call `triggerCommand("writeFile")` to modify `vite.config.ts`, and trigger a config reload that executes arbitrary Node.js code. User interaction is required (clicking a malicious link), but attack surface is broad in local development scenarios. Patches are available in @vitest/browser versions 4.1.6 and 5.0.0-beta.3.
Affected products
- Vitest @vitest/browser >=4.0.17, <4.1.6; >=5.0.0-beta.0, <5.0.0-beta.3
Timeline
- 2026-05-19: disclosed: Vulnerability disclosed on GitHub
- 2026-06-01: advisory: GHSA-2h32-95rg-cppp published on GitHub Advisory Database
- 2026-05-19: patched: Patches released: @vitest/browser 4.1.6 and 5.0.0-beta.3
References
- https://github.com/vitest-dev/vitest/security/advisories/GHSA-2h32-95rg-cppp
- https://github.com/vitest-dev/vitest
- https://github.com/vitest-dev/vitest/blob/cba2036a197ec8ed42c35a37db78ef07192202c7/packages/browser/src/client/public/esm-client-injector.js
- https://github.com/vitest-dev/vitest/blob/cba2036a197ec8ed42c35a37db78ef07192202c7/packages/browser/src/node/serverOrchestrator.ts