Skip to content

IMAP4.login_plain() does not reject NUL in a memoryview credential #159631

Open

Description

@fedonman

Bug description:

IMAP4.login_plain() raises ValueError for a user name or password that contains NUL, but not when the value is a memoryview or another bytes-like object other than bytes and bytearray. The NUL is then sent in the PLAIN message as an extra field separator.

import imaplib

class IMAP4(imaplib.IMAP4):
    def __init__(self):
        pass
    def authenticate(self, mechanism, authobject):
        print(authobject(b''))

IMAP4().login_plain(memoryview(b'user\0admin'), b'password')

Output:

b'\x00user\x00admin\x00password'

Expected: ValueError: NUL is not allowed in user name or password, as with login_plain(b'user\0admin', b'password').

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    on Oct 17, 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/ directorytopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions