fix(fetch): treat U+0060 (`) as an HTTP token code point - #5806
Open
Khizarc wants to merge 1 commit into
Open
Conversation
The MIME Sniffing standard defines the HTTP token code points to include the
range U+005E (^) to U+0060 (`), but HTTP_TOKEN_CODEPOINTS covers only ^ and _
and stops one code point short of the backtick.
That produces three distinct wrong results:
parseMIMEType('text/pl`ain') -> 'failure', rather than a valid type
parseMIMEType('text/plain;a`b=1') -> the parameter is silently dropped
serializeAMimeType(x = 'a`b') -> x="a`b", quoted unnecessarily
Node's own MIMEType in node:util accepts the backtick in all three positions,
so undici is the outlier here.
Add the code point to the character class, and cover each of the three
positions with a test.
Signed-off-by: Khizar <Khizarchaudhryy@gmail.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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...
No open issue — found by auditing
lib/web/fetch/data-url.jsagainst the MIME Sniffing standard.Rationale
HTTP token code points are defined as:
HTTP_TOKEN_CODEPOINTScovers^and_but stops one code point short of U+0060:The regex is used in four places, which gives three distinct wrong results:
parseMIMEType('text/pl`ain')'failure'parseMIMEType('text/plain;a`b=1')serializeAMimeTypewith valuea`bx="a`b"x=a`bThe giveaway is that
^and_— the other two code points in that same range — parse fine.Node's own
MIMETypeinnode:utilaccepts the backtick in all three positions, so undici is the outlier within the project:I checked whether #4483 (improve regexes in data-uri.js) introduced this. It did not — that PR moved the
-and added theuflag; the backtick was already missing beforehand. This is long-standing, not a regression.Changes
One code point added to the character class, plus tests covering each of the three affected positions.
Features
N/A
Bug Fixes
U+0060(`) is now treated as an HTTP token code point, so it is accepted in a type, a subtype, and a parameter name, and is not quoted when serializing a parameter value.Breaking Changes and Deprecations
N/A
Status
npm run test:fetchgreen (481 fetch + 28 webidl + 47 busboy, 0 failures);npm run lintclean