Vite 6.0.6 represents a minor update to the Vite ecosystem, succeeding version 6.0.5. While both versions share the same core purpose as a native-ESM powered web development build tool, a key difference lies in the updated dependency on esbuild. Vite 6.0.6 adopts esbuild version 0.24.2, a slight bump from the 0.24.0 used in version 6.0.5. This seemingly small change might incorporate bug fixes, performance tweaks, or even new features within esbuild itself, potentially leading to faster build times or improved compatibility.
For developers using Vite, understanding the impact of dependency updates like this, even minor version bumps, is crucial. While the core functionalities of Vite remain intact, it's advisable to look at the esbuild changelog. Both versions rely on a rich ecosystem of dependencies, like rollup, postcss, and a plethora of development tools like sass, lightningcss, and @rollup/plugin-* family, providing a comprehensive suite for modern web development. The peerDependencies highlight compatibility with various frontend technologies, including tsx, less, sass, and @types/node versions. Developers embracing the Vite ecosystem should find this version aligns seamlessly within web projects. Additionally, the update occurred on 2024-12-26, a few days after the release of Vite 6.0.5 on 2024-12-20, suggesting a quick patch or feature enhancement.
All the vulnerabilities related to the version 6.0.6 of the package
Websites were able to send any requests to the development server and read the response in vite
Vite allowed any websites to send any requests to the development server and read the response due to default CORS settings and lack of validation on the Origin header for WebSocket connections.
[!WARNING] This vulnerability even applies to users that only run the Vite dev server on the local machine and does not expose the dev server to the network.
Users that does not match either of the following conditions should be able to upgrade to a newer version of Vite that fixes the vulnerability without any additional configuration.
localhost
or *.localhost
If you are using the backend integration feature and not setting server.origin
, you need to add the origin of the backend server to the server.cors.origin
option. Make sure to set a specific origin rather than *
, otherwise any origin can access your development server.
If you are using a reverse proxy in front of Vite and sending requests to Vite with a hostname other than localhost
or *.localhost
, you need to add the hostname to the new server.allowedHosts
option. For example, if the reverse proxy is sending requests to http://vite:5173
, you need to add vite
to the server.allowedHosts
option.
localhost
or *.localhost
You need to add the hostname to the new server.allowedHosts
option. For example, if you are accessing the development server via http://foo.example.com:8080
, you need to add foo.example.com
to the server.allowedHosts
option.
If you are using a plugin / framework, try upgrading to a newer version of Vite that fixes the vulnerability. If the WebSocket connection appears not to be working, the plugin / framework may have a code that connects to the WebSocket server on their own from the browser.
In that case, you can either:
legacy.skipWebSocketTokenCheck: true
to opt-out the fix for [2] while the plugin / framework is incompatible with the new version of Vite
Set server.cors
to false
or limit server.cors.origin
to trusted origins.
There aren't any mitigations for this.
Use Chrome 94+ or use HTTPS for the development server.
There are three causes that allowed malicious websites to send any requests to the development server:
Vite sets the Access-Control-Allow-Origin
header depending on server.cors
option. The default value was true
which sets Access-Control-Allow-Origin: *
. This allows websites on any origin to fetch
contents served on the development server.
Attack scenario:
http://malicious.example.com
).fetch('http://127.0.0.1:5173/main.js')
request by JS in that malicious web page. This request is normally blocked by same-origin policy, but that's not the case for the reasons above.http://127.0.0.1:5173/main.js
.Vite starts a WebSocket server to handle HMR and other functionalities. This WebSocket server did not perform validation on the Origin header and was vulnerable to Cross-Site WebSocket Hijacking (CSWSH) attacks. With that attack, an attacker can read and write messages on the WebSocket connection. Vite only sends some information over the WebSocket connection (list of the file paths that changed, the file content where the errored happened, etc.), but plugins can send arbitrary messages and may include more sensitive information.
Attack scenario:
http://malicious.example.com
).new WebSocket('http://127.0.0.1:5173', 'vite-hmr')
by JS in that malicious web page.Unless server.https
is set, Vite starts the development server on HTTP. Non-HTTPS servers are vulnerable to DNS rebinding attacks without validation on the Host header. But Vite did not perform validation on the Host header. By exploiting this vulnerability, an attacker can send arbitrary requests to the development server bypassing the same-origin policy.
http://malicious.example.com:5173
) (HTTPS won't work).fetch('/main.js')
request by JS in that malicious web page.http://127.0.0.1:5173/main.js
bypassing the same origin policy.Users with the default server.cors
option may:
server.proxy
may have those functionalities.All users may get the file paths of the files that changed and the file content where the error happened be stolen by malicious websites.
For users that is using a plugin that sends messages over WebSocket, that content may be stolen by malicious websites.
For users that is using a plugin that has a functionality that is triggered by messages over WebSocket, that functionality may be exploited by malicious websites.
Users using HTTP for the development server and using a browser that is not Chrome 94+ may:
server.proxy
may have those functionalities.Chrome 94+ users are not affected for [3], because sending a request to a private network page from public non-HTTPS page is forbidden since Chrome 94.
Safari has a bug that blocks requests to loopback addresses from HTTPS origins. This means when the user is using Safari and Vite is listening on lookback addresses, there's another condition of "the malicious web page is served on HTTP" to make [1] and [2] to work.
react
template which utilizes HMR functionality.npm create vite@latest my-vue-app-react -- --template react
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>vite CSWSH</title>
</head>
<body>
<div id="logs"></div>
<script>
const div = document.querySelectorAll('#logs')[0];
const ws = new WebSocket('ws://localhost:5173','vite-hmr');
ws.onmessage = event => {
const logLine = document.createElement('p');
logLine.innerHTML = event.data;
div.append(logLine);
};
</script>
</body>
</html>
npm run dev
http://localhost:5173/
) as well as the malicious page in the browser.src/App.jsx
file and intentionally place a syntax errorHere's a video demonstrating the POC:
https://github.com/user-attachments/assets/a4ad05cd-0b34-461c-9ff6-d7c8663d6961
Vite bypasses server.fs.deny when using ?raw??
The contents of arbitrary files can be returned to the browser.
Only apps explicitly exposing the Vite dev server to the network (using --host
or server.host
config option) are affected.
@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.
$ 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...
Vite has a server.fs.deny
bypassed for inline
and raw
with ?import
query
The contents of arbitrary files can be returned to the browser.
Only apps explicitly exposing the Vite dev server to the network (using --host
or server.host
config option) are affected.
?inline&import
(originally reported as ?import&?inline=1.wasm?init
)?raw?import
/@fs/
isn't needed to reproduce the issue for files inside the project root.
Original report (check details above for simplified cases):
The ?import&?inline=1.wasm?init ending allows attackers to read arbitrary files and returns the file content if it exists. Base64 decoding needs to be performed twice
$ npm create vite@latest
$ cd vite-project/
$ npm install
$ npm run dev
Example full URL http://localhost:5173/@fs/C:/windows/win.ini?import&?inline=1.wasm?init
Vite allows server.fs.deny to be bypassed with .svg or relative paths
The contents of arbitrary files can be returned to the browser.
Only apps explicitly exposing the Vite dev server to the network (using --host or server.host config option) are affected.
.svg
Requests ending with .svg
are loaded at this line.
https://github.com/vitejs/vite/blob/037f801075ec35bb6e52145d659f71a23813c48f/packages/vite/src/node/plugins/asset.ts#L285-L290
By adding ?.svg
with ?.wasm?init
or with sec-fetch-dest: script
header, the restriction was able to bypass.
This bypass is only possible if the file is smaller than build.assetsInlineLimit
(default: 4kB) and when using Vite 6.0+.
The check was applied before the id normalization. This allowed requests to bypass with relative paths (e.g. ../../
).
npm create vite@latest
cd vite-project/
npm install
npm run dev
send request to read etc/passwd
curl 'http://127.0.0.1:5173/etc/passwd?.svg?.wasm?init'
curl 'http://127.0.0.1:5173/@fs/x/x/x/vite-project/?/../../../../../etc/passwd?import&?raw'
Vite has an server.fs.deny
bypass with an invalid request-target
The contents of arbitrary files can be returned to the browser if the dev server is running on Node or Bun.
Only apps with the following conditions are affected.
HTTP 1.1 spec (RFC 9112) does not allow #
in request-target
. Although an attacker can send such a request. For those requests with an invalid request-line
(it includes request-target
), the spec recommends to reject them with 400 or 301. The same can be said for HTTP 2 (ref1, ref2, ref3).
On Node and Bun, those requests are not rejected internally and is passed to the user land. For those requests, the value of http.IncomingMessage.url
contains #
. Vite assumed req.url
won't contain #
when checking server.fs.deny
, allowing those kinds of requests to bypass the check.
On Deno, those requests are not rejected internally and is passed to the user land as well. But for those requests, the value of http.IncomingMessage.url
did not contain #
.
npm create vite@latest
cd vite-project/
npm install
npm run dev
send request to read /etc/passwd
curl --request-target /@fs/Users/doggy/Desktop/vite-project/#/../../../../../etc/passwd http://127.0.0.1:5173
Vite's server.fs.deny bypassed with /. for files under project root
The contents of files in the project root
that are denied by a file matching pattern can be returned to the browser.
Only apps explicitly exposing the Vite dev server to the network (using --host or server.host config option) are affected.
Only files that are under project root
and are denied by a file matching pattern can be bypassed.
.env
, .env.*
, *.{crt,pem}
, **/.env
**/.git/**
, .git/**
, .git/**/*
server.fs.deny
can contain patterns matching against files (by default it includes .env
, .env.*
, *.{crt,pem}
as such patterns).
These patterns were able to bypass for files under root
by using a combination of slash and dot (/.
).
npm create vite@latest
cd vite-project/
cat "secret" > .env
npm install
npm run dev
curl --request-target /.env/. http://localhost:5173
esbuild enables any website to send any requests to the development server and read the response
esbuild allows any websites to send any request to the development server and read the response due to default CORS settings.
esbuild sets Access-Control-Allow-Origin: *
header to all requests, including the SSE connection, which allows any websites to send any request to the development server and read the response.
https://github.com/evanw/esbuild/blob/df815ac27b84f8b34374c9182a93c94718f8a630/pkg/api/serve_other.go#L121 https://github.com/evanw/esbuild/blob/df815ac27b84f8b34374c9182a93c94718f8a630/pkg/api/serve_other.go#L363
Attack scenario:
http://malicious.example.com
).fetch('http://127.0.0.1:8000/main.js')
request by JS in that malicious web page. This request is normally blocked by same-origin policy, but that's not the case for the reasons above.http://127.0.0.1:8000/main.js
.In this scenario, I assumed that the attacker knows the URL of the bundle output file name. But the attacker can also get that information by
/index.html
: normally you have a script tag here/assets
: it's common to have a assets
directory when you have JS files and CSS files in a different directory and the directory listing feature tells the attacker the list of files/esbuild
SSE endpoint: the SSE endpoint sends the URL path of the changed files when the file is changed (new EventSource('/esbuild').addEventListener('change', e => console.log(e.type, e.data))
)The scenario above fetches the compiled content, but if the victim has the source map option enabled, the attacker can also get the non-compiled content by fetching the source map file.
npm i
npm run watch
fetch('http://127.0.0.1:8000/app.js').then(r => r.text()).then(content => console.log(content))
in a different website's dev tools.Users using the serve feature may get the source code stolen by malicious websites.