Skip to content

fix(metadata): fold every line boundary when writing headers - #1356

Merged
henryiii merged 3 commits into
pypa:mainfrom
rajath201:metadata-header-fold
Aug 1, 2026
Merged

fix(metadata): fold every line boundary when writing headers#1356
henryiii merged 3 commits into
pypa:mainfrom
rajath201:metadata-header-fold

Conversation

@rajath201

Copy link
Copy Markdown
Contributor

header_store_parse folds \n into a continuation line, but the email package ends a header line on every boundary str.splitlines recognizes. A value carrying a bare \r, \v, \f, \x1c-\x1e, \x85, U+2028 or U+2029 goes out unfolded, so Metadata.from_raw({"author": "a\rRequires-Dist: evil"}).as_rfc822() writes an author header and then a Requires-Dist header that was never on the metadata object. Values arriving from pyproject.toml or a JSON payload reach this path directly, since on the parse side those bytes are already line breaks.

Folding on the whole boundary set keeps this in one place instead of a per-field check across summary, author, keywords, classifier and project-url, and \n output stays byte for byte what it was. Summary still needs its own check to remain one line, so it now tests the same set.

@henryiii
henryiii force-pushed the metadata-header-fold branch from 366fe21 to 7b31392 Compare July 31, 2026 19:30
henryiii added 2 commits July 31, 2026 16:24
The header injection only happens on CPython releases without the
CVE-2024-6923 fix; patched releases raise HeaderWriteError for a bare
carriage return instead. Reword the comment and changelog to say so, add
the PR reference, and test the fold through Metadata.as_rfc822() and the
exotic-boundary rejection in Summary validation.

Assisted-by: ClaudeCode:claude-fable-5
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
@henryiii

Copy link
Copy Markdown
Contributor

On newer CPythons, this is an error, it's only on CPythons older than about 2024 (CVE-2024-6923) that this would cause a security issue on. I've pushed an update to clarify the wording and added a test.

@henryiii
henryiii merged commit 2d873eb into pypa:main Aug 1, 2026
127 of 129 checks passed
Sign up for free to 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.

2 participants