Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% set ver2 = '.'.join(version.split('.')[0:2]) %}
{% set ver2nd = ''.join(version.split('.')[0:2]) %}
{% set ver3nd = ''.join(version.split('.')[0:3]) %}
{% set build_number = 0 %}
{% set build_number = 1 %}

# this makes the linter happy
{% set channel_targets = channel_targets or 'conda-forge main' %}
Expand Down Expand Up @@ -72,6 +72,8 @@ source:
- patches/0021-Override-configure-LIBFFI.patch
- patches/0022-Allow-linking-ncursesw-panelw-on-macOS-if-available.patch
- patches/0023-Do-not-define-pid_t-as-it-might-conflict-with-the-ac.patch
- patches/0024-Reject-control-characters-in-POP3-commands.patch
- patches/0025-Reject-NUL-CR-and-LF-in-IMAP-command-arguments.patch

build:
number: {{ build_number }}
Expand Down Expand Up @@ -234,6 +236,7 @@ outputs:
- tests/cython/*
- tests/prefix-replacement/*
- run_test.py
- tests/test_mail_commands.py
commands:
- echo on # [win]
- set # [win]
Expand Down Expand Up @@ -281,6 +284,7 @@ outputs:
- popd
- popd
- python run_test.py
- python tests/test_mail_commands.py
- test ! -f default.profraw # [osx]
# Test workaround for https://github.com/conda/conda/issues/10969
- test -d "$PREFIX/lib/python3.1/site-packages" # [unix]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
From 396a25a04b30f50c4623999aee3f59a652f4a429 Mon Sep 17 00:00:00 2001
From: Saakshaat Singh <97133528+saakshaat-singh@users.noreply.github.com>
Date: Mon, 16 Nov 2026 14:01:37 -0500
Subject: [PATCH 24/25] fix

---
Lib/poplib.py | 2 ++
Lib/test/test_poplib.py | 8 ++++++++
.../2026-11-16-19-00-00.gh-issue-143923.pop312.rst | 1 +
3 files changed, 11 insertions(+)
create mode 100644 Misc/NEWS.d/next/Security/2026-11-16-19-00-00.gh-issue-143923.pop312.rst

diff --git a/Lib/poplib.py b/Lib/poplib.py
index 9eb662d..5c83522 100644
--- a/Lib/poplib.py
+++ b/Lib/poplib.py
@@ -122,6 +122,8 @@ def _putline(self, line):
def _putcmd(self, line):
if self._debugging: print('*cmd*', repr(line))
line = bytes(line, self.encoding)
+ if re.search(b'[\x00-\x1F\x7F]', line):
+ raise ValueError('Control characters not allowed in commands')
self._putline(line)


diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py
index f1ebbea..46d788a 100644
--- a/Lib/test/test_poplib.py
+++ b/Lib/test/test_poplib.py
@@ -395,6 +395,14 @@ def test_quit(self):
self.assertIsNone(self.client.sock)
self.assertIsNone(self.client.file)

+ def test_control_characters(self):
+ for char in test_support.control_characters_c0():
+ with self.subTest(char=char):
+ with self.assertRaises(ValueError):
+ self.client.user(f'user{char}')
+ with self.assertRaises(ValueError):
+ self.client.pass_(f'{char}pass')
+
@requires_ssl
def test_stls_capa(self):
capa = self.client.capa()
diff --git a/Misc/NEWS.d/next/Security/2026-11-16-19-00-00.gh-issue-143923.pop312.rst b/Misc/NEWS.d/next/Security/2026-11-16-19-00-00.gh-issue-143923.pop312.rst
new file mode 100644
index 0000000..18379d8
--- /dev/null
+++ b/Misc/NEWS.d/next/Security/2026-11-16-19-00-00.gh-issue-143923.pop312.rst
@@ -0,0 +1 @@
+Reject control characters in POP3 commands (CVE-2025-15367).
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
From 5efe71be702d7849972a3db940430b2069ff4dd0 Mon Sep 17 00:00:00 2001
From: Saakshaat Singh <97133528+saakshaat-singh@users.noreply.github.com>
Date: Mon, 16 Nov 2026 14:34:35 -0500
Subject: [PATCH 25/25] fix

---
Lib/imaplib.py | 10 ++-
Lib/test/test_imaplib.py | 61 +++++++++++++++++++
...11-16-19-00-00.gh-issue-143921.imap312.rst | 3 +
3 files changed, 71 insertions(+), 3 deletions(-)
create mode 100644 Misc/NEWS.d/next/Security/2026-11-16-19-00-00.gh-issue-143921.imap312.rst

diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index e337fe6..23503f0 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -132,6 +132,7 @@
# We compile these in _mode_xxx.
_Literal = br'.*{(?P<size>\d+)}$'
_Untagged_status = br'\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?'
+_control_chars = re.compile(b'[\x00\r\n]')



@@ -972,8 +973,11 @@ def _check_bye(self):

def _command(self, name, *args):

- if self.state not in Commands[name]:
+ literal = self.literal
+ if literal is not None:
self.literal = None
+
+ if self.state not in Commands[name]:
raise self.error("command %s illegal in state %s, "
"only allowed in states %s" %
(name, self.state,
@@ -994,11 +998,11 @@ def _command(self, name, *args):
if arg is None: continue
if isinstance(arg, str):
arg = bytes(arg, self._encoding)
+ if _control_chars.search(arg):
+ raise ValueError("NUL, CR and LF not allowed in commands")
data = data + b' ' + arg

- literal = self.literal
if literal is not None:
- self.literal = None
if type(literal) is type(self._command):
literator = literal
else:
diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py
index 4429a90..de6cd23 100644
--- a/Lib/test/test_imaplib.py
+++ b/Lib/test/test_imaplib.py
@@ -537,6 +537,67 @@ def test_unselect(self):
self.assertEqual(data[0], b'Returned to authenticated state. (Success)')
self.assertEqual(client.state, 'AUTH')

+ def test_command_control_characters(self):
+ client, _ = self._setup(SimpleIMAPHandler)
+ with mock.patch.object(client, 'send') as send:
+ for char in '\0\r\n':
+ for arg in (f'a{char}b', f'a{char}b'.encode('ascii')):
+ with self.subTest(arg=arg):
+ with self.assertRaisesRegex(ValueError,
+ 'NUL, CR and LF not allowed in commands'):
+ client._command('LOGIN', arg, 'password')
+ send.assert_not_called()
+
+ def test_quoted_control_characters(self):
+ client, _ = self._setup(SimpleIMAPHandler)
+ for char in support.control_characters_c0():
+ if char in '\0\r\n':
+ continue
+ with self.subTest(char=char):
+ arg = f'"a{char}b"'
+ with mock.patch.object(client, 'send') as send:
+ tag = client._command('LOGIN', 'user', arg)
+ send.assert_called_once_with(
+ tag + b' LOGIN user ' + arg.encode('ascii') + b'\r\n')
+
+ def test_rejected_append_clears_literal(self):
+ client, _ = self._setup(SimpleIMAPHandler)
+ client.login('user', 'pass')
+ for char in '\0\r\n':
+ for mailbox in (f'a{char}b', f'a{char}b'.encode('ascii')):
+ with self.subTest(mailbox=mailbox):
+ with self.assertRaises(ValueError):
+ client.append(mailbox, None, None, b'message')
+ self.assertIsNone(client.literal)
+ typ, _ = client.select('INBOX')
+ self.assertEqual(typ, 'OK')
+ with self.subTest(case='flags'):
+ with self.assertRaises(ValueError):
+ client.append('INBOX', '(\\Flag\n)', None, b'message')
+ self.assertIsNone(client.literal)
+ typ, _ = client.select('INBOX')
+ self.assertEqual(typ, 'OK')
+ client.logout()
+ with self.subTest(case='illegal_state'):
+ with self.assertRaises(imaplib.IMAP4.error):
+ client.append('INBOX', None, None, b'message')
+ self.assertIsNone(client.literal)
+
+ def test_append_literal_crlf(self):
+ class AppendServer(SimpleIMAPHandler):
+ def cmd_APPEND(self, tag, args):
+ size = int(args[-1].strip('{}'))
+ self._send_textline('+')
+ self.server.response = self.rfile.read(size + 2)
+ self._send_tagged(tag, 'OK', 'APPEND completed')
+
+ client, server = self._setup(AppendServer)
+ client.login('user', 'pass')
+ message = b'Subject: test\r\n\r\nbody\tend'
+ typ, _ = client.append('INBOX', None, None, message)
+ self.assertEqual(typ, 'OK')
+ self.assertEqual(server.response, message + b'\r\n')
+

class NewIMAPTests(NewIMAPTestsMixin, unittest.TestCase):
imap_class = imaplib.IMAP4
diff --git a/Misc/NEWS.d/next/Security/2026-11-16-19-00-00.gh-issue-143921.imap312.rst b/Misc/NEWS.d/next/Security/2026-11-16-19-00-00.gh-issue-143921.imap312.rst
new file mode 100644
index 0000000..aa95dfe
--- /dev/null
+++ b/Misc/NEWS.d/next/Security/2026-11-16-19-00-00.gh-issue-143921.imap312.rst
@@ -0,0 +1,3 @@
+Reject NUL, CR and LF in IMAP command arguments (CVE-2025-15366).
+Other control characters in quoted strings and literal data remain allowed.
+Discard pending message literals when a command is rejected.
47 changes: 47 additions & 0 deletions recipe/tests/test_mail_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import imaplib
import poplib
import unittest
from unittest.mock import Mock


class MailCommandTests(unittest.TestCase):
def test_pop3_controls(self):
client = Mock(_debugging=0, encoding='ascii')
for code in (*range(32), 127):
with self.subTest(code=code):
with self.assertRaises(ValueError):
poplib.POP3._putcmd(client, f'USER user{chr(code)}')
client._putline.assert_not_called()
poplib.POP3._putcmd(client, 'USER user')
client._putline.assert_called_once_with(b'USER user')

def test_imap_controls(self):
client = Mock(state='NONAUTH', literal=None, untagged_responses={},
is_readonly=False, _encoding='ascii', debug=0)
client._new_tag.return_value = b'T0'
for char in '\0\r\n':
for arg in (f'user{char}', f'user{char}'.encode('ascii')):
with self.subTest(arg=arg):
with self.assertRaises(ValueError):
imaplib.IMAP4._command(client, 'LOGIN', arg, 'password')
client.send.assert_not_called()
imaplib.IMAP4._command(client, 'LOGIN', 'user', '"pass\tword"')
client.send.assert_called_once_with(b'T0 LOGIN user "pass\tword"\r\n')

def test_rejected_imap_literal(self):
client = Mock(state='AUTH', untagged_responses={},
is_readonly=False, _encoding='ascii', debug=0)
client._new_tag.return_value = b'T0'
for char in '\0\r\n':
with self.subTest(char=char):
client.literal = b'message'
with self.assertRaises(ValueError):
imaplib.IMAP4._command(client, 'APPEND', f'a{char}b')
self.assertIsNone(client.literal)
client.send.assert_not_called()
imaplib.IMAP4._command(client, 'NOOP')
client.send.assert_called_once_with(b'T0 NOOP\r\n')


if __name__ == '__main__':
unittest.main()
Loading