Repository navigation
fix(mime-node): escape backslash and quote in Content-Type name parameter - #1837
Merged
andris9 merged 1 commit intoAug 4, 2026
Conversation
…eter The `name` parameter of the Content-Type header was wrapped in a quoted-string without escaping backslash or double-quote characters, unlike the Content-Disposition `filename` parameter on the same node (which is built via buildHeaderValue). An attachment filename ending in a backslash produced `name="foo\"` -- an unterminated quoted-string, since the trailing backslash escapes the closing quote. A lenient MIME parser can consume past the line boundary and merge or hide the following headers (Content-Transfer-Encoding, Content-Disposition), enabling header/parameter smuggling. Backslashes elsewhere in the name also silently corrupted the received filename. Escape `\` and `"` as quoted-pairs before wrapping, matching the Content-Disposition path. Adds regression tests.
andris9
added a commit
that referenced
this pull request
Aug 4, 2026
…stringify Follow-up to #1837, no behaviour change. The escaping added there is exactly what buildHeaderValue already does for filename=, so use the same call rather than a second hand-rolled escaper that can drift from it. The tests that came with the fix asserted with indexOf, and filename= ends in name=, so both assertions matched inside the Content-Disposition line instead. One of the two passed against the unpatched code. Pin the full header line with anchored regexes like the neighbouring filename tests do, and add a case for a quote in the filename, which never reaches the quoting step because encodeWords turns the whole value into a mime word first. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013bYRfSN3MWR2St9WLuPeXA
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.
Summary
The
nameparameter of theContent-Typeheader is wrapped in a quoted-string without escaping\or", unlike theContent-Dispositionfilenameparameter built on the same node (which goes throughbuildHeaderValue→JSON.stringifyand is escaped correctly).An attachment whose filename ends in a backslash produces an unterminated quoted-string, because the trailing backslash escapes the closing quote:
A lenient MIME parser continues consuming past the line boundary until it finds the next
", merging or hiding the following headers (Content-Transfer-Encoding,Content-Disposition) — i.e. header/parameter smuggling. A backslash elsewhere in the name (e.g.a\b.txt) is also read as a quoted-pair by a conforming parser, silently corrupting the received filename.Reproduction
Fix
Escape
\and"as quoted-pairs before wrapping thenamevalue in quotes, matching what theContent-Dispositionpath already does:The change is a no-op for the existing non-ASCII (RFC 2047 encoded-word) path, since encoded words contain no
\or".Tests
Adds two regression tests in
test/mime-node/mime-node-test.jsasserting thename=parameter is emitted with the same escaping asfilename=. Both fail without the fix and pass with it.npm run lint— cleannpm run format:check— changed files cleannpm test— full suite passing (615 tests)