The vulnerability exists in the @vitest/mocker package, where redirect mock targets are not validated against Vite's file-serving allowlist. This allows an attacker to register a redirect mock that points to a file outside the intended project root. The root cause is the lack of path validation in two key areas:
-
Unauthenticated WebSocket: The interceptorPlugin's configureServer function sets up a WebSocket listener (vitest:interceptor:register) that accepts redirect mock registrations. The path provided by the client is combined with the server's root path without any checks to prevent directory traversal. An attacker who can connect to the dev server's WebSocket can exploit this to register a malicious redirect.
-
Authenticated RPC: A similar flaw exists in the setupBrowserRpc function, which handles mock registration for Vitest's browser mode. Although this path requires authentication, it still fails to validate the redirect path, posing a risk from authenticated users.
The vulnerability is triggered when the mocked module is requested. The interceptorPlugin's load hook then reads the file from the malicious path using readFile, disclosing its contents.
The patches fix this by introducing a check (isFileLoadingAllowed or a new checkFileAccess function) at the point of mock registration to ensure the resolved path is within the server's allowed file system boundaries.