/

CVE-2026-47428

Severity:

CRITICAL RISK

(9.6)

Reflected XSS (CWE-79) in Vitest Browser Test Runner

CVE-2026-47428

Deferred

Vulnerability type

Category:

Cross-Site Scripting (XSS)

CWE:

CWE-79

Impact:

Authentication Token Theft and Arbitrary Script Execution

Severity:

CRITICAL RISK

(9.6)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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 otelCarrier or 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 otelCarrier query 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_TOKEN and 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_TOKEN and 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.

Sources

SourceLink
github.comgithub.com/vitest-dev/vitest/commit/18af98cee1830604d57f6a02bf28f8067cdffc06
github.comgithub.com/vitest-dev/vitest/commit/3514f9fa135c90e1c35754fc4d27c9cf351faafa
github.comgithub.com/vitest-dev/vitest/pull/10283
github.comgithub.com/vitest-dev/vitest/pull/10285
github.comgithub.com/vitest-dev/vitest/releases/tag/v4.1.6
github.comgithub.com/vitest-dev/vitest/releases/tag/v5.0.0-beta.3
github.comgithub.com/vitest-dev/vitest/security/advisories/GHSA-2h32-95rg-cppp

Frequently asked

questions

It is exploitable over the network wherever the Vitest Browser Mode runner endpoint is reachable. Attackers need to convince a user (often a developer or CI operator) to open a crafted URL targeting the /__vitest_test__/ endpoint.

The attacker must be able to send or host a malicious browser-runner URL and get it opened in a browser that has access to the Vitest server origin. No prior authentication is required if the endpoint itself is reachable.

The safest pattern is to never inject untrusted data directly into HTML or JavaScript. Instead, consistently encode all dynamic values, avoid constructing inline scripts from URL parameters, and separate diagnostic or telemetry data from executable code.

Teams can define security standards for internal tooling, enforce output encoding in templates, and use automated static analysis and CI checks to block direct interpolation of request parameters into scripts. Regular security reviews of dev endpoints and minimizing exposure of tokens in browser contexts also help prevent recurrence.

Find out what's already
exploitable in your codebase.