Certificate Hostname Validation Bypass via Leading Dot in Hostname
libcurl's wildcard certificate matching accepted a hostname beginning with a dot against a wildcard pattern, so .example.com was treated as matching *.example.com. An attacker with a wildcard certificate for a domain could therefore have a certificate wrongly accepted when a client connected to a leading-dot hostname, enabling a man-in-the-middle.
- Disclosed after 3 days
Summary
A hostname validation bypass in libcurl's wildcard certificate matching. The hostmatch() function fails to handle hostnames starting with a dot, causing .example.com to match *.example.com.
When hostname starts with ., memchr() returns position 0, so the entire hostname including the leading dot is compared against the pattern suffix. Since *.example.com becomes .example.com after skipping *, they match.
Affected version
curl 8.17.0
Steps To Reproduce
poc.sh:
#!/bin/bash
CURL="${1:-curl}"
PORT=9443
cat > /tmp/san.cnf << 'EOF'
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
CN = *.test.local
[v3_req]
subjectAltName = DNS:*.test.local
EOF
openssl req -x509 -newkey rsa:2048 -keyout /tmp/wc.key -out /tmp/wc.crt -days 1 -nodes -config /tmp/san.cnf 2>/dev/null
fuser -k $PORT/tcp 2>/dev/null
sleep 1
openssl s_server -accept $PORT -cert /tmp/wc.crt -key /tmp/wc.key -www </dev/null >/dev/null 2>&1 &
PID=$!
sleep 2
$CURL -v --max-time 5 --cacert /tmp/wc.crt --resolve ".test.local:$PORT:127.0.0.1" "https://.test.local:$PORT/" 2>&1
kill $PID 2>/dev/null
rm -f /tmp/san.cnf /tmp/wc.key /tmp/wc.crt
Run: chmod +x poc.sh ./poc.sh /path/to/curl-8.17.0
Supporting Material/References:
Vulnerable output (8.17.0):
- subject: CN=*.test.local
- subjectAltName: ".test.local" matches cert's "*.test.local"
- SSL certificate verified via OpenSSL.
GET / HTTP/1.1 Host: .test.local:9443
Expected output (7.81.0):
- subjectAltName does not match .test.local
curl: (60) SSL: no alternative certificate subject name matches target host name '.test.local'
Vulnerable code: https://github.com/curl/curl/blob/400fffa90f30c7a2dc762fa33009d24851bd2016/lib/vtls/hostcheck.c#L110-L116
Impact
An attacker holding a wildcard certificate for a domain can bypass hostname verification when the client connects to a leading-dot hostname. For example, a certificate for *.example.com will incorrectly validate against .example.com.
Exploitation requires the attacker to direct the victim to connect to a leading-dot hostname. Standard DNS rejects such hostnames, so exploitation is limited to scenarios where DNS is bypassed (e.g., /etc/hosts manipulation, custom resolver configurations, or applications using libcurl's CURLOPT_RESOLVE).
If exploited, the attacker can perform man-in-the-middle attacks on HTTPS connections.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the wildcard matching logic searched for the first dot in the hostname and, when the dot was at position zero, compared the whole hostname including that leading dot against the pattern suffix, so the two strings lined up.
Impact
An attacker holding a wildcard certificate could have it wrongly accepted for a leading-dot hostname, enabling man-in-the-middle attacks, though exploitation is limited because standard DNS rejects such hostnames and the attacker must bypass DNS resolution.
What the attacker needed
Attacker holds a wildcard certificate; victim connects to a leading-dot hostname; DNS resolution bypassed (hosts file, resolver…
How it was found
- Create a self-signed certificate whose subject alternative name is a wildcard for a test domain.
- Start a local TLS server on a chosen port using that certificate.
- Run the affected curl against a leading-dot hostname, forcing it to the local address and trusting the test certificate.
- Observe that the certificate is accepted and the request is sent, whereas an older version rejects it.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When your browser or a program like curl connects to a website over HTTPS, it checks that the site's certificate was issued for the name you typed. Certificates can use a wildcard, such as *.example.com, to cover any single subdomain. Here the check was too loose: a name starting with a dot was wrongly accepted as covered by the wildcard, so a certificate the attacker owns could be trusted for a name it should not cover.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.