]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-143923: Reject control characters in POP3 commands
authorSeth Michael Larson <seth@python.org>
Tue, 20 Jan 2026 20:46:32 +0000 (14:46 -0600)
committerGitHub <noreply@github.com>
Tue, 20 Jan 2026 20:46:32 +0000 (20:46 +0000)
Lib/poplib.py
Lib/test/test_poplib.py
Misc/NEWS.d/next/Security/2026-01-16-11-43-47.gh-issue-143923.DuytMe.rst [new file with mode: 0644]

index 4469bff44b4c45593e1a026c0f6e9cd9c094f76a..b97274c5c32ee63ea1933d657abc730f8468ab2b 100644 (file)
@@ -122,6 +122,8 @@ class POP3:
     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)
 
 
index ef2da97f86734a208b2ef4ae7ee5a8aa0ca303b2..18ca7cb556836e673f5038587835c1eb995bf733 100644 (file)
@@ -17,6 +17,7 @@ from test.support import socket_helper
 from test.support import threading_helper
 from test.support import asynchat
 from test.support import asyncore
+from test.support import control_characters_c0
 
 
 test_support.requires_working_socket(module=True)
@@ -395,6 +396,13 @@ class TestPOP3Class(TestCase):
         self.assertIsNone(self.client.sock)
         self.assertIsNone(self.client.file)
 
+    def test_control_characters(self):
+        for c0 in control_characters_c0():
+            with self.assertRaises(ValueError):
+                self.client.user(f'user{c0}')
+            with self.assertRaises(ValueError):
+                self.client.pass_(f'{c0}pass')
+
     @requires_ssl
     def test_stls_capa(self):
         capa = self.client.capa()
diff --git a/Misc/NEWS.d/next/Security/2026-01-16-11-43-47.gh-issue-143923.DuytMe.rst b/Misc/NEWS.d/next/Security/2026-01-16-11-43-47.gh-issue-143923.DuytMe.rst
new file mode 100644 (file)
index 0000000..3cde4df
--- /dev/null
@@ -0,0 +1 @@
+Reject control characters in POP3 commands.