Skip to content

fix(dev): denied requests overly #20410

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

Merged
merged 4 commits into from
Jul 28, 2025

Conversation

sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Jul 15, 2025

Description

This line was not matching.

if (fs.allow.some((uri) => isUriInFilePath(uri, filePath))) return true

  • 9df604b: added some comments and renamed some vars to make it clear that some function receives normalized absolute paths (this leads to requests denied more than needed. this does not lead to requests allowed more than needed)
  • f73e0c6: removed the check against non-resolved ids as this was no longer needed
  • feb3040: changed from checkServingAccess to checkLoadingAccess for deniedServingAccessForTransform as this function receives a path instead of an URL (this leads to requests denied more than needed. this does not lead to requests allowed more than needed)
  • 8fe09fd: normalized paths before calling isFileLoadingAllowed (this isn't needed for the fix, but included as it's related to the change in 9df604b)

fixes #19795
fixes #20408
refs #20144

@sapphi-red sapphi-red requested review from patak-dev and bluwy July 15, 2025 12:00
@sapphi-red sapphi-red added p2-edge-case Bug, but has workaround or limited in scope (priority) feat: dev dev server labels Jul 15, 2025
@sapphi-red sapphi-red changed the title fix(dev): overly denied requests fix(dev): denied requests overly Jul 15, 2025
@patak-dev
Copy link
Member

/ecosystem-ci run

Copy link

pkg-pr-new bot commented Jul 15, 2025

Open in StackBlitz

npm i https://pkg.pr.new/vite@20410

commit: 8fe09fd

@SystemParadox
Copy link

I'm just an outside observer and not intimitely familar with all the specifics here so maybe I'm missing something, but I still seriously question why there should be any mention of svgRE in the transform middleware. What is anything specific to SVGs doing here?

The only reason this seems to be here is because the SVG handler further down isn't properly checking the requested path before reading the file on disk. So again, either this is a generic path security problem that should be fixed in a generic way and shouldn't have any mention of SVGs, or it's a specific problem with the SVG handler and it should be fixed there.

@vite-ecosystem-ci

This comment was marked as outdated.

@patak-dev
Copy link
Member

I'm just an outside observer and not intimitely familar with all the specifics here so maybe I'm missing something, but I still seriously question why there should be any mention of svgRE in the transform middleware. What is anything specific to SVGs doing here?

The only reason this seems to be here is because the SVG handler further down isn't properly checking the requested path before reading the file on disk. So again, either this is a generic path security problem that should be fixed in a generic way and shouldn't have any mention of SVGs, or it's a specific problem with the SVG handler and it should be fixed there.

There are two options. One is stopping denied files from ever entering the pipeline, and the other one is as you say, give the responsibility to every plugin that loads from the file system to do the check.

The idea with adding the check before entering the pipeline was that it would make plugins more secure. The check rawRE.test(id) || urlRE.test(id) || inlineRE.test(id) || svgRE.test(id) was what was needed for internal plugins, but the long term plan was to remove this condition and test every non-virtual id (and we could even remove this check

isFileLoadingAllowed(environment.getTopLevelConfig(), file)
).

This was also added in response to CVEs, so minimal changes were applied because we needed to release them in patches. I don't know now if the long term plan to remove the condition is feasible because there are virtual plugins that don't properly mark their ids with \0 though, and I think it is still a possibility that the current check is removed in favor of moving the checks before each load.

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes make sense to me. Nice to see some cleanups too.

@vite-ecosystem-ci
Copy link

Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably good to wait for a minor for this one?

@sapphi-red sapphi-red added this to the 7.1 milestone Jul 16, 2025
@sapphi-red sapphi-red merged commit 4be5270 into vitejs:main Jul 28, 2025
22 checks passed
@sapphi-red sapphi-red deleted the fix/overly-deny-requests branch July 28, 2025 03:07
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) trigger: preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken .svg import when importing dynamically Using url query param in vite dev server shows 403 page
4 participants