Skip to content

email.utils.formataddr does not reject CR and LF in address parts #150479

Description

@metsw24-max

email.headerregistry.Address rejects CR and LF in its arguments (Lib/email/headerregistry.py), but the legacy email.utils.formataddr() passes them straight into the returned header string:

>>> from email.utils import formataddr
>>> formataddr(("Alice\r\nBcc: eve@example.com", "alice@example.com"))
'"Alice\r\nBcc: eve@example.com" <alice@example.com>'
>>> formataddr(("Alice", "alice@example.com\r\nSubject: spoofed"))
'Alice <alice@example.com\r\nSubject: spoofed>'

formataddr() is documented as producing a value suitable for a From/To/Cc header and is often used to build header strings directly, so it should reject CR/LF the same way Address does.

Linked PRs

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-emailtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions