fix(fetch): prefer filename* over filename in multipart form-data#5068
Merged
mcollina merged 1 commit intonodejs:mainfrom Apr 19, 2026
Merged
Conversation
When a multipart/form-data Content-Disposition header carries both the legacy `filename` parameter and the RFC 5987 extended `filename*` parameter, RFC 5987 §4.1 requires the extended form to win regardless of the order the two parameters appear in. The previous implementation simply assigned the latest value seen, so a `filename` appearing after `filename*` would clobber the percent-decoded extended value. Track whether `filename` was sourced from the extended form and ignore any subsequent legacy `filename` so the extended value is always used when both are present. Adds regression tests for the original bug payload, filename-only, filename*-only, both orders of the two attributes, and a percent-encoded UTF-8 value. Closes: nodejs#4661
KhafraDev
approved these changes
Apr 19, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5068 +/- ##
==========================================
- Coverage 93.10% 93.10% -0.01%
==========================================
Files 110 110
Lines 35788 35799 +11
==========================================
+ Hits 33322 33331 +9
- Misses 2466 2468 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mcollina
pushed a commit
that referenced
this pull request
Apr 29, 2026
) (cherry picked from commit f6c5dda)
Merged
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.
This relates to...
Closes #4661
Rationale
When a
multipart/form-dataContent-Dispositionheader carries both the legacyfilenameparameter and the RFC 5987 extendedfilename*parameter, RFC 5987 §4.1 requires the extended form to take precedence regardless of the order the two parameters appear in:The previous parser simply assigned
filenameto whichever attribute was seen last, so a legacyfilenameappearing afterfilename*would clobber the percent-decoded extended value. The original bug report (#4661) used a payload generated by the C# HTTP client which emits both attributes in that order — pre PR #4662 the parser threwexpected CRLF; after PR #4662 it parses successfully but ignores thefilename*value.This change tracks whether
filenamewas sourced from the extended form and refuses to overwrite it with a subsequent legacyfilename, so the extended value is always used when both are present.The maintainer follow-up on the issue specifically requested:
All three are added in
test/busboy/issue-4661.js, plus tests for both attribute orderings and a percent-encoded UTF-8 value (%E2%82%AC→€).Changes
Features
N/A
Bug Fixes
lib/web/fetch/formdata-parser.js—parseContentDispositionAttributenow reports whether the attribute used the extended (*) notation, and thecontent-dispositionheader handler keeps the extendedfilename*value even when a legacyfilenamefollows it.test/busboy/issue-4661.js— regression coverage for the original payload, filename-only, filename*-only, both orderings, and percent-encoded UTF-8.Breaking Changes and Deprecations
None.
Status