summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_poplib.py
diff options
context:
space:
mode:
authorJamie Davis <davisjam@vt.edu>2018-03-04 05:33:32 (GMT)
committerBenjamin Peterson <benjamin@python.org>2018-03-04 05:33:32 (GMT)
commit0e6c8ee2358a2e23117501826c008842acb835ac (patch)
treee430b938abc09f1a5bb9613f11c60e575a9e2865 /Lib/test/test_poplib.py
parent13cfd57dcf58485d6242fd8118c6ea4b10e29aab (diff)
downloadcpython-0e6c8ee2358a2e23117501826c008842acb835ac.zip
cpython-0e6c8ee2358a2e23117501826c008842acb835ac.tar.gz
cpython-0e6c8ee2358a2e23117501826c008842acb835ac.tar.bz2
bpo-32981: Fix catastrophic backtracking vulns (#5955)
* Prevent low-grade poplib REDOS (CVE-2018-1060) The regex to test a mail server's timestamp is susceptible to catastrophic backtracking on long evil responses from the server. Happily, the maximum length of malicious inputs is 2K thanks to a limit introduced in the fix for CVE-2013-1752. A 2KB evil response from the mail server would result in small slowdowns (milliseconds vs. microseconds) accumulated over many apop calls. This is a potential DOS vector via accumulated slowdowns. Replace it with a similar non-vulnerable regex. The new regex is RFC compliant. The old regex was non-compliant in edge cases. * Prevent difflib REDOS (CVE-2018-1061) The default regex for IS_LINE_JUNK is susceptible to catastrophic backtracking. This is a potential DOS vector. Replace it with an equivalent non-vulnerable regex. Also introduce unit and REDOS tests for difflib. Co-authored-by: Tim Peters <tim.peters@gmail.com> Co-authored-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Lib/test/test_poplib.py')
-rw-r--r--Lib/test/test_poplib.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py
index fd0db79..bf568bd 100644
--- a/Lib/test/test_poplib.py
+++ b/Lib/test/test_poplib.py
@@ -308,9 +308,19 @@ class TestPOP3Class(TestCase):
def test_rpop(self):
self.assertOK(self.client.rpop('foo'))
- def test_apop(self):
+ def test_apop_normal(self):
self.assertOK(self.client.apop('foo', 'dummypassword'))
+ def test_apop_REDOS(self):
+ # Replace welcome with very long evil welcome.
+ # NB The upper bound on welcome length is currently 2048.
+ # At this length, evil input makes each apop call take
+ # on the order of milliseconds instead of microseconds.
+ evil_welcome = b'+OK' + (b'<' * 1000000)
+ with test_support.swap_attr(self.client, 'welcome', evil_welcome):
+ # The evil welcome is invalid, so apop should throw.
+ self.assertRaises(poplib.error_proto, self.client.apop, 'a', 'kb')
+
def test_top(self):
expected = (b'+OK 116 bytes',
[b'From: postmaster@python.org', b'Content-Type: text/plain',