-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
fix(server): improve malformed URL handling in middlewares #20830
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
sapphi-red
merged 6 commits into
main
from
copilot/fix-e015e0b0-d873-40ae-8455-585bb96a3369
Sep 25, 2025
Merged
fix(server): improve malformed URL handling in middlewares #20830
sapphi-red
merged 6 commits into
main
from
copilot/fix-e015e0b0-d873-40ae-8455-585bb96a3369
Sep 25, 2025
Conversation
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
…n middlewares Co-authored-by: sapphi-red <[email protected]>
Co-authored-by: sapphi-red <[email protected]>
decodeURIIfPossible
to src/node/utils.ts
and use that in viteServeStaticMiddleware
and serveRawFsMiddleware
to fix @vitejs/vite/issues/20829 . Make sure to add an e2e test in playground/html
. Add a test for @vitejs/vite/pull/19397 as well.decodeURIIfPossible
to utils and fix malformed URL handling in middlewares
Copilot finished work on behalf of
sapphi-red
September 24, 2025 02:02
sapphi-red
approved these changes
Sep 24, 2025
I pushed a commit that I think makes the malformed uri warning a little better:
Previously there wasn't any url logged to debug. |
decodeURIIfPossible
to utils and fix malformed URL handling in middlewares
bluwy
approved these changes
Sep 24, 2025
Nice, thanks! |
1 task
renovate bot
added a commit
to andrei-picus-tink/auto-renovate
that referenced
this pull request
Oct 3, 2025
| datasource | package | from | to | | ---------- | ------- | ----- | ----- | | npm | vite | 7.1.7 | 7.1.8 | ## [v7.1.8](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-718-2025-10-02-small) ##### Bug Fixes - **css:** improve url escape characters handling ([#20847](vitejs/vite#20847)) ([24a61a3](vitejs/vite@24a61a3)) - **deps:** update all non-major dependencies ([#20855](vitejs/vite#20855)) ([788a183](vitejs/vite@788a183)) - **deps:** update artichokie to 0.4.2 ([#20864](vitejs/vite#20864)) ([e670799](vitejs/vite@e670799)) - **dev:** skip JS responses for document requests ([#20866](vitejs/vite#20866)) ([6bc6c4d](vitejs/vite@6bc6c4d)) - **glob:** fix HMR for array patterns with exclusions ([#20872](vitejs/vite#20872)) ([63e040f](vitejs/vite@63e040f)) - keep ids for virtual modules as-is ([#20808](vitejs/vite#20808)) ([d4eca98](vitejs/vite@d4eca98)) - **server:** drain stdin when not interactive ([#20837](vitejs/vite#20837)) ([bb950e9](vitejs/vite@bb950e9)) - **server:** improve malformed URL handling in middlewares ([#20830](vitejs/vite#20830)) ([d65a983](vitejs/vite@d65a983)) ##### Documentation - **create-vite:** provide deno example ([#20747](vitejs/vite#20747)) ([fdb758a](vitejs/vite@fdb758a)) ##### Miscellaneous Chores - **deps:** update rolldown-related dependencies ([#20810](vitejs/vite#20810)) ([ea68a88](vitejs/vite@ea68a88)) - **deps:** update rolldown-related dependencies ([#20854](vitejs/vite#20854)) ([4dd06fd](vitejs/vite@4dd06fd)) - update url of `create-react-app` license ([#20865](vitejs/vite#20865)) ([166a178](vitejs/vite@166a178))
renovate bot
added a commit
to andrei-picus-tink/auto-renovate
that referenced
this pull request
Oct 3, 2025
| datasource | package | from | to | | ---------- | ------- | ----- | ----- | | npm | vite | 7.1.7 | 7.1.9 | ## [v7.1.9](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-719-2025-10-03-small) ##### Reverts - **server:** drain stdin when not interactive ([#20885](vitejs/vite#20885)) ([12d72b0](vitejs/vite@12d72b0)) ## [v7.1.8](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-718-2025-10-02-small) ##### Bug Fixes - **css:** improve url escape characters handling ([#20847](vitejs/vite#20847)) ([24a61a3](vitejs/vite@24a61a3)) - **deps:** update all non-major dependencies ([#20855](vitejs/vite#20855)) ([788a183](vitejs/vite@788a183)) - **deps:** update artichokie to 0.4.2 ([#20864](vitejs/vite#20864)) ([e670799](vitejs/vite@e670799)) - **dev:** skip JS responses for document requests ([#20866](vitejs/vite#20866)) ([6bc6c4d](vitejs/vite@6bc6c4d)) - **glob:** fix HMR for array patterns with exclusions ([#20872](vitejs/vite#20872)) ([63e040f](vitejs/vite@63e040f)) - keep ids for virtual modules as-is ([#20808](vitejs/vite#20808)) ([d4eca98](vitejs/vite@d4eca98)) - **server:** drain stdin when not interactive ([#20837](vitejs/vite#20837)) ([bb950e9](vitejs/vite@bb950e9)) - **server:** improve malformed URL handling in middlewares ([#20830](vitejs/vite#20830)) ([d65a983](vitejs/vite@d65a983)) ##### Documentation - **create-vite:** provide deno example ([#20747](vitejs/vite#20747)) ([fdb758a](vitejs/vite@fdb758a)) ##### Miscellaneous Chores - **deps:** update rolldown-related dependencies ([#20810](vitejs/vite#20810)) ([ea68a88](vitejs/vite@ea68a88)) - **deps:** update rolldown-related dependencies ([#20854](vitejs/vite#20854)) ([4dd06fd](vitejs/vite@4dd06fd)) - update url of `create-react-app` license ([#20865](vitejs/vite#20865)) ([166a178](vitejs/vite@166a178))
renovate bot
added a commit
to andrei-picus-tink/auto-renovate
that referenced
this pull request
Oct 4, 2025
| datasource | package | from | to | | ---------- | ------- | ----- | ----- | | npm | vite | 7.1.7 | 7.1.9 | ## [v7.1.9](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-719-2025-10-03-small) ##### Reverts - **server:** drain stdin when not interactive ([#20885](vitejs/vite#20885)) ([12d72b0](vitejs/vite@12d72b0)) ## [v7.1.8](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-718-2025-10-02-small) ##### Bug Fixes - **css:** improve url escape characters handling ([#20847](vitejs/vite#20847)) ([24a61a3](vitejs/vite@24a61a3)) - **deps:** update all non-major dependencies ([#20855](vitejs/vite#20855)) ([788a183](vitejs/vite@788a183)) - **deps:** update artichokie to 0.4.2 ([#20864](vitejs/vite#20864)) ([e670799](vitejs/vite@e670799)) - **dev:** skip JS responses for document requests ([#20866](vitejs/vite#20866)) ([6bc6c4d](vitejs/vite@6bc6c4d)) - **glob:** fix HMR for array patterns with exclusions ([#20872](vitejs/vite#20872)) ([63e040f](vitejs/vite@63e040f)) - keep ids for virtual modules as-is ([#20808](vitejs/vite#20808)) ([d4eca98](vitejs/vite@d4eca98)) - **server:** drain stdin when not interactive ([#20837](vitejs/vite#20837)) ([bb950e9](vitejs/vite@bb950e9)) - **server:** improve malformed URL handling in middlewares ([#20830](vitejs/vite#20830)) ([d65a983](vitejs/vite@d65a983)) ##### Documentation - **create-vite:** provide deno example ([#20747](vitejs/vite#20747)) ([fdb758a](vitejs/vite@fdb758a)) ##### Miscellaneous Chores - **deps:** update rolldown-related dependencies ([#20810](vitejs/vite#20810)) ([ea68a88](vitejs/vite@ea68a88)) - **deps:** update rolldown-related dependencies ([#20854](vitejs/vite#20854)) ([4dd06fd](vitejs/vite@4dd06fd)) - update url of `create-react-app` license ([#20865](vitejs/vite#20865)) ([166a178](vitejs/vite@166a178))
renovate bot
added a commit
to andrei-picus-tink/auto-renovate
that referenced
this pull request
Oct 5, 2025
| datasource | package | from | to | | ---------- | ------- | ----- | ----- | | npm | vite | 7.1.7 | 7.1.9 | ## [v7.1.9](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-719-2025-10-03-small) ##### Reverts - **server:** drain stdin when not interactive ([#20885](vitejs/vite#20885)) ([12d72b0](vitejs/vite@12d72b0)) ## [v7.1.8](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-718-2025-10-02-small) ##### Bug Fixes - **css:** improve url escape characters handling ([#20847](vitejs/vite#20847)) ([24a61a3](vitejs/vite@24a61a3)) - **deps:** update all non-major dependencies ([#20855](vitejs/vite#20855)) ([788a183](vitejs/vite@788a183)) - **deps:** update artichokie to 0.4.2 ([#20864](vitejs/vite#20864)) ([e670799](vitejs/vite@e670799)) - **dev:** skip JS responses for document requests ([#20866](vitejs/vite#20866)) ([6bc6c4d](vitejs/vite@6bc6c4d)) - **glob:** fix HMR for array patterns with exclusions ([#20872](vitejs/vite#20872)) ([63e040f](vitejs/vite@63e040f)) - keep ids for virtual modules as-is ([#20808](vitejs/vite#20808)) ([d4eca98](vitejs/vite@d4eca98)) - **server:** drain stdin when not interactive ([#20837](vitejs/vite#20837)) ([bb950e9](vitejs/vite@bb950e9)) - **server:** improve malformed URL handling in middlewares ([#20830](vitejs/vite#20830)) ([d65a983](vitejs/vite@d65a983)) ##### Documentation - **create-vite:** provide deno example ([#20747](vitejs/vite#20747)) ([fdb758a](vitejs/vite@fdb758a)) ##### Miscellaneous Chores - **deps:** update rolldown-related dependencies ([#20810](vitejs/vite#20810)) ([ea68a88](vitejs/vite@ea68a88)) - **deps:** update rolldown-related dependencies ([#20854](vitejs/vite#20854)) ([4dd06fd](vitejs/vite@4dd06fd)) - update url of `create-react-app` license ([#20865](vitejs/vite#20865)) ([166a178](vitejs/vite@166a178))
renovate bot
added a commit
to andrei-picus-tink/auto-renovate
that referenced
this pull request
Oct 6, 2025
| datasource | package | from | to | | ---------- | ------- | ----- | ----- | | npm | vite | 7.1.7 | 7.1.9 | ## [v7.1.9](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-719-2025-10-03-small) ##### Reverts - **server:** drain stdin when not interactive ([#20885](vitejs/vite#20885)) ([12d72b0](vitejs/vite@12d72b0)) ## [v7.1.8](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-718-2025-10-02-small) ##### Bug Fixes - **css:** improve url escape characters handling ([#20847](vitejs/vite#20847)) ([24a61a3](vitejs/vite@24a61a3)) - **deps:** update all non-major dependencies ([#20855](vitejs/vite#20855)) ([788a183](vitejs/vite@788a183)) - **deps:** update artichokie to 0.4.2 ([#20864](vitejs/vite#20864)) ([e670799](vitejs/vite@e670799)) - **dev:** skip JS responses for document requests ([#20866](vitejs/vite#20866)) ([6bc6c4d](vitejs/vite@6bc6c4d)) - **glob:** fix HMR for array patterns with exclusions ([#20872](vitejs/vite#20872)) ([63e040f](vitejs/vite@63e040f)) - keep ids for virtual modules as-is ([#20808](vitejs/vite#20808)) ([d4eca98](vitejs/vite@d4eca98)) - **server:** drain stdin when not interactive ([#20837](vitejs/vite#20837)) ([bb950e9](vitejs/vite@bb950e9)) - **server:** improve malformed URL handling in middlewares ([#20830](vitejs/vite#20830)) ([d65a983](vitejs/vite@d65a983)) ##### Documentation - **create-vite:** provide deno example ([#20747](vitejs/vite#20747)) ([fdb758a](vitejs/vite@fdb758a)) ##### Miscellaneous Chores - **deps:** update rolldown-related dependencies ([#20810](vitejs/vite#20810)) ([ea68a88](vitejs/vite@ea68a88)) - **deps:** update rolldown-related dependencies ([#20854](vitejs/vite#20854)) ([4dd06fd](vitejs/vite@4dd06fd)) - update url of `create-react-app` license ([#20865](vitejs/vite#20865)) ([166a178](vitejs/vite@166a178))
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.
This PR addresses server crashes when encountering malformed URLs in static file serving middleware by centralizing and improving malformed URL handling.
Problem
Vite's development server would crash when encountering malformed URLs, particularly from template engines or user input containing expressions like:
The crash occurred because
decodeURI()
throws an error when given malformed input, causing the entire middleware chain to fail.Solution
Centralized utility function: Moved
decodeURIIfPossible
frompackages/vite/src/node/plugins/html.ts
topackages/vite/src/node/utils.ts
to make it available across the codebase.Fixed static middleware: Updated both
serveStaticMiddleware
andserveRawFsMiddleware
inpackages/vite/src/node/server/middlewares/static.ts
to usedecodeURIIfPossible
instead ofdecodeURI
, gracefully handling malformed URLs by skipping processing rather than crashing.Comprehensive testing: Added E2E tests in
playground/html
that verify the server doesn't crash with various malformed URL patterns.Changes
packages/vite/src/node/utils.ts
: AddeddecodeURIIfPossible
function with JSDocpackages/vite/src/node/plugins/html.ts
: Removed local function, imported from utilspackages/vite/src/node/server/middlewares/static.ts
: Updated both middleware functions to use safe decodingplayground/html/malformed-url.html
: Test page with various malformed URL patternsplayground/html/__tests__/html.spec.ts
: E2E tests for malformed URL handlingplayground/html/vite.config.js
: Added malformed-url.html to build inputsBehavior
When a malformed URL is encountered:
URIError: URI malformed
This fix ensures that user input or template engine expressions in HTML attributes don't crash the development server, improving developer experience and application stability.
Fixes #20829
Related to #19397
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
vite.dev
/home/REDACTED/.cache/playwright-bin/chromium_headless_shell-1187/chrome-linux/headless_shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AvoidUnnecessaryBeforeUnloadCheckSync,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate,AutoDeElevate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --edge-skip-compat-layer-relaunch --enable-automation --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --no-sandbox --disable-setuid-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-RKuUAy --remote-debugging-pipe --no-startup-window
(dns block)workers.cloudflare.com
If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.