From 0e6c8ee2358a2e23117501826c008842acb835ac Mon Sep 17 00:00:00 2001 From: Jamie Davis Date: Sun, 4 Mar 2018 00:33:32 -0500 Subject: 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 Co-authored-by: Christian Heimes --- Lib/difflib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/difflib.py') diff --git a/Lib/difflib.py b/Lib/difflib.py index 82964719dc..043a169c28 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -1083,7 +1083,7 @@ class Differ: import re -def IS_LINE_JUNK(line, pat=re.compile(r"\s*#?\s*$").match): +def IS_LINE_JUNK(line, pat=re.compile(r"\s*(?:#\s*)?$").match): r""" Return 1 for ignorable line: iff `line` is blank or contains a single '#'. -- cgit v1.2.1