Description
Vitest is a testing framework powered by Vite. Affected versions are subject to arbitrary remote Code Execution when accessing a malicious website while Vitest API server is listening by Cross-site WebSocket hijacking (CSWSH) attacks. When `api` option is enabled (Vitest UI enables it), Vitest starts a WebSocket server. This WebSocket server did not check Origin header and did not have any authorization mechanism and was vulnerable to CSWSH attacks. This WebSocket server has `saveTestFile` API that can edit a test file and `rerun` API that can rerun the tests. An attacker can execute arbitrary code by injecting a code in a test file by the `saveTestFile` API and then running that file by calling the `rerun` API. This vulnerability can result in remote code execution for users that are using Vitest serve API. This issue has been patched in versions 1.6.1, 2.1.9 and 3.0.5. Users are advised to upgrade. There are no known workarounds for this vulnerability.
EPSS Score:
0%
Comprehensive Technical Analysis of EUVD-2025-0225
1. Vulnerability Assessment and Severity Evaluation
The vulnerability described in EUVD-2025-0225 affects the Vitest testing framework, which is powered by Vite. The issue allows for arbitrary remote code execution (RCE) through Cross-site WebSocket hijacking (CSWSH) attacks. The WebSocket server in Vitest lacks proper Origin header checks and authorization mechanisms, making it susceptible to CSWSH attacks. This vulnerability is particularly severe because it can lead to RCE, which is one of the most critical types of vulnerabilities.
Severity Evaluation:
- CVSS Base Score: 9.7
- CVSS Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H
The high CVSS score indicates that this vulnerability is critical. The attack vector is network-based (AV:N), requires low complexity (AC:L), does not require privileges (PR:N), and requires user interaction (UI:R). The impact on confidentiality, integrity, and availability is high (C:H/I:H/A:H).
2. Potential Attack Vectors and Exploitation Methods
Attack Vectors:
- Cross-site WebSocket Hijacking (CSWSH): An attacker can exploit the vulnerability by tricking a user into visiting a malicious website while the Vitest API server is listening. The malicious website can then hijack the WebSocket connection.
- Arbitrary Code Execution: Once the WebSocket connection is hijacked, the attacker can use the
saveTestFileAPI to inject malicious code into a test file and then execute it using thererunAPI.
Exploitation Methods:
- Phishing: An attacker can send a phishing email or message containing a link to a malicious website.
- Malicious Advertisements: An attacker can place malicious advertisements on legitimate websites that, when clicked, exploit the vulnerability.
- Compromised Websites: An attacker can compromise a legitimate website and inject malicious code to exploit the vulnerability.
3. Affected Systems and Software Versions
The vulnerability affects the following versions of Vitest:
- Version 2.0.0 to 2.1.8
- Version ≤ 0.0.125
- Version 3.0.0 to 3.0.4
- Version 1.0.0 to 1.6.0
Users are advised to upgrade to the patched versions:
- 1.6.1
- 2.1.9
- 3.0.5
4. Recommended Mitigation Strategies
Immediate Actions:
- Upgrade Vitest: Ensure that all instances of Vitest are upgraded to the patched versions (1.6.1, 2.1.9, or 3.0.5).
- Disable API Option: If upgrading is not immediately possible, consider disabling the
apioption in Vitest to mitigate the risk.
Long-Term Strategies:
- Regular Patch Management: Implement a robust patch management process to ensure that all software is kept up-to-date.
- User Education: Educate users about the risks of phishing and the importance of verifying the authenticity of links before clicking.
- Network Security: Implement network security measures such as firewalls and intrusion detection systems to monitor and block suspicious traffic.
5. Impact on European Cybersecurity Landscape
The vulnerability in Vitest poses a significant risk to organizations and individuals using the framework within the European Union. Given the critical nature of RCE vulnerabilities, this issue could lead to data breaches, unauthorized access, and potential disruption of services. The widespread use of Vitest in development and testing environments amplifies the potential impact, making it crucial for organizations to address this vulnerability promptly.
6. Technical Details for Security Professionals
Vulnerability Details:
- WebSocket Server: The WebSocket server in Vitest does not check the Origin header and lacks authorization mechanisms, making it vulnerable to CSWSH attacks.
- APIs Involved: The
saveTestFileAPI allows editing of test files, and thererunAPI allows rerunning tests. An attacker can inject malicious code into a test file and execute it.
Code References:
- Setup File: The vulnerability is present in the setup file of the Vitest API. Relevant code sections can be found in the provided GitHub links:
Patches:
- Commit References: The patches can be reviewed in the following GitHub commits:
Additional References:
By addressing this vulnerability promptly and implementing robust security measures, organizations can mitigate the risks associated with EUVD-2025-0225 and enhance their overall cybersecurity posture.