CVE-2026-112949: @vitest/mocker Code Injection Vulnerability via Unauthenticated Manual Mock Registration
Summary
CVE-2026-112949: Vitest: Code injection via unauthenticated manual mock registration. Affects @vitest/mocker across 2 version ranges.
>= 2.1.0-beta.7, < 4.1.12
>= 5.0.0-beta.1, < 5.0.3
Fixed in 4.1.12 or 5.0.3, depending on the release line you run. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
Vitest is a modern testing framework designed for Vite applications, providing developers with tools to create and run tests efficiently. The @vitest/mocker package allows for mocking modules during testing, enabling developers to simulate various scenarios without relying on actual implementations. However, a vulnerability exists in the way this package handles mock registrations, specifically through its interceptorPlugin, which can be exploited by unauthenticated clients.
Vulnerability Detail
The vulnerability arises from the @vitest/mocker's interceptorPlugin, which accepts mock registrations over Vite's dev-server WebSocket without any authentication. This allows an attacker with access to the dev server to inject arbitrary JavaScript into the module source by manipulating the mock's URL. The lack of escaping for the interpolated URL means that malicious code can be executed in the developer's browser, leading to potential data theft, unauthorized actions, and other security risks. The vulnerability is classified under CWE-94 (Code Injection) and has a CVSS score of 4.7, indicating a moderate severity level.
How To Fix
Latest published version: 5.0.5 as of 22 Oct 2026
npm install @vitest/mocker@5.0.5
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
>= 2.1.0-beta.7, < 4.1.124.1.12npm install @vitest/mocker@4.1.12 -
>= 5.0.0-beta.1, < 5.0.35.0.3npm install @vitest/mocker@5.0.3
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
As a temporary workaround, avoid using the interceptorPlugin or mockerPlugin directly until you can update to the patched version. Additionally, ensure that your development environment is not exposed to untrusted clients who could exploit this vulnerability.
Conclusion
The CVE-2026-112949 vulnerability in the @vitest/mocker package poses a significant risk to developers by allowing code injection through unauthenticated mock registrations. It is crucial to update to the patched versions to mitigate this risk and ensure the security of your development environment.
See every vulnerability recorded for @vitest/mocker →
FAQ
The vulnerability allows unauthenticated clients to inject arbitrary JavaScript into modules served by the dev server, which can then execute in the developer's browser.
Developers using the @vitest/mocker package in their projects are at risk, particularly those who utilize the interceptorPlugin or mockerPlugin APIs.
You can use Vulert, which monitors and alerts for open-source vulnerabilities in your software. By analyzing your package-lock.json, Vulert can identify if your application is affected by this vulnerability.
Exploitation of this vulnerability can lead to code execution in the developer's browser, allowing attackers to access sensitive data, manipulate application behavior, and perform unauthorized actions.
Yes, avoid using the vulnerable plugins and restrict access to your development server to trusted clients only until the package is updated.
References
Related vulnerabilities
Recent vulnerabilities recorded for @vitest/mocker.