Skip to content

Commit bd51456

Browse files
committed
more RFC links and explanation.
1 parent cf3a20e commit bd51456

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

Lib/encodings/idna.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,15 @@ def ToASCII(label):
101101
raise UnicodeError("label empty or too long")
102102

103103
def ToUnicode(label):
104-
if len(label) > 1000:
104+
if len(label) > 1024:
105105
# Protection from https://github.com/python/cpython/issues/98433.
106106
# https://datatracker.ietf.org/doc/html/rfc5894#section-6
107107
# doesn't specify a label size limit prior to NAMEPREP. But having
108108
# one makes practical sense.
109109
# This leaves ample room for nameprep() to remove Nothing characters
110-
# while still preventing us from wasting CPU decoding a big thing
111-
# that'll just hit the actual <= 63 length limit in Step 6.
110+
# per https://www.rfc-editor.org/rfc/rfc3454#section-3.1 while still
111+
# preventing us from wasting time decoding a big thing that'll just
112+
# hit the actual <= 63 length limit in Step 6.
112113
raise UnicodeError("label way too long")
113114
# Step 1: Check for ASCII
114115
if isinstance(label, bytes):

Lib/test/test_codecs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ def test_builtin_encode(self):
15541554

15551555
def test_builtin_decode_length_limit(self):
15561556
with self.assertRaises(UnicodeError) as ctx:
1557-
(b"xn--016c"+b"a"*1010).decode("idna")
1557+
(b"xn--016c"+b"a"*1100).decode("idna")
15581558
self.assertIn("way too long", str(ctx.exception))
15591559
with self.assertRaises(UnicodeError) as ctx:
15601560
(b"xn--016c"+b"a"*70).decode("idna")

Misc/NEWS.d/next/Security/2022-11-04-09-29-36.gh-issue-98433.l76c5G.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ such as :mod:`urllib` http ``3xx`` redirects potentially allow for an attacker
66
to supply such a name.
77

88
Individual labels within an IDNA encoded DNS name will now raise an error early
9-
during IDNA decoding if they are longer than 1000 encoded characters given that
10-
each decoded DNS label must be 63 or fewer characters. Only an application
11-
presenting a suspicious hostname value consisting primarily of "Nothing"
12-
characters to be removed would run into of this new limit. See :rfc:`5894`
13-
section 6 and :rfc:`3491`.
9+
during IDNA decoding if they are longer than 1024 unicode characters given that
10+
each decoded DNS label must be 63 or fewer characters and the entire decoded
11+
DNS name is limited to 255. Only an application presenting a hostname or label
12+
consisting primarily of :rfc:`3454` section 3.1 "Nothing" characters to be
13+
removed would run into of this new limit. See also :rfc:`5894` section 6 and
14+
:rfc:`3491`.

0 commit comments

Comments
 (0)