Skip to content

Virtual modules ending in *.svg fail to load #19914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
7 tasks done
Fuzzyma opened this issue Apr 22, 2025 · 4 comments
Open
7 tasks done

Virtual modules ending in *.svg fail to load #19914

Fuzzyma opened this issue Apr 22, 2025 · 4 comments
Labels
feat: dev dev server p2-edge-case Bug, but has workaround or limited in scope (priority) regression The issue only appears after a new release

Comments

@Fuzzyma
Copy link

Fuzzyma commented Apr 22, 2025

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

@sapphi-red sapphi-red added p2-edge-case Bug, but has workaround or limited in scope (priority) regression The issue only appears after a new release feat: dev dev server labels Apr 23, 2025
@sapphi-red
Copy link
Member

Probably it's happening because deniedServingAccessForTransform returns false even if the file does not exist on the file system.

if (options.allowId && !options.allowId(id)) {
const err: any = new Error(`Denied ID ${id}`)
err.code = ERR_DENIED_ID
throw err
}

allowId(id) {
return !deniedServingAccessForTransform(id, server, res, next)
},

if (isFileReadable(cleanUrl(url))) {

// if the file doesn't exist, we shouldn't restrict this path as it can
// be an API call. Middlewares would issue a 404 if the file isn't handled
next()

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
Copy link
Member

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

@Fuzzyma
Copy link
Author

Fuzzyma commented Apr 23, 2025

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

@danielrentz
Copy link

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

Security report: GHSA-xcj6-pq6g-qj4x
Fixed in vite 6.3.0-beta.2: #19782
Backport to vite 5.4.17: #19784

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: dev dev server p2-edge-case Bug, but has workaround or limited in scope (priority) regression The issue only appears after a new release
Projects
None yet
Development

No branches or pull requests

3 participants