Skip to content

gh-143921: Narrow the control character check in imaplib commands#153067

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:imaplib-narrow-ctl-check
Jul 5, 2026
Merged

gh-143921: Narrow the control character check in imaplib commands#153067
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:imaplib-narrow-ctl-check

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jul 5, 2026

Copy link
Copy Markdown
Member

The broad check rejected all of 0x00-0x1F and 0x7F, but only NUL, CR and LF are actually unsafe (command injection / binary truncation).
TAB and other control characters are valid QUOTED-CHARs per RFC 3501 and RFC 9051, and a mailbox name containing them can be returned by the server via LIST, so the client must be able to send it back in SELECT, STATUS, etc. Rejecting such names made imaplib unable to operate on a folder that legitimately exists.
Now that GH-152703 restored argument quoting, such arguments are sent as quoted strings; only NUL, CR and LF (which cannot be represented even in a quoted string) are still rejected.

🤖 Generated with Claude Code

Only NUL, CR and LF are rejected now.  Other control characters are
valid in quoted strings and can occur in mailbox names returned by
the server, so they are now accepted and sent quoted.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@serhiy-storchaka serhiy-storchaka requested a review from a team as a code owner July 5, 2026 06:27
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 5, 2026
@serhiy-storchaka serhiy-storchaka merged commit d0921ef into python:main Jul 5, 2026
59 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jul 5, 2026

Copy link
Copy Markdown

GH-153135 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 5, 2026
serhiy-storchaka added a commit that referenced this pull request Jul 5, 2026
…nds (GH-153067) (GH-153135)

Only NUL, CR and LF are rejected now.  Other control characters are
valid in quoted strings and can occur in mailbox names returned by
the server, so they are now accepted and sent quoted.
(cherry picked from commit d0921ef)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants