mirror of
https://github.com/apple/swift-nio-ssl
synced 2026-11-28 05:14:29 +00:00
### Motivation
`AnalysedCertificateHostname.init` already refuses to construct a
wildcard matcher when the certificate's first label begins with the IDNA
A-label prefix `xn--` (line 287). The symmetric case is not enforced: a
wildcard SAN whose own first label is plain ASCII can still expand into
a target hostname whose first label begins with `xn--`.
A SAN of the form `*-5wao1o.example.com` will currently match a target
hostname `xn--rksmrgs-5wao1o.example.com` (the IDNA A-label form of
`räksmörgås.example.com`). Both OpenSSL's `equal_wildcard` and CPython's
`ssl._dnsname_match` reject that case explicitly; this library accepts
it.
Verified by copying `AnalysedCertificateHostname` verbatim from `main`
into a standalone executable and running:
```
[OK ] Sanity: wildcard matches normal subdomain
cert SAN: *.example.com
target: foo.example.com
expected: true got: true
[OK ] Sanity: wildcard does NOT match different parent
cert SAN: *.example.com
target: foo.evil.com
expected: false got: false
[OK ] Sanity: cert that IS an A-label wildcard rejected at parse
cert SAN: xn--*.example.com
target: xn--anything.example.com
expected: false got: false
[BROKEN ] VULN: partial wildcard expansion produces A-label target
cert SAN: *-5wao1o.example.com
target: xn--rksmrgs-5wao1o.example.com
expected: false got: true
```
After the patch in this PR the BROKEN case becomes OK.
### Modifications
In `validMatchForName`, after splitting the target around its first
period, return `false` if the target's first label begins with `xn--`.
Mirrors the existing cert-side check at line 287 and the
`caseInsensitiveElementsEqual(asciiIDNAIdentifier)` idiom already in use
in this file.
### Result
Wildcard SANs no longer expand into IDNA A-label targets, matching the
behaviour of OpenSSL and CPython. The existing
`testDoesNotMatchIDNALabelWithWildcard` continues to cover the cert-side
variant; the target-side variant is the new case this patch addresses.
---------
Co-authored-by: Cory Benfield <lukasa@apple.com>