Repository navigation #
This report was submitted with AI assistance
Description #
Summary
By sending an HTTP request to the dev server, a arbitrary code execution was possible.
Impact
Only apps that match the following condition are affected:
- explicitly exposes the Vite dev server to the network (using
--hostorserver.hostconfig option )
Details
Vite's resolver plugin has __vite-browser-external:<suffix> virtual module and __vite-optional-peer-dep:<suffix> virtual module. These modules embedded the module ID, which is derived from the URL, without escaping. The <suffix> can be any value, so any code was able to be injected in those modules.
Since Vite trusts the module code, there was two problems with this injection.
First, the modules referenced by a module are allowed for the server.fs check. For example, if the attacker injects import '/path/to/some-secret-file.txt', /path/to/some-secret-file.txt can be fetched.
Second, Vite uses eval to extract the value in the module code for new Worker and import.meta.glob. By using that functionality, the attacker can make Vite evaluate the injected code on the server. Vite prevents some module / global variables like exports, require to avoid bugs, but because this is not a security boundary, there's a bypass like globalThis.process.getBuiltinModule.
PoC
printf 'CANARY-SECRET-not-valid-js\n' > /tmp/decoy-secret.txt # outside the project
vite
/tmp/decoy-secret.txt stands in for any sensitive file outside the allow list.
- Check that the target is correctly blocked.
GET /@fs/tmp/decoy-secret.txtreturns 403 Restricted ("outside of Vite serving allow list"). - Perform the injection. Send a request carrying the crafted id (it is shown decoded. \n are real newlines in the sent URL, percent-encoded on the wire): This pulls
GET /@id/__vite-browser-external:`);}});
import '/@fs/tmp/decoy-secret.txt';
var z=new Proxy({}, {get(_, key) {throw new Error(`?import
/tmp/decoy-secret.txt into the module graph.
3. Extract the file. GET /@fs/tmp/decoy-secret.txt returns the content in the body (CANARY-SECRET-not-valid-js ).
Notes on the fixes
The vulnerable code in v8 lives in the Rolldown binary. The code is only meant to be used by Vite and thus the report is not linked to Rolldown. Vite 8.3.7 and Vite 8.2.5 relies on the fix in Rolldown 1.2.17. Vite 8.1.7 relies on the fix in Rolldown 1.1.7.