Skip to content

Commit 7a0fe23

Browse files
committed
consider wildcard in left most segment only
1 parent a6fba9b commit 7a0fe23

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

Lib/ssl.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class CertificateError(ValueError):
221221
pass
222222

223223

224-
def _dnsname_match(dn, hostname, max_wildcards=1):
224+
def _dnsname_match(dn, hostname):
225225
"""Matching according to RFC 6125, section 6.4.3
226226
227227
http://tools.ietf.org/html/rfc6125#section-6.4.3
@@ -233,13 +233,11 @@ def _dnsname_match(dn, hostname, max_wildcards=1):
233233
leftmost, *remainder = dn.split(r'.')
234234

235235
wildcards = leftmost.count('*')
236-
if wildcards > max_wildcards:
237-
# Issue #17980: avoid denials of service by refusing more
238-
# than one wildcard per fragment. A survey of established
239-
# policy among SSL implementations showed it to be a
240-
# reasonable choice.
236+
if wildcards == 1 and len(leftmost) > 1:
237+
""" Only match wildcard in leftmost segment.
238+
"""
241239
raise CertificateError(
242-
"too many wildcards in certificate DNS name: " + repr(dn))
240+
"wildcard can only be present in left most segment: " + repr(dn))
243241

244242
# speed up common case w/o wildcards
245243
if not wildcards:

Lib/test/test_ssl.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,10 @@ def fail(cert, hostname):
512512
fail(cert, 'Xa.com')
513513
fail(cert, '.a.com')
514514

515-
# only match one left-most wildcard
515+
# only match wildcard in left-most segment
516516
cert = {'subject': ((('commonName', 'f*.com'),),)}
517-
ok(cert, 'foo.com')
518-
ok(cert, 'f.com')
517+
fail(cert, 'foo.com')
518+
fail(cert, 'f.com')
519519
fail(cert, 'bar.com')
520520
fail(cert, 'foo.a.com')
521521
fail(cert, 'bar.foo.com')
@@ -637,7 +637,7 @@ def fail(cert, hostname):
637637
# Issue #17980: avoid denials of service by refusing more than one
638638
# wildcard per fragment.
639639
cert = {'subject': ((('commonName', 'a*b.com'),),)}
640-
ok(cert, 'axxb.com')
640+
fail(cert, 'axxb.com')
641641
cert = {'subject': ((('commonName', 'a*b.co*'),),)}
642642
fail(cert, 'axxb.com')
643643
cert = {'subject': ((('commonName', 'a*b*.com'),),)}

0 commit comments

Comments
 (0)