CVE-2025-24964

9.6 CRITICAL

📋 TL;DR

This vulnerability allows remote attackers to execute arbitrary code on systems running Vitest with the API server enabled. Attackers can exploit Cross-site WebSocket hijacking to inject malicious code into test files and trigger execution. Users running Vitest with the API option enabled (including Vitest UI users) are affected.

💻 Affected Systems

Products:
  • Vitest
Versions: All versions before 1.6.1, 2.1.9, and 3.0.5
Operating Systems: All operating systems running Vitest
Default Config Vulnerable: ✅ No
Notes: Only vulnerable when the 'api' option is enabled. Vitest UI enables this option by default.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Full system compromise with attacker gaining complete control over the affected system, potentially leading to data theft, ransomware deployment, or lateral movement within the network.

🟠

Likely Case

Remote code execution allowing attackers to run arbitrary commands, steal sensitive data, or install malware on the developer's machine.

🟢

If Mitigated

No impact if API server is disabled or proper network segmentation isolates the Vitest instance from untrusted networks.

🌐 Internet-Facing: HIGH - WebSocket server lacks origin checking and authentication, making internet-exposed instances trivially exploitable.
🏢 Internal Only: HIGH - Even internal instances are vulnerable to attacks from malicious internal websites or compromised internal systems.

🎯 Exploit Status

Public PoC: ✅ No
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Exploitation requires the victim to visit a malicious website while Vitest API server is running. No authentication needed to access WebSocket APIs.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: 1.6.1, 2.1.9, or 3.0.5 depending on major version

Vendor Advisory: https://github.com/vitest-dev/vitest/security/advisories/GHSA-9crc-q9x8-hgqq

Restart Required: Yes

Instructions:

1. Identify your Vitest major version (1.x, 2.x, or 3.x). 2. Update to the patched version: npm update vitest@^1.6.1 or npm update vitest@^2.1.9 or npm update vitest@^3.0.5. 3. Restart any running Vitest processes.

🔧 Temporary Workarounds

Disable API Server

all

Disable the Vitest API server to prevent WebSocket exposure

Set api: false in vitest.config.js or remove --api flag from startup

Network Isolation

all

Restrict network access to Vitest API server

Use firewall rules to block external access to Vitest WebSocket port (default varies)

🧯 If You Can't Patch

  • Disable the Vitest API server completely in configuration
  • Ensure Vitest only runs in isolated network segments without internet access

🔍 How to Verify

Check if Vulnerable:

Check if Vitest version is below 1.6.1, 2.1.9, or 3.0.5 AND api option is enabled in configuration

Check Version:

npx vitest --version or check package.json

Verify Fix Applied:

Verify Vitest version is 1.6.1+, 2.1.9+, or 3.0.5+ and test that WebSocket connections now require proper origin validation

📡 Detection & Monitoring

Log Indicators:

  • Unexpected WebSocket connections to Vitest API
  • Unusual test file modifications
  • Unexpected test execution events

Network Indicators:

  • WebSocket traffic to Vitest port from unexpected origins
  • saveTestFile API calls followed by rerun API calls

SIEM Query:

websocket.destination_port: [vitest_port] AND NOT websocket.origin_header: [expected_origins]

🔗 References

📤 Share & Export