fix: decode escaped field names, not just filenames - #1473
Open
MohammedAlkindi wants to merge 1 commit into
Open
fix: decode escaped field names, not just filenames#1473MohammedAlkindi wants to merge 1 commit into
MohammedAlkindi wants to merge 1 commit into
Conversation
The WHATWG serialisation rule that decodeFormDataName reverses covers field names as well as filenames, as its own comment says, but it was only applied to filename. Busboy leaves the escapes in place, so req.body keys, file.fieldname and err.field all carried the raw %22, %0D and %0A.
The practical effect is that upload.single('a"b') rejects a browser upload from an input named a"b with LIMIT_UNEXPECTED_FILE, and the only way to accept it was to register the escaped spelling.
fieldNameSize is measured on the name as it arrived, since decoding shortens it.
kilisamemarisaaa
left a comment
Contributor
There was a problem hiding this comment.
Verified on Windows with Node 24.12.0 at 26c5a6b: npm test passes (138 passing, 2 pending) and standard lint is clean. The new field-name cases cover percent-encoding decode, literal percent preservation, expected-file matching, and decoded limit errors; existing filename and storage/cleanup coverage remains green. I found no correctness issues.
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.
decodeFormDataNamereverses the WHATWG escaping of%0A,%0Dand%22, and its own comment says the rule covers "field names and filenames". It was only applied tofilename. Busboy leaves both escaped, soreq.bodykeys,file.fieldnameanderr.fieldall carried the raw escapes.Measured against the unpatched tree:
So an
<input name='a"b' type=file>upload is rejected outright, and the only way to accept it was to register the escaped spelling.fieldNameSizenow measures the name as it arrived, since decoding shortens it and measuring the decoded form would quietly weaken that limit.decodeFormDataNameitself is untouched, so the deliberate "neverdecodeURIComponent" property still holds and50%.pdfstays intact.Six new tests, two of which pass before the change as controls (a name with no escapes, and a literal percent sign). The other four fail on the unpatched tree. Each of the two call sites was neutered independently to confirm both are load-bearing.
Suite: 132 passing before, 138 after, 2 pending, no failures either side;
standardexits 0.This is the field-name half of #1421, which fixed the filename half.