Skip to content
Misconfiguration Disclosed report Advanced CVE-2022-30115

HSTS multi-trailing-dot bypass-ish: possible incomplete fix for CVE-2022-30115

The HSTS and alt-svc hostname normalisation in curl strips only one trailing dot, so a hostname with two or more trailing dots does not match a stored HSTS entry. An attacker who can get such a hostname fetched could have the connection sent over plaintext HTTP instead of being upgraded to HTTPS.

giant_anteater Follow

Originally disclosed on HackerOne

  • Disclosed after 5 days

Hi all,

Honestly, I'm not completely certain about this issue, but I think the CVE-2022-30115 fix ("HSTS bypass via trailing dot") is incomplete: the same asymmetry exists for hostnames with two or more trailing dots, so http://example.com../ still gets sent in plaintext when there's a valid HSTS entry for example.com. The fix commit itself — fae6fea209 (2022-05-09, "hsts: ignore trailing dots when comparing hosts names") — used a single if rather than a while, so anything beyond one trailing dot still slips through.

The short version: the HSTS layer normalises the runtime hostname by stripping one trailing dot before lookup; the URL parser and the peer layer preserve every trailing dot verbatim. So a single-dot host (example.com.) is correctly normalised down to example.com and matches the stored entry — that's the 2022 fix doing its job — but example.com.. ends up looking for example.com. in the store and never matches.

The strip is a single if, not a while, in all three places it appears:

  • lib/hsts.c:117-119 (hsts_create, store path)
  • lib/hsts.c:156-158 (hsts_check, lookup path)
  • lib/hsts.c:439-441 (hsts_add_host_expire, file-load path)

So, this is the same hostname-normalisation issue as CVE-2022-30115, just with multiple trailing dots rather than one: the 2022 fix handles exactly one trailing dot, but not two or more. Replacing each if with a while makes the normalisation consistent, and hsts_check would probably also needs an if(!hlen) return NULL; guard for an all-dots host (untested, jfyi).

Using while instead of if would match how major browser HSTS implementations treat this class of hostname canonicalisation. This would match how major browser HSTS implementations treat this class of hostname canonicalisation, e.g. Chromium's HSTS preload lookup strips the full trailing-dot suffix before lookup in DecodeHSTSPreload() (size_t trailing_dot_found = host.find_last_not_of('.');). Firefox's HSTS path canonicalises hostnames through CanonicalizeHostname(), whose contract explicitly covers hostnames with multiple trailing dots and normalises them to lowercase with no trailing dot.

Anyways, a quick Reproducer on master:

Bash
echo 'example.com "29991231 23:59:59"' > /tmp/hsts.txt
for H in 'example.com' 'example.com.' 'example.com..'; do
  echo "=== http://$H/ ===";
  ./src/curl -sv --hsts /tmp/hsts.txt \
    --resolve "$H:80:127.0.0.1" --resolve "$H:443:127.0.0.1" \
    --max-time 1 --connect-timeout 1 -o /dev/null "http://$H/" 2>&1 \
    | grep -E "Switched|Trying " | head -2
done

Output:

=== http://example.com/ ===
* Switched from HTTP to HTTPS due to HSTS => https://example.com/
*   Trying 127.0.0.1:443...
=== http://example.com./ ===
* Switched from HTTP to HTTPS due to HSTS => https://example.com./
*   Trying 127.0.0.1:443...
=== http://example.com../ ===
*   Trying 127.0.0.1:80...

--resolve for both 80 and 443 isolates the upgrade decision — the destination address is identical, the only thing that varies is whether libcurl picked https://.

Caveat: example.com.. is of course notreally a legal DNS name (empty label) and standard resolvers reject it — getent, host, dig and curl's own default resolver all fail. So the bypass needs /etc/hosts, attacker-controlled DNS, or app code feeding the multi-dot name into a --resolve-equivalent (like similar to how we use --resolve above). The url-parser test in tests/libtest/lib1560.c:209 actually mentions this specific case, so it is seemingly a valid usage: "Multiple trailing dots, not okay in DNS but works in /etc/hosts".

Also, same single-if pattern in lib/altsvc.c — altsvc_createid at :98-101 on store and hostcompare at :440-441 on lookup — with the same multi-dot miss:

Bash
echo 'h2 example.com 443 h2 alt.example.com 8443 "20991231 23:59:59" 1 0' \
    > /tmp/altsvc.txt
for H in 'example.com' 'example.com.' 'example.com..'; do
  echo "=== https://$H/ ==="
  ./src/curl -v --alt-svc /tmp/altsvc.txt \
    --resolve "$H:443:127.0.0.1" \
    --resolve "alt.example.com:8443:127.0.0.1" \
    --max-time 1 --connect-timeout 1 -k -o /dev/null "https://$H/" 2>&1 \
    | grep -E "Trying" | head -1
done
=== https://example.com/ ===
*   Trying 127.0.0.1:8443...        <- alt-svc hit, alt port used
=== https://example.com./ ===
*   Trying 127.0.0.1:8443...        <- alt-svc hit (1-dot strip works)
=== https://example.com../ ===
*   Trying 127.0.0.1:443...         <- alt-svc miss, canonical port

The alt-svc miss is just a missed optimisation, not a security downgrade — but worth fixing for consistency (and I'll report a similar actual security issue with that later).

Impact

HSTS protection is silently bypassed for any hostname with two or more trailing dots, downgrading HTTPS to plaintext and exposing credentials and cookies to a network attacker who can influence the URL being fetched.

The original report as published on HackerOne, by giant_anteater. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

The hostname normalisation in the HSTS (and alt-svc) code strips a single trailing dot with an if rather than a while, so hostnames with two or more trailing dots are not canonicalised before the store lookup.

Impact

HSTS protection could be silently bypassed for hostnames with two or more trailing dots, downgrading to plaintext and exposing credentials and cookies to a network attacker, though such names are not legal DNS and need /etc/hosts, attacker-controlled DNS or app code to reach.

What the attacker needed

Attacker can influence the URL fetched; multi-dot name resolvable via hosts or DNS

The fix

The normalisation should strip the full trailing-dot suffix (a while loop instead of an if) in all three HSTS places and the alt-svc code, with a guard for an all-dots host.

How it was found

  1. Create an HSTS store file containing an entry for the bare hostname.
  2. Run curl against the bare hostname, the one-dot hostname and the two-dot hostname, resolving both ports to the same address.
  3. Observe that the bare and one-dot hosts are upgraded to HTTPS while the two-dot host connects on port 80 in plaintext.

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.

HSTS is a rule a site gives the browser or client saying 'always talk to me over the encrypted HTTPS protocol, never plain HTTP'. curl stores these rules and checks the hostname before connecting, but it only removes one trailing dot from the name before comparing, so a name ending in two dots does not match the stored rule and the request goes out unencrypted.

What is Misconfiguration?

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.

More by giant_anteater

View all

93 more disclosed reports, best first.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Security misconfiguration

The lesson behind this report.

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.