Repository navigation
Conversation
email.utils.parseaddr() and getaddresses(), in strict mode (the default),
silently dropped a comment embedded inside a dot-atom and spliced the
surrounding atoms together (e.g. 'u(comment)ser@d.com' -> 'user@d.com').
Strict mode now returns ('', '') for such addresses; strict=False keeps
the historical lenient behavior.
Signed-off-by: ZHOU Zijun <zijunzhou03222@gmail.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.
Fixes #159475.
Summary
email.utils.parseaddr()andgetaddresses(), in strict mode (the defaultsince the CVE-2023-27043 fix), still silently drop a comment that is embedded
inside a dot-atom and splice the surrounding atoms together:
email.headerregistry.Address('u(comment)ser@d.com')rejects this input(local-part is not dot-atom / quoted-string / obs-local-part), so a caller that
validates or authorizes with
parseaddrand then hands the original string toa strict component gets a subject mismatch — the same class as CVE-2019-11340
(Matrix Sydent) and the motivation behind CVE-2023-27043.
Change
Add an internal
_inline_commentflag to the lenientAddrlistClassparser inLib/email/_parseaddr.py. It is set when a comment is consumed immediatelybefore another atom inside an addr-spec (or its domain) — exactly the position
where the comment would be silently dropped and two atoms spliced. In strict
mode,
parseaddr/getaddressesnow return('', '')/[('', '')]whenthe flag is set.
strict=Falsekeeps the historical lenient behavior unchanged.parentheses) are unchanged.
Why it matters
parseaddr/getaddressesis not deprecated and is still widely used insecurity-sensitive paths: CPython's own
smtplib, Django, Sentry, Odoo (whichexplicitly opts into
strict=False), and Ansible all call it. "Legacy" heremeans a compat API rather than an abandoned one. The minimal ask is that strict
mode fail closed instead of silently inventing an addr-spec that no strict
reader would accept.
Tests
Added
test_parseaddr_inline_commenttoLib/test/test_email/test_email.py,covering local-part and domain splicing, empty and nested comments,
getaddressesparity, and the still-accepted leading / trailing / quoted cases.