Skip to content

Commit e4f6e4f

Browse files
committed
Backport patch from python issue17980 PYTHON-522
1 parent 19c6c99 commit e4f6e4f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pymongo/ssl_match_hostname.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@ class CertificateError(ValueError):
88
pass
99

1010

11-
def _dnsname_to_pat(dn):
11+
def _dnsname_to_pat(dn, max_wildcards=1):
1212
pats = []
1313
for frag in dn.split(r'.'):
14+
if frag.count('*') > max_wildcards:
15+
# Issue #17980: avoid denials of service by refusing more
16+
# than one wildcard per fragment. A survery of established
17+
# policy among SSL implementations showed it to be a
18+
# reasonable choice.
19+
raise CertificateError(
20+
"too many wildcards in certificate DNS name: " + repr(dn))
1421
if frag == '*':
1522
# When '*' is a fragment by itself, it matches a non-empty dotless
1623
# fragment.

0 commit comments

Comments
 (0)