Skip to content

[3.12] gh-143921: Reject unsafe IMAP command characters - #162135

Open
saakshaat-singh wants to merge 1 commit into
python:3.12from
saakshaat-singh:ssingh/312-imap-command-validation-v2
Open

saakshaat-singh wants to merge 1 commit into
python:3.12from
saakshaat-singh:ssingh/312-imap-command-validation-v2

Conversation

@saakshaat-singh

Copy link
Copy Markdown

Before this PR

Python 3.12.16 permits NUL, CR, and LF in IMAP command arguments. If untrusted input reaches an argument, CR/LF can introduce additional protocol commands (CVE-2025-15366).

After this PR

==COMMIT_MSG==
==COMMIT_MSG==

This backports the corrected argument validation from GH-153287, rejecting NUL, CR, and LF before sending a command. Other control characters remain permitted in explicitly quoted arguments, and message literals retain their existing contents.

The change also adapts the pending literal-state correction from GH-162017. A rejected APPEND must discard its pending message; otherwise a subsequent command can transmit content that the caller was told had been rejected. The literal is captured and cleared before command validation.

Upstream context

The original backport decision cited compatibility concerns. The narrower validation subsequently landed in 3.13 and 3.14. This PR requests a maintainer decision on applying that narrower guard to 3.12, together with the state-cleanup safeguard; the latter remains under review on main.

Validation

The focused test_imaplib suite completed 110 tests, with 6 skipped, using the changed sources with the released conda-forge Python 3.12.16 interpreter. Coverage includes string and bytes arguments, rejection before sending, legal quoted controls, successful APPEND literals, and command reuse after rejected APPEND calls. The new cleanup regression fails against the previous backport for all six mailbox variants and invalid flags. CPython's configured pre-commit checks passed.

Review and next steps

  1. Obtain protocol and state-management review from the python/email-team code owners, using GH-143921 and GH-162010 for the existing discussions.
  2. Resolve the main-branch follow-up and the 3.12 backport decision with the maintainers and release manager, then complete the CLA and CI requirements before merge.
  3. If review remains idle, follow the documented review process: after one month, follow up on the issue; after another week without a response, ask in the Core Development Discourse category.

Refs #143921, #162010

Testing

Possible downsides?

Applications that previously supplied NUL, CR, or LF in command arguments will now receive ValueError. The pending state-cleanup change requires upstream review alongside the backport.

Are Docs needed?

@python-cla-bot

Copy link
Copy Markdown

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

CLA not signed

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.

1 participant