Repository navigation
fix(server): handle malformed URI in unbundled indexHtml middleware - #23616
Open
maxymlyskov wants to merge 2 commits into
Open
maxymlyskov wants to merge 2 commits into
maxymlyskov wants to merge 2 commits into
Conversation
An .html request with a bad percent escape, such as /%E0%A4%A.html, reaches the non-bundled branch of viteIndexHtmlMiddleware, where decodeURIComponent throws a URIError. The middleware is async and connect only catches synchronous errors, so the rejection is unhandled and the dev and preview servers exit with code 1. Guard the decode like the bundled-dev branch of the same function does since vitejs#22781, and fall through to next(). The added test gets no response on main (it times out with the unhandled URIError) and passes with this change.
The node-22 job failed in playground/hmr (circular imports poll timeout), which this change does not touch.
maxymlyskov
force-pushed
the
fix/malformed-uri-in-indexhtml-middleware
branch
from
October 21, 2026 21:13
97efd82 to
853bd37
Compare
This branch has not been deployed
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.
An
.htmlrequest with a broken percent escape crashes the dev server and the preview server. In the unbundled branch,viteIndexHtmlMiddlewarecallsdecodeURIComponenton the url without a guard. The middleware is async and connect only catches synchronous throws, so theURIErrorbecomes an unhandled rejection and Node exits.With vite packed from main and installed into a small app (Node 22.12):
With this change both return 404 for the bad url and keep serving
/.The bundled-dev branch of the same function has guarded this since #22781. This wraps the two decodes in the unbundled branch the same way and falls through to
next(). The decode order stays as it is.#21313 and #22789 tried this before. On #21313 the process didn't exit; with an installed vite on current main it does, as above. #22789 decoded before
fsPathFromId, which changes the order; this keeps it.The test in
indexHtml.spec.tsrequests/%E0%A4%A.htmland/@fs/%E0%A4%A.html, expects a 404 for each, then a 200 for/. On main it times out with the unhandledURIError.AI usage: I used AI to check my reasoning and look things up, and had it generate several candidate fixes. I compared them and picked this one myself.