Skip to content

gh-162010: Drop pending literal on rejected imaplib.APPEND commands - #162017

Open
jhaabhijeet864 wants to merge 1 commit into
python:mainfrom
jhaabhijeet864:gh-162010
Open

jhaabhijeet864 wants to merge 1 commit into
python:mainfrom
jhaabhijeet864:gh-162010

Conversation

@jhaabhijeet864

@jhaabhijeet864 jhaabhijeet864 commented Nov 14, 2026 •

Copy link
Copy Markdown

Fixes #162010. Follow-up to gh-143921 / CVE-2025-15366.

Problem

When IMAP4.append() is invoked, it stores the message payload in self.literal before calling _command('APPEND', ...). If an argument contains control characters (such as NUL, CR, or LF), _command() raises a ValueError("NUL, CR and LF not allowed in commands") while building the command line.

Because this check happens before self.literal is ingested and cleared, self.literal remained pending on the instance. When the caller subsequently issues any other command (e.g., noop()), _command() attaches the leftover literal to that command. The server unexpectedly receives NOOP {size} followed by the message bytes, leading to client connection abortion and unintended transmission of aborted message data.

Solution

Ingest and clear self.literal into local scope at the start of _command(). This ensures that any validation failure or exception occurring prior to transmission unconditionally clears self.literal and prevents literal state leakage across commands.

Testing

  • Added regression test test_control_characters_append_literal in Lib/test/test_imaplib.py.
  • Verified with the full test_imaplib test suite (268 passed, 0 failures).
  • Verified with the reproduction script from the issue.

@jhaabhijeet864
jhaabhijeet864 requested a review from a team as a code owner November 14, 2026 20:03
@python-cla-bot

python-cla-bot Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

…ands

When IMAP4.append() is called, it stores the message payload in self.literal and calls _command('APPEND', ...). Following pythongh-143921 (CVE-2025-15366), if any argument contains control characters (NUL, CR, or LF), _command() raises ValueError before popping and clearing self.literal. This left self.literal pending on the client instance, attaching itself as an unexpected literal to whatever command was executed next (such as NOOP).

Ingest and clear self.literal into local scope at the start of _command(), guaranteeing that any exception occurring prior to transmission drops the literal immediately and prevents session corruption or data leakage.
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.

imaplib: a rejected APPEND leaves its message pending as the literal of the next command

1 participant