Repository navigation
[3.12] gh-143921: Reject unsafe IMAP command characters - #162135
Open
saakshaat-singh wants to merge 1 commit into
Open
saakshaat-singh wants to merge 1 commit into
saakshaat-singh wants to merge 1 commit into
Conversation
|
The following commit authors need to sign the Contributor License Agreement: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_imaplibsuite 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
python/email-teamcode owners, using GH-143921 and GH-162010 for the existing discussions.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?