Fix TypeError from unconditional strict= kwarg on old Python patch releases#162
Open
mkilijanek wants to merge 1 commit into
Open
Fix TypeError from unconditional strict= kwarg on old Python patch releases#162mkilijanek wants to merge 1 commit into
mkilijanek wants to merge 1 commit into
Conversation
…support it email.utils.getaddresses() only gained the strict= keyword as part of the CVE-2023-27043 hardening, and it was backported to patch releases >=3.10.15, >=3.11.10, >=3.12.6 rather than to every release across those minor versions. get_addresses() passed strict=True unconditionally, so on an older patch release within an otherwise supported minor version this raised: TypeError: getaddresses() got an unexpected keyword argument 'strict' for every address header, breaking mail-parser entirely on those interpreters. email.utils.supports_strict_parsing is the stdlib's own capability flag for this hardening; get_addresses() now checks it and only passes strict= when the running interpreter actually supports it, falling back to the pre-hardening call signature otherwise. The existing regex fallback for RFC-non-compliant display names, and every other code path, is unaffected on interpreters that do support strict parsing (the common case in CI and production). Reported via a downstream consumer, parsedmarc: domainaware/parsedmarc#808
This was referenced Jul 13, 2026
mkilijanek
added a commit
to mkilijanek/parsedmarc-core
that referenced
this pull request
Jul 14, 2026
mailparser.parse_from_string() unconditionally passes strict=True to email.utils.getaddresses(), which only exists on Python patch releases >=3.10.15, >=3.11.10, >=3.12.6 (the CVE-2023-27043 backports). On an older patch release within an otherwise-supported minor version, this raises TypeError: getaddresses() got an unexpected keyword argument 'strict' -- and parsedmarc's existing broad exception handlers silently turned that into a generic "invalid report" error, with nothing indicating the real cause was an outdated Python patch release rather than a bad report. _mailparser_parse_from_string() now catches this specific TypeError, gated on email.utils.supports_strict_parsing so unrelated TypeErrors still pass through untouched, and re-raises as EmailParserError naming the required Python versions. The existing catch-alls in parse_report_email() and parse_failure_report() already embed the inner exception's message into their own, so the clearer text reaches operators with no other control-flow changes. The real fix belongs upstream in mail-parser: filed as SpamScope/mail-parser#162 (open, not yet merged as of this commit). This is a workaround for parsedmarc users in the meantime. Fixes domainaware#808. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
027b747 to
8fc164d
Compare
|
Someone beat you to it. #161 |
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
get_addresses()unconditionally passesstrict=Truetoemail.utils.getaddresses(). That keyword only exists as part of the CVE-2023-27043 hardening, and CPython backported it to patch releases>=3.10.15,>=3.11.10,>=3.12.6— not to every release within those minor versions. On an older patch release (e.g. 3.11.3), callingget_addresses()for any address header raises:which breaks address parsing entirely on that interpreter (and, transitively, any project depending on mail-parser to parse address headers on such a host).
Reported via a downstream consumer (parsedmarc): domainaware/parsedmarc#808
Fix
email.utils.supports_strict_parsingis the stdlib's own capability flag for this hardening (present andTrueon the patched releases above).get_addresses()now checks it and only passesstrict=Truewhen the running interpreter actually supports it, falling back to the pre-hardening call signature (getaddresses([raw_header])) otherwise. Everything else — the existing regex fallback for RFC-non-compliant display names,Headerhandling, etc. — is unaffected on interpreters that do support strict parsing, which is the common case in CI and production.Test plan
test_get_addresses_omits_strict_kwarg_when_unsupportedandtest_get_addresses_uses_strict_kwarg_when_supportedtotests/test_utils.py, both mockingemail.utils.getaddresses/email.utils.supports_strict_parsingto assert the exact call signature used in each case.uv run pytest tests/— 212 passed (full suite, including theoutlookextra).uv run ruff check ./uv run ruff format --check .— clean.pre-commit run --all-fileson the touched files — all hooks pass, including thepyrighthook.