Skip to content

gh-150479: reject CR and LF in email.utils.formataddr#150480

Open
metsw24-max wants to merge 1 commit into
python:mainfrom
metsw24-max:reject-crlf-in-formataddr
Open

gh-150479: reject CR and LF in email.utils.formataddr#150480
metsw24-max wants to merge 1 commit into
python:mainfrom
metsw24-max:reject-crlf-in-formataddr

Conversation

@metsw24-max
Copy link
Copy Markdown

@metsw24-max metsw24-max commented May 26, 2026

formataddr() passes CR and LF in the name or address straight into the
returned header string, so a crafted display name or address can inject
extra headers. headerregistry.Address already rejects these; do the same here.

@metsw24-max metsw24-max requested a review from a team as a code owner May 26, 2026 15:44
@python-cla-bot
Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

Copy link
Copy Markdown
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formataddr is meant to be the reverse of parseaddr which has a strict/non-strict form. I would suggest you to do the same, namely with a strict parameter. We should allow non-strict forms to be allowed, even with CR/LF.

On the other hand, it may be assumed that this is a GIGO case where formataddr should only be called on an RFC-compliant pair, not an arbitrary one.

Note: please update the docs to mention the change with a versionchanged directive.

@bitdancer what do you want to do for this one? I think it would make sense to retain some strictness as for the other helpers. This is the only helper that doesn't have a strict parameter.

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 26, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be put in the comfy chair!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants