Skip to content

Reject CR/LF in raw multipart part-header fields - #2244

Merged
hyperxpro merged 1 commit into
mainfrom
multipart-header-crlf
Jul 18, 2026
Merged

Reject CR/LF in raw multipart part-header fields#2244
hyperxpro merged 1 commit into
mainfrom
multipart-header-crlf

Conversation

@hyperxpro

Copy link
Copy Markdown
Member

Motivation

MultipartPart writes several part-header fields (dispositionType, contentType, contentTransferEncoding, contentId, and custom header names/values) directly into the multipart header without validating CR/LF characters. This allows header injection or multipart body splitting. While name and filename were hardened in #2203, these fields remained unprotected.

Modification

Add asciiHeaderBytes(String) to reject CR/LF characters before encoding to US-ASCII, and use it for all raw part-header fields. name and filename continue using their existing quoted-string escaping.

Result

Raw part-header fields now fail fast on CR/LF input, preventing header injection while leaving valid values unaffected.

MultipartPart wrote dispositionType, contentType, contentTransferEncoding,
contentId, and custom part-header names and values straight into the header
without validation, while name and filename were already escaped. A CR or LF
in any of these injects extra part headers or splits the body. Reject CR/LF
in these raw fields and fail closed; a legitimate value never contains them.
@hyperxpro
hyperxpro merged commit 1a73921 into mainJul 18, 2026
29 of 30 checks passed
@hyperxpro
hyperxpro deleted the multipart-header-crlf branch July 18, 2026 08:37
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@hyperxpro