/

CVE-2026-47429

Severity:

CRITICAL RISK

(9.8)

Path Traversal (CWE-22) in Vitest UI/API Server

CVE-2026-47429

Analyzed

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File Read and Script Execution

Severity:

CRITICAL RISK

(9.8)

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

A path traversal flaw in the Vitest UI/API server on Windows allows crafted \\?\\..\\ paths to bypass file serving restrictions and read files outside the project directory.

Combined with exposed API write and rerun capabilities, an attacker could abuse these endpoints to write or execute arbitrary test scripts when the Vitest server is accessible.

Affected context

The vulnerability affects projects running the Vitest UI/API server on Windows systems, particularly in development or shared environments where the server is exposed to other users or networks.

It occurs when the server relies on isFileServingAllowed to restrict file access for the /__vitest_attachment__ route but fails to properly handle special Windows-style path prefixes such as \\?\\..\\.

In this context, attackers who can reach the Vitest UI/API endpoints may access files outside the intended project root and interact with exposed write/rerun features.

Exploit preconditions

  • Attack surface: Vitest UI/API HTTP endpoints reachable over localhost, internal network, or the internet.
  • Required access: Ability to send HTTP requests to the running Vitest UI/API server on a Windows host.
  • Trigger point (file read): Supplying crafted \\?\\..\\ style paths to /__vitest_attachment__ to traverse directories and access non-project files.
  • Trigger point (script execution): Invoking write-related endpoints such as saveTestFile and rerun features to create or modify test files that will be executed by the test runner.
  • Why exploitation is possible: The file permission check is applied before or without normalizing Windows-specific paths, causing isFileServingAllowed to incorrectly authorize access; additionally, UI/API endpoints expose file-writing and test rerun behavior without strong isolation from untrusted clients.

Why this happens

At its core, this issue stems from improper validation and normalization of filesystem paths before authorization decisions are made.

The server-side logic relies on isFileServingAllowed to determine whether a requested file path resides within an allowed directory, but it does not fully account for Windows path semantics and special prefixes (\\?\\) that change how relative segments like .. are interpreted.

This maps directly to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the application trusts user-supplied path segments and joins or evaluates them without canonicalization, enabling traversal outside a constrained root.

The exposed write and rerun API features further compound the risk by allowing clients to influence on-disk test files and trigger their execution, effectively turning file-system access flaws into potential arbitrary script execution in the test environment.

Potential impact

  • Reading sensitive files outside the project directory, such as configuration files, credentials, or user data, if accessible to the Vitest process.
  • Discovering internal directory structures, source code, or build artifacts that were not intended to be exposed over HTTP.
  • Writing or modifying test files through exposed endpoints and causing them to be executed by the Vitest runner.
  • Achieving arbitrary code execution in the context of the user running Vitest (for example, a developer account) by abusing test execution mechanisms.
  • Facilitating lateral movement within a development environment by harvesting secrets or modifying tests used in CI-like workflows.

General mitigation guidance

Mitigation typically centers on robust path handling, narrowing API capabilities, and reducing trust boundaries around development tooling.

Path validation and normalization patterns:

  • Canonicalize and normalize all incoming filesystem paths before authorization, resolving .., symbolic links, and Windows-specific prefixes.
  • Enforce strict root directory constraints by comparing canonical paths against a known allowed base directory and rejecting any request that attempts to escape it.
  • Treat any non-standard or device-style prefixes (e.g., \\?\ on Windows) as unsafe and disallow them in HTTP file-serving routes.

API surface and privilege reduction:

  • Limit or disable write-oriented endpoints (such as those saving test files) when not strictly necessary, especially in shared or remote-access scenarios.
  • Apply explicit authorization or origin checks to UI/API routes to ensure only intended users can trigger file writes and test reruns.
  • Run the Vitest process with least privilege, using user accounts and filesystem permissions that strictly confine what files the process can read or write.

Secure-by-default configuration:

  • Default development servers to bind only to localhost and require deliberate configuration changes before exposing them to wider networks.
  • Provide clear documentation and configuration options for project-level allowed paths, keeping attachment and artifact directories tightly scoped.

How teams detect issues like this

Detection efforts can focus both on code-level patterns and runtime behavior.

Static and code review approaches:

  • Use static analysis or linting rules to flag direct concatenation of user-controlled path segments without canonicalization or root-directory checks.
  • During code review, look for file-serving or file-writing utilities that accept raw request parameters and pass them into filesystem APIs such as fs.readFile, fs.writeFile, or fs.createReadStream without prior validation.
  • Enforce internal guidelines that mandate the use of centralized, security-reviewed path resolution helpers for all routes that touch the filesystem.

Runtime and operational monitoring:

  • Inspect HTTP logs for suspicious path patterns containing .., unusual Windows prefixes like \\?\, or attempts to access files outside known project paths.
  • Implement application-level logging around file-serving and file-writing endpoints, recording normalized paths and rejecting anomalous or out-of-root requests.

Automated tooling:

  • Integrate automated security testing tools or DAST scanners that specifically probe for path traversal through web-accessible endpoints.
  • Incorporate security-focused unit and integration tests that exercise path-handling logic using edge-case Windows paths and traversal sequences.

Sources

SourceLink
github.comgithub.com/vitest-dev/vitest/commit/20e00ef7808de6d330c5e2fda530f686e08f1c8d
github.comgithub.com/vitest-dev/vitest/commit/af88b1f5d82844a4761ea9a977156c98e2b14ca8
github.comgithub.com/vitest-dev/vitest/pull/10445
github.comgithub.com/vitest-dev/vitest/pull/9350
github.comgithub.com/vitest-dev/vitest/releases/tag/v3.2.5
github.comgithub.com/vitest-dev/vitest/releases/tag/v4.1.0
github.comgithub.com/vitest-dev/vitest/security/advisories/GHSA-5xrq-8626-4rwp

Frequently asked

questions

It can be remotely exploitable if the Vitest UI/API server is exposed beyond localhost, such as when bound to all interfaces or accessible from other machines on the network.

If the server is strictly bound to localhost and only accessible by the local developer, the practical exposure is significantly reduced, though still relevant in multi-user or shared desktop scenarios.

An attacker needs the ability to send HTTP requests to the Vitest UI/API server running on a Windows host.

No filesystem access or shell account is required; the attack operates entirely through HTTP endpoints that mishandle paths and write/rerun operations.

The most robust pattern is to normalize and canonicalize all paths, compare them against a predefined allowed root directory, and reject any request that attempts to escape that root.

In addition, restricting or removing write-capable endpoints from untrusted clients helps prevent path issues from escalating into arbitrary code execution.

Adopt a standard path-handling utility that performs canonicalization and root enforcement, and mandate its usage for all filesystem-exposed routes.

Combine that with secure defaults (localhost-only binding, minimal API surface), thorough code review focused on file and path usage, and automated tests that include traversal and platform-specific path edge cases.

Find out what's already
exploitable in your codebase.