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
saveTestFileand 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
isFileServingAllowedto 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, orfs.createReadStreamwithout 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.

