Summary
Vitest Browser Mode inserted the otelCarrier query parameter directly into an inline module script, enabling crafted URLs to execute arbitrary JavaScript in the Vitest server origin.
Under these conditions, an attacker can run code in the browser context and recover VITEST_API_TOKEN, which enables authenticated API calls against the Vitest server.
Affected context
This vulnerability occurs in Vitest environments that:
- Use Browser Mode and expose the
/__vitest_test__/endpoint - Accept
otelCarrieror similar query parameters from user-controlled URLs - Render those parameters directly into inline
<script type="module">content
It primarily affects scenarios where developers or CI systems access Vitest via browser-based runners and the server origin is reachable by other parties on the network or in shared testing environments.
Exploit preconditions
- Attack surface: HTTP requests to the Vitest Browser Mode runner endpoint
/__vitest_test__/ - Required access: Ability to cause a victim to open or follow a crafted browser-runner URL (e.g., link, redirect, or injected URL in developer tooling)
- Trigger point: The Vitest server injects the
otelCarrierquery parameter directly into inline module script content without proper encoding or sanitization - Why exploitation is possible: Untrusted URL parameters are treated as JavaScript source and executed in the context of the Vitest server origin, allowing access to browser-exposed secrets like
VITEST_API_TOKEN
Why this happens
The underlying bug is an instance of reflected cross-site scripting (XSS) mapped to CWE-79: Improper Neutralization of Input During Web Page Generation.
Vitest Browser Mode takes a query parameter (otelCarrier), assumes it is benign diagnostic data, and embeds it directly into an inline module <script> without escaping or encoding.
Because the parameter is fully attacker-controlled and becomes part of executable JavaScript, a crafted value can break out of the expected structure and inject arbitrary script logic.
This insecure pattern is common when server-side template generation or dev tooling renders dynamic data into HTML or JavaScript without considering that URLs are part of the untrusted input surface.
Potential impact
- An attacker may execute arbitrary JavaScript in the browser context under the Vitest server origin.
- Attackers could recover
VITEST_API_TOKENand other accessible tokens or secrets stored in the browser or exposed via scripts. - Malicious scripts can perform authenticated API calls to the Vitest server, potentially manipulating test runs or configuration.
- Attackers may pivot to broader compromise of developer workflows, manipulating test results or injecting malicious behaviors into CI pipelines.
General mitigation guidance
Mitigation should focus on treating browser-accessible endpoints and all query parameters as untrusted input and enforcing strict encoding rules.
Common defensive patterns include:
- Ensuring that any data from URLs, headers, or bodies is properly HTML- or JavaScript-encoded before being inserted into pages or scripts.
- Avoiding inline script construction from raw parameters; instead, pass values through non-executable data channels (e.g., JSON configuration fetched via XHR or structured objects).
- Applying a clear separation between code and data in dev tooling, so diagnostic or telemetry values never become part of executable source.
- Restricting capabilities of tokens like
VITEST_API_TOKENand favoring short-lived, least-privilege credentials that are not broadly accessible in the browser environment. - Adopting secure defaults for developer-facing dashboards and runners, such as disabling inline scripts and enabling Content Security Policy (CSP) where practical.
How teams detect issues like this
Detection can rely on a mix of code, configuration, and behavior analysis:
- Static analysis rules targeting direct insertion of request parameters (query, headers, body) into HTML or JavaScript templates can reveal similar patterns.
- Code review checklists for dev tooling and test harnesses should flag inline scripts that interpolate user-controlled values.
- Automated security scanning of exposed dev endpoints (including browser-based test runners) with XSS payloads can validate whether encoding is consistently applied.
- Organizational policies can require that web-facing frameworks and tooling pass security linting or CI hooks that block unsafe templating patterns.
- Observing unusual authenticated calls originating from test runner origins in logging or monitoring systems may highlight abuse of stolen tokens.

