Summary
A path traversal and missing authorization check in Vitest Browser Mode commands allows browser-supplied paths to bypass the allowWrite permission boundary. A client that can reach the Browser Mode API may read, create, overwrite, or delete files accessible to the Vitest process.
Affected context
The issue occurs in Vitest deployments that expose the Browser Mode API and process commands such as uploads, screenshots, tracing operations, or trace annotations. Risk increases when the API is reachable by an untrusted client, because supplied paths are not consistently restricted to the project root or governed by the write-permission setting.
Exploit preconditions
- Attack surface: Vitest Browser Mode API
- Required access: Ability to reach and submit commands to the Browser Mode API
- Trigger point: Browser provider commands that accept file paths
- Why exploitation is possible: The commands trust browser-supplied paths without consistently enforcing
allowWriteor project-root confinement - Required runtime condition: The target files must be accessible to the Vitest process
Why this happens
The underlying flaw combines improper path validation with missing authorization enforcement. File-operation handlers accept client-provided paths without reliably canonicalizing and constraining them to an intended directory, while write-capable actions can proceed even when allowWrite is disabled. This behavior maps primarily to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, with related concerns involving exposed file resources and missing authorization checks.
Potential impact
- An attacker may read sensitive local files accessible to the Vitest process.
- An attacker could create or overwrite image, screenshot, or trace files.
- An attacker could delete files permitted by the process filesystem privileges.
- Test artifacts, diagnostics, or project data could be tampered with.
- File manipulation may contribute to broader application or development-environment compromise.
General mitigation guidance
Mitigation generally focuses on treating all browser-supplied paths as untrusted and enforcing authorization before any filesystem operation.
Common defensive patterns include:
- Require an explicit write authorization gate for every write, overwrite, and delete operation.
- Resolve and canonicalize paths, then enforce confinement beneath an approved project or artifact directory.
- Prefer safe, server-generated filenames and opaque artifact identifiers over client-selected paths.
- Use allowlisted operation-specific directories and file types.
- Run the Vitest process with least-privilege filesystem permissions.
- Keep the Browser Mode API on a trusted network boundary and require appropriate authentication.
- Apply read-only filesystem controls where file creation or modification is unnecessary.
How teams detect issues like this
Organizations can look for:
- Static analysis findings where request-derived values flow into filesystem APIs without canonicalization or directory-boundary checks.
- Code review signals showing authorization checks applied to some file commands but omitted from related commands.
- Tests that submit absolute paths, parent-directory segments, symlinked paths, and paths outside the project root.
- Policy checks requiring centralized path-validation and permission-enforcement helpers for browser-facing file operations.
- Runtime monitoring for unexpected reads, writes, overwrites, or deletions performed by the Vitest process.
- Automated security review tools that identify path traversal and missing authorization patterns.

