René's URL Explorer Experiment


Title: EmailMessage objects break when folding malformed header · Issue #132105 · python/cpython · GitHub

Open Graph Title: EmailMessage objects break when folding malformed header · Issue #132105 · python/cpython

X Title: EmailMessage objects break when folding malformed header · Issue #132105 · python/cpython

Description: Bug report Bug description: In certain cases, with EmailMessage objects, encoded headers can fold with double line endings, causing breakage of flattened message objects, making messages display improperly in email clients and rendering ...

Open Graph Description: Bug report Bug description: In certain cases, with EmailMessage objects, encoded headers can fold with double line endings, causing breakage of flattened message objects, making messages display im...

X Description: Bug report Bug description: In certain cases, with EmailMessage objects, encoded headers can fold with double line endings, causing breakage of flattened message objects, making messages display im...

Opengraph URL: https://github.com/python/cpython/issues/132105

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"EmailMessage objects break when folding malformed header","articleBody":"# Bug report\n\n### Bug description:\n\nIn certain cases, with `EmailMessage` objects, encoded headers can fold with double line endings, causing breakage of flattened message objects, making messages display improperly in email clients and rendering attachments inaccessible.\n\nPython3.11.11 does not exhibit this behaviour. But numerous other Python versions eg `3.11.9`, `3.12.x`, `3.10.x` and `3.9.x` are affected by the bug.\n\nThe specific malformation is where:\n* a header is long\n* a header is presented with its value presented as RFC 2047 UTF8 base64\n* when decoded, the header's payload ends with a newline `\\n`\n\nAn example of this:\n```\nSubject: =?utf-8?B?Vm9pY2Vib3ggRmlybWE6IFRlc3QtTmFjaHJpY2h0IHVtIDEwOjAzOjM1IDA0LjA0LjI1IC0gQUdGRU8gRVMgNTIyIElUIHVwIC0gc3RhaXBzbmV0Cg==?=\n```\n\nHere is a test script which reproduces the problem on many/most recent Python versions:\n```python\n#!/usr/bin/env python3\n\"\"\"\nReproduces a bug with flattening email headers whose encoded payloads end in a newline\n\"\"\"\nimport sys\nfrom email import policy\nfrom email.parser import Parser, BytesParser, HeaderParser\n\nsampleRaw = \"\"\"Date: Fri, 04 Apr 2025 10:03:35 +0200\\r\nFrom: sender@foo.com\\r\nSubject: =?utf-8?B?Vm9pY2Vib3ggRmlybWE6IFRlc3QtTmFjaHJpY2h0IHVtIDEwOjAzOjM1IDA0LjA0LjI1IC0gQUdGRU8gRVMgNTIyIElUIHVwIC0gc3RhaXBzbmV0Cg==?=\\r\nMIME-Version: 1.0\\r\nContent-Type: multipart/mixed;\\r\n boundary=\"235711131719\"\\r\nTo: recipient@bar.com\\r\n\\r\nThis is a multi-part message in MIME format.\\r\n--235711131719\\r\nContent-Type: text/plain; charset=UTF-8; format=flowed\\r\nContent-Transfer-Encoding: 7bit\\r\n\\r\nThis is readable part of the body\\r\n--235711131719--\\r\n\\r\n\"\"\"\n\nmessageObj = Parser(policy=policy.default).parsestr(sampleRaw)\n\nprint(sys.version)\nprint(\"--------\")\nprint(messageObj.as_string())\nprint(\"--------\")\n```\n\nPython 3.11.11 flattens the message correctly. Here is an excerpt in/around the `Subject:` header:\n```\nFrom: sender@foo.com\nSubject: Voicebox Firma: Test-Nachricht um 10:03:35 04.04.25 - AGFEO ES 522 IT\n up - =?utf-8?q?staipsnet=0A?=\nMIME-Version: 1.0\nContent-Type: multipart/mixed;\n boundary=\"235711131719\"\nTo: recipient@bar.com\n\nThis is a multi-part message in MIME format.\n```\nAs can be seen here, the header has been re-wrapped to quoted-printable (which is fine), the embedded newline is present in the encoded payload, but when the header is folded out, it has only the one line ending. Great.\n\nBut other pythons I've tested with come up with:\n```\nFrom: sender@foo.com\nSubject: Voicebox Firma: Test-Nachricht um 10:03:35 04.04.25 - AGFEO ES 522 IT\n up - staipsnet\n\nMIME-Version: 1.0\nContent-Type: multipart/mixed;\n boundary=\"235711131719\"\nTo: recipient@bar.com\n\nThis is a multi-part message in MIME format.\n--235711131719\nContent-Type: text/plain; charset=UTF-8; format=flowed\nContent-Transfer-Encoding: 7bit\n\nThis is readable part of the body\n```\nNote the blank line after `Subject:`.\n\nWhen messages folded and delivered with this breakage are delivered, MTAs will often add `Content-Type: text/plain` because the headers after Subject have been lost into the body.\n\nThe recipient of the above message will see this formatted as plain text in their viewing pane:\n```\nMIME-Version: 1.0\nContent-Type: multipart/mixed;\n boundary=\"235711131719\"\nTo: recipient@bar.com\n\nThis is a multi-part message in MIME format.\n--235711131719\nContent-Type: text/plain; charset=UTF-8; format=flowed\nContent-Transfer-Encoding: 7bit\n\nThis is readable part of the body\n```\nIf there were any attachments, their encoded representations will appear after that as gibberish strings, and the mail client won't indicate an attachment is present.\n\nThis has potentially serious security implications. If an email delivery chain has python stdlib-based mail processing at or near the end, a carefully structured malicious header can \n- evade sanitisation\n- nullify and/or replace headers added upstream in the chain\n- inject malicious extra headers and MIME-encoded context which may cause subsequent handling steps, and/or the final MUA, to be hijacked for exploit attempts.\n\n\nWorkaround for me has been to subclass a policy, and implement a `_fold()` method to get the parent class' folding, then `.rstrip()` it, then add `\"\\r\\n\"` to the end.\n\n\n\n\n\n### CPython versions tested on:\n\n3.12\n\n### Operating systems tested on:\n\nLinux","author":{"url":"https://github.com/davidmcnabnz","@type":"Person","name":"davidmcnabnz"},"datePublished":"2025-04-05T01:42:19Z","url":"https://github.com/python/cpython/issues/132105"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:20b9c065-9c1e-b521-276e-77edae9d12d7
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDB60:4D1C6:2B3B9CB:3B10EDD:6B00589D
html-safe-nonce73e6ddff37d1a10ac99390090b86bf03f880c2e975e86d1a83a0965d44cd3745
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQjYwOjREMUM2OjJCM0I5Q0I6M0IxMEVERDo2QjAwNTg5RCIsInZpc2l0b3JfaWQiOiI3NTEwMjYwOTIwNzE5OTk2NDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac4ea51b31e29e35764c86dae6510bf7a30641ee48ebc8b5ed533e6a9237508df8
hovercard-subject-tagissue:2973726664
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/132105/issue_layout
twitter:imagehttps://opengraph.githubassets.com/292d8c5667ec72e77ca350a6c26da2f121ebaf562691ac6d28de14fb7ab9221f/python/cpython/issues/132105
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/292d8c5667ec72e77ca350a6c26da2f121ebaf562691ac6d28de14fb7ab9221f/python/cpython/issues/132105
og:image:altBug report Bug description: In certain cases, with EmailMessage objects, encoded headers can fold with double line endings, causing breakage of flattened message objects, making messages display im...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedavidmcnabnz
hostnamegithub.com
expected-hostnamegithub.com
None29be975efff6507a5d135de9c7d634cf7ff8f0c55222a64386ab3202209aaf73
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseeacd927ba6112e3b01ba99c762bd699a4a4f5df7
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/132105#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F132105
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F132105
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/132105
Reloadhttps://github.com/python/cpython/issues/132105
Reloadhttps://github.com/python/cpython/issues/132105
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/132105
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/132105
EmailMessage objects break when folding malformed headerhttps://github.com/python/cpython/issues/132105#top
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-emailhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-email%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/davidmcnabnz
davidmcnabnzhttps://github.com/davidmcnabnz
on Apr 5, 2025https://github.com/python/cpython/issues/132105#issue-2973726664
davidmcnabnzhttps://github.com/davidmcnabnz
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Apr 5, 2025https://github.com/python/cpython/issues/132105#event-17137846962
skirpichevhttps://github.com/skirpichev
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-emailhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-email%22
on Apr 5, 2025https://github.com/python/cpython/issues/132105#event-17137963871
https://github.com/davidmcnabnz
davidmcnabnzhttps://github.com/davidmcnabnz
on Apr 6, 2025https://github.com/python/cpython/issues/132105#issuecomment-2781196759
https://github.com/rijo7
rijo7https://github.com/rijo7
on Apr 6, 2025https://github.com/python/cpython/issues/132105#issuecomment-2781459651
https://github.com/davidmcnabnz
davidmcnabnzhttps://github.com/davidmcnabnz
on Apr 10, 2025https://github.com/python/cpython/issues/132105#issuecomment-2792174983
@rijo7https://github.com/rijo7
https://github.com/medmunds
medmundshttps://github.com/medmunds
on May 6, 2025https://github.com/python/cpython/issues/132105#issuecomment-2855535784
@davidmcnabnzhttps://github.com/davidmcnabnz
#122754https://github.com/python/cpython/pull/122754
#122233https://github.com/python/cpython/pull/122233
https://github.com/tonghuaroot
tonghuaroothttps://github.com/tonghuaroot
on Jun 23, 2026https://github.com/python/cpython/issues/132105#issuecomment-4777614660
@davidmcnabnzhttps://github.com/davidmcnabnz
@medmundshttps://github.com/medmunds
gh-121650https://github.com/python/cpython/issues/121650
#122233https://github.com/python/cpython/pull/122233
CVE-2024-6923https://github.com/advisories/GHSA-87qc-q3w7-7m8w
#122233https://github.com/python/cpython/pull/122233
#122754https://github.com/python/cpython/pull/122754
#122608https://github.com/python/cpython/pull/122608
https://github.com/medmunds
medmundshttps://github.com/medmunds
on Jun 23, 2026https://github.com/python/cpython/issues/132105#issuecomment-4784056239
@tonghuaroothttps://github.com/tonghuaroot
gh-121650https://github.com/python/cpython/issues/121650
hugovkhttps://github.com/hugovk
duplicatehttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Aduplicate
email.policy.default - gotcha with re-using parsed headers with embedded newlines #121650https://github.com/python/cpython/issues/121650
on Oct 29, 2026https://github.com/python/cpython/issues/132105#event-34584709396
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/132105
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/132105
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-emailhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-email%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.