Skip to content

Reject control characters in IMAP commands #143921

Activity

  1. added a commit that references this issue on Jan 16, 2026
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Jan 16, 2026
  3. bitdancer commented on Jan 16, 2026

    @bitdancer
    Member

    If there is someone familiar enough with IMAP to review this, please do.

    Otherwise I need a bit more detail, since I'm not that familiar with IMAP, and both the RFC and the code are quite complex. Can you cover how the RFC makes non-printables (other than space) illegal in 'commands', and how that relates to the imaplib implementation of _command? I scanned the RFC and code for a bit, and while my gut says your PR is correct, it isn't obvious by any means.

  4. added a commit that references this issue on Jan 20, 2026
  5. added a commit that references this issue on Feb 3, 2026
  6. 13 remaining items

  7. serhiy-storchaka commented on Jul 3, 2026

    @serhiy-storchaka
    Member

    I think the broad check should be reverted and replaced with a narrow one.

    It rejects all of 0x00–0x1F and 0x7F, but only CR, LF, and NUL are actually unsafe (command injection / binary truncation). TAB and the other control characters are valid QUOTED_CHARs per RFC 9051, and such a mailbox name can be returned by the server via LIST, so the client must be able to send it back — as a quoted string — in SELECT, STATUS, etc. Rejecting it with ValueError makes imaplib unable to operate on a folder that legitimately exists, which is a regression.

    The narrow check keeps the security fix without over-rejecting:

    _control_chars = re.compile(b'[\x00\r\n]')

    This is only the safety guard, though. Handling characters that are legal but need quoting — space, ", \, as well as TAB — requires proper argument quoting, which is what #152703 (gh-40038) restores. Without that, those arguments still aren't sent correctly; a blanket control-character reject is the wrong layer to solve this at.

  8. added 4 commits that reference this issue on Jul 5, 2026
  9. caruccio commented on Sep 17, 2026

    @caruccio

    Hi there. Is this fix planned for 3.10, 3.11 or 3.12?

  10. added a commit that references this issue on Oct 1, 2026
  11. added a commit that references this issue on Oct 5, 2026
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/ directorytype-securityA security issue

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions