doh: cap the maximum TTL to 24 hours

To avoid mistakes or abuse to cause problems. Many public DNS providers
cap their cache times to this.

Verify in test 1650

Reported-by: netspacer.research
Closes #22122
This commit is contained in:
Daniel Stenberg 2026-06-21 23:32:09 +02:00
parent 8ed285f06d
commit e8e3af2abb
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
2 changed files with 14 additions and 9 deletions

View file

@ -725,7 +725,9 @@ UNITTEST void de_init(struct dohentry *de)
curlx_dyn_init(&de->cname[i], DYN_DOH_CNAME);
}
/* @unittest 1655 */
/* TTL value cap */
#define MAX_DNS_TTL 86400U /* 24 hours */
/* @unittest 1650 */
UNITTEST DOHcode doh_resp_decode(const unsigned char *doh,
size_t dohlen,
DNStype dnstype,
@ -795,6 +797,8 @@ UNITTEST DOHcode doh_resp_decode(const unsigned char *doh,
return DOH_DNS_OUT_OF_RANGE;
ttl = doh_get32bit(doh, index);
if(ttl > MAX_DNS_TTL)
ttl = MAX_DNS_TTL;
if(ttl < d->ttl)
d->ttl = ttl;
index += 4;