vite icon indicating copy to clipboard operation
vite copied to clipboard

Virtual modules ending in *.svg fail to load

Open Fuzzyma opened this issue 8 months ago • 4 comments

Describe the bug

I am using a vite plugin to add a virtual module. Just by chance, since its generating an svg, I ended its name in *.svg. This worked fine in vite v5 but fails after upgrading to vite v6. The server seems to resolve the svg differently and cant find in. Renaming the ending immediately solves this problem.

Reproduction

https://stackblitz.com/edit/vitejs-vite-ecxwyqxf?file=src%2Fmain.js

Steps to reproduce

  • load the reproduction and see it not working
  • rename both occurrences of the virtual module to not end in *.svg
  • see a rectangle appear

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 7 PRO 6850HS with Radeon Graphics
    Memory: 12.45 GB / 15.28 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
    Yarn: 3.3.0 - ~/.nvm/versions/node/v22.14.0/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
    pnpm: 10.4.1 - ~/.local/share/pnpm/pnpm
    bun: 1.2.3 - ~/.bun/bin/bun
  Browsers:
    Chrome: 134.0.6998.88

Used Package Manager

npm

Logs

No response

Validations

Fuzzyma avatar Apr 22 '25 16:04 Fuzzyma

Probably it's happening because deniedServingAccessForTransform returns false even if the file does not exist on the file system. https://github.com/vitejs/vite/blob/3db608a4c30a327d05007a4128b178493b1f4691/packages/vite/src/node/server/transformRequest.ts#L256-L260 https://github.com/vitejs/vite/blob/3db608a4c30a327d05007a4128b178493b1f4691/packages/vite/src/node/server/middlewares/transform.ts#L252-L254 https://github.com/vitejs/vite/blob/3db608a4c30a327d05007a4128b178493b1f4691/packages/vite/src/node/server/middlewares/static.ts#L271 https://github.com/vitejs/vite/blob/3db608a4c30a327d05007a4128b178493b1f4691/packages/vite/src/node/server/middlewares/static.ts#L284-L286 I guess changing ensureServingAccess to return 3-values (instead of a boolean) and calling next on the caller side can solve this issue.

sapphi-red avatar Apr 23 '25 03:04 sapphi-red

I think this also happens with the newer version of v5 as it's caused by the security patch.

sapphi-red avatar Apr 23 '25 03:04 sapphi-red

I think this also happens with the newer version of v5 as it's caused by the security patch.

possible. My original version was on a fairly old v5

Fuzzyma avatar Apr 23 '25 09:04 Fuzzyma

Just for the records (stumbled over this as well with our plugin)

Security report: https://github.com/vitejs/vite/security/advisories/GHSA-xcj6-pq6g-qj4x Fixed in vite 6.3.0-beta.2: https://github.com/vitejs/vite/pull/19782 Backport to vite 5.4.17: https://github.com/vitejs/vite/pull/19784

danielrentz avatar May 07 '25 04:05 danielrentz