Skip to content

Conversation

@sethmlarson
Copy link
Contributor

@sethmlarsonsethmlarson 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))<[email protected]>` should not be folded to `((loremipsum)(loremipsum)(loremipsum)\n(loremipsum))<[email protected]>` but should rather stay `((loremipsum)(loremipsum)(loremipsum)(loremipsum))<[email protected]>` 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
@sethmlarsonsethmlarsonforce-pushed the email-preserve-parens-when-folding-comments branch from 3a9b2c7 to 8ad0fdbCompareJanuary 16, 2026 20:45
@sethmlarsonsethmlarson added type-security A security issue stdlib Standard Library Python modules in the Lib/ directory topic-email labels Jan 16, 2026
@Yhg1sYhg1s 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
@Yhg1sYhg1s enabled auto-merge (squash) January 19, 2026 12:15
@Yhg1sYhg1s merged commit 17d1490 into python:mainJan 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 <[email protected]> Co-authored-by: Denis Ledoux <[email protected]>
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 <[email protected]> Co-authored-by: Denis Ledoux <[email protected]>
@bedevere-app
Copy link

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

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

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

@bedevere-appbedevere-appbot 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

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

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

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

@bedevere-appbedevere-appbot 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 <[email protected]> Co-authored-by: Denis Ledoux <[email protected]>
@sethmlarsonsethmlarson 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 <[email protected]> Co-authored-by: Denis Ledoux <[email protected]>
@sethmlarsonsethmlarson 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
@sethmlarsonsethmlarson 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 <[email protected]> Co-authored-by: Denis Ledoux <[email protected]>
@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 <[email protected]> Co-authored-by: Denis Ledoux <[email protected]>
@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 <[email protected]> Co-authored-by: Denis Ledoux <[email protected]>
@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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.10only security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-emailtype-securityA security issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@sethmlarson@bitdancer@Yhg1s@beledouxdenis