File CVE-2022-45061-DoS-by-IDNA-decode.patch of Package python (Revision 7c7532457b948cc36e86ff51d95885bc)
Currently displaying revision 7c7532457b948cc36e86ff51d95885bc , Show latest
89
1
From fa792ddee55dc02c6392842c8194a464339f6f1b Mon Sep 17 00:00:00 2001
2
From: "Miss Islington (bot)"
3
<31488909+miss-islington@users.noreply.github.com>
4
Date: Mon, 7 Nov 2022 18:57:10 -0800
5
Subject: [PATCH] [3.11] gh-98433: Fix quadratic time idna decoding. (GH-99092)
6
(GH-99222)
7
8
There was an unnecessary quadratic loop in idna decoding. This restores
9
the behavior to linear.
10
11
(cherry picked from commit d315722564927c7202dd6e111dc79eaf14240b0d)
12
13
(cherry picked from commit a6f6c3a3d6f2b580f2d87885c9b8a9350ad7bf15)
14
15
Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
16
Co-authored-by: Gregory P. Smith <greg@krypto.org>
17
---
18
Lib/encodings/idna.py | 32 ++++------
19
Lib/test/test_codecs.py | 6 +
20
Misc/NEWS.d/next/Security/2022-11-04-09-29-36.gh-issue-98433.l76c5G.rst | 6 +
21
3 files changed, 27 insertions(+), 17 deletions(-)
22
create mode 100644 Misc/NEWS.d/next/Security/2022-11-04-09-29-36.gh-issue-98433.l76c5G.rst
23
24
--- a/Lib/encodings/idna.py
25
+++ b/Lib/encodings/idna.py
26
27
28
# Check bidi
29
RandAL = map(stringprep.in_table_d1, label)
30
- for c in RandAL:
31
- if c:
32
- # There is a RandAL char in the string. Must perform further
33
- # tests:
34
- # 1) The characters in section 5.8 MUST be prohibited.
35
- # This is table C.8, which was already checked
36
- # 2) If a string contains any RandALCat character, the string
37
- # MUST NOT contain any LCat character.
38
- if filter(stringprep.in_table_d2, label):
39
- raise UnicodeError("Violation of BIDI requirement 2")
40
-
41
- # 3) If a string contains any RandALCat character, a
42
- # RandALCat character MUST be the first character of the
43
- # string, and a RandALCat character MUST be the last
44
- # character of the string.
45
- if not RandAL[0] or not RandAL[-1]:
46
- raise UnicodeError("Violation of BIDI requirement 3")
47
+ if any(RandAL):
48
+ # There is a RandAL char in the string. Must perform further
49
+ # tests:
50
+ # 1) The characters in section 5.8 MUST be prohibited.
51
+ # This is table C.8, which was already checked
52
+ # 2) If a string contains any RandALCat character, the string
53
+ # MUST NOT contain any LCat character.
54
+ if any(stringprep.in_table_d2(x) for x in label):
55
+ raise UnicodeError("Violation of BIDI requirement 2")
56
+ # 3) If a string contains any RandALCat character, a
57
+ # RandALCat character MUST be the first character of the
58
+ # string, and a RandALCat character MUST be the last
59
+ # character of the string.
60
+ if not RandAL[0] or not RandAL[-1]:
61
+ raise UnicodeError("Violation of BIDI requirement 3")
62
63
return label
64
65
--- a/Lib/test/test_codecs.py
66
+++ b/Lib/test/test_codecs.py
67
68
self.assertEqual(u"pyth\xf6n.org".encode("idna"), "xn--pythn-mua.org")
69
self.assertEqual(u"pyth\xf6n.org.".encode("idna"), "xn--pythn-mua.org.")
70
71
+ def test_builtin_decode_length_limit(self):
72
+ with self.assertRaisesRegexp(UnicodeError, "too long"):
73
+ (b"xn--016c"+b"a"*1100).decode("idna")
74
+ with self.assertRaisesRegexp(UnicodeError, "too long"):
75
+ (b"xn--016c"+b"a"*70).decode("idna")
76
+
77
def test_stream(self):
78
import StringIO
79
r = codecs.getreader("idna")(StringIO.StringIO("abc"))
80
--- /dev/null
81
+++ b/Misc/NEWS.d/next/Security/2022-11-04-09-29-36.gh-issue-98433.l76c5G.rst
82
83
+The IDNA codec decoder used on DNS hostnames by :mod:`socket` or :mod:`asyncio`
84
+related name resolution functions no longer involves a quadratic algorithm.
85
+This prevents a potential CPU denial of service if an out-of-spec excessive
86
+length hostname involving bidirectional characters were decoded. Some protocols
87
+such as :mod:`urllib` http ``3xx`` redirects potentially allow for an attacker
88
+to supply such a name.
89