Repository navigation
Conversation
The non-`fullBundle` branch of `indexHtmlMiddleware` called `decodeURIComponent(url)` (and `decodeURIComponent(fsPathFromId(url))`) without a guard. A request for a malformed URL such as `GET /%c0.html` therefore threw `URIError: URI malformed`, crashing the middleware instead of falling through. #22781 already added the identical guard to the `fullBundle` branch. This commit mirrors that pattern to the regular dev-server path: decode once inside a try/catch, call `return next()` on failure, and use the decoded value (`pathname`) in both the `/@fs/` and the root branches. Valid input is byte-identical to the previous behaviour; only the throwing path changes.
Contributor
Author
|
Closing this since CI is red and I can't verify it properly. I'd rather not leave a broken PR in your queue. Sorry for the noise. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The non-
fullBundlebranch ofindexHtmlMiddlewarecalleddecodeURIComponent(url)unguarded in two places (packages/vite/src/node/server/middlewares/indexHtml.ts). A request for a malformed.htmlURL such asGET /%c0.htmlpassesrejectInvalidRequest(which only blocks#), passes thefullBundleguard (which callsnext()immediately for out-of-scope files), and then lands on the unguarded decode — throwingURIError: URI malformedand crashing the middleware.Relation to #22781
#22781 (my previous contribution, merged by @sapphi-red) added exactly this guard to the
fullBundlebranch:This PR mirrors that identical pattern onto the regular dev-server (non-
fullBundle) path, which is the symmetric sibling left unguarded:decodeURIComponent(fsPathFromId(url))andfsPathFromId(decodeURIComponent(url))are equivalent for any URI whereFS_PREFIX(/@fs/) is not itself percent-encoded (it cannot be, since it comes fromcleanUrl). Valid input is byte-identical to the previous behaviour; only the throwing path changes.Test
Added a test in
packages/vite/src/node/server/middlewares/__tests__/indexHtml.spec.tsthat wraps the Vite middleware stack in a real HTTP server and asserts thatGET /%c0.htmlreturns a non-500 response (falls through to 404 rather than crashing).