Skip to content

Conversation

@sethmlarson
Copy link
Contributor

@sethmlarson sethmlarson commented Jan 16, 2026

- No forced space to indent,
- use almost the same code as the `bare-quoted-string`
block above, handle nested comments and escaped parenthesis
in addition
e.g. with a 40 characters length policy, the below
`((loremipsum)(loremipsum)(loremipsum)(loremipsum))<spy@example.org>`

should not be folded to
`((loremipsum)(loremipsum)(loremipsum)\n(loremipsum))<spy@example.org>`

but should rather stay
`((loremipsum)(loremipsum)(loremipsum)(loremipsum))<spy@example.org>`

to prevent to add a new line not starting with a space / with no
indentation
To test a whitespace between two nested comments leads to a
new line with one space indentation on folding
@sethmlarson sethmlarson force-pushed the email-preserve-parens-when-folding-comments branch from 3a9b2c7 to 8ad0fdb Compare January 16, 2026 20:45
@sethmlarson sethmlarson added type-security A security issue stdlib Standard Library Python modules in the Lib/ directory topic-email labels Jan 16, 2026
@Yhg1s Yhg1s added needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jan 19, 2026
@Yhg1s Yhg1s enabled auto-merge (squash) January 19, 2026 12:15
@Yhg1s Yhg1s merged commit 17d1490 into python:main Jan 19, 2026
50 checks passed
@miss-islington-app
Copy link

Thanks @sethmlarson for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11, 3.12, 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2026
…H-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490aa97bd6b98a42b1a9b324ead84e7fd8a2)

Co-authored-by: Seth Michael Larson <seth@python.org>
Co-authored-by: Denis Ledoux <dle@odoo.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2026
…H-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson <seth@python.org>
Co-authored-by: Denis Ledoux <dle@odoo.com>
@bedevere-app
Copy link

bedevere-app bot commented Jan 19, 2026

GH-144034 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Jan 19, 2026
@bedevere-app
Copy link

bedevere-app bot commented Jan 19, 2026

GH-144035 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jan 19, 2026
@miss-islington-app
Copy link

Sorry, @sethmlarson and @Yhg1s, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 17d1490aa97bd6b98a42b1a9b324ead84e7fd8a2 3.10

@bedevere-app
Copy link

bedevere-app bot commented Jan 19, 2026

GH-144036 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Jan 19, 2026
@bedevere-app
Copy link

bedevere-app bot commented Jan 19, 2026

GH-144037 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label Jan 19, 2026
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2026
…H-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson <seth@python.org>
Co-authored-by: Denis Ledoux <dle@odoo.com>
@sethmlarson sethmlarson added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jan 19, 2026
@miss-islington-app
Copy link

Thanks @sethmlarson for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @sethmlarson for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @sethmlarson for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @sethmlarson for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2026
…H-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson <seth@python.org>
Co-authored-by: Denis Ledoux <dle@odoo.com>
@sethmlarson sethmlarson removed needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jan 19, 2026
@sethmlarson sethmlarson deleted the email-preserve-parens-when-folding-comments branch January 19, 2026 16:55
@miss-islington-app
Copy link

Sorry @sethmlarson and @Yhg1s, I had trouble completing the backport.
Please retry by removing and re-adding the "needs backport to 3.12" label.
Please backport backport using cherry_picker on the command line.

cherry_picker 17d1490aa97bd6b98a42b1a9b324ead84e7fd8a2 3.12

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2026
…H-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson <seth@python.org>
Co-authored-by: Denis Ledoux <dle@odoo.com>
@miss-islington-app
Copy link

Sorry @sethmlarson and @Yhg1s, I had trouble completing the backport.
Please retry by removing and re-adding the "needs backport to 3.14" label.
Please backport backport using cherry_picker on the command line.

cherry_picker 17d1490aa97bd6b98a42b1a9b324ead84e7fd8a2 3.14

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2026
…H-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson <seth@python.org>
Co-authored-by: Denis Ledoux <dle@odoo.com>
@miss-islington-app
Copy link

Sorry @sethmlarson and @Yhg1s, I had trouble completing the backport.
Please retry by removing and re-adding the "needs backport to 3.13" label.
Please backport backport using cherry_picker on the command line.

cherry_picker 17d1490aa97bd6b98a42b1a9b324ead84e7fd8a2 3.13

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2026
…H-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson <seth@python.org>
Co-authored-by: Denis Ledoux <dle@odoo.com>
@miss-islington-app
Copy link

Sorry @sethmlarson and @Yhg1s, I had trouble completing the backport.
Please retry by removing and re-adding the "needs backport to 3.11" label.
Please backport backport using cherry_picker on the command line.

cherry_picker 17d1490aa97bd6b98a42b1a9b324ead84e7fd8a2 3.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.10 only security fixes stdlib Standard Library Python modules in the Lib/ directory topic-email type-security A security issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants