Conversation
…espace The embedded-header check required the colon to follow the name directly, so a line like "cc : injected@example.com" slipped past it. Receivers are lenient about that whitespace and read the line as a header anyway, which is the bypass reported in the issue. R. David Murray described the fix on the issue: allow whitespace before the colon in the pattern. Continuation lines are unaffected, since they begin with whitespace and the pattern still requires a non-blank first character after the newline.
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.
Closes #76787.
@bitdancer said what to do here in 2022 and nobody picked it up:
The check is
_embedded_header = re.compile(r'\n[^ \t]+:'), which needs the colon right after the name. Receivers are not that strict — as @bitdancer put it earlier in the thread, most MTAs and MUAs try hard to guess what a non-compliant message meant, and a space before the colon is one of the things they forgive. So the injected line gets read as a header at the far end while the guard here sees nothing. On main:The pattern is now
r'\n[^ \t]+[ \t]*:'.Folding is untouched. A continuation line begins with whitespace, and the pattern still requires a non-blank character straight after the newline, so
'dummy\n continued here: not a header'goes through as before. There is a test for that alongside the three injected forms, because widening a guard is exactly where you want to know you have not started rejecting valid input../python.exe -m test test_emailis 1,821 passing, andtest_smtplib test_emailtogether 1,906. RevertingLib/email/header.pywhile keeping the tests fails.The issue is public and has been since 2018, with the proof of concept attached to the original report and the fix described openly on the thread, so I am treating it as an ordinary bug rather than something for security@python.org. main only.