|
| 1 | +From 2b0994c29a721c91c572cff7808c572a24d251eb Thu Nov 23 00:00:00 2023 |
| 2 | +From: Daniel Stenberg < [email protected]> |
| 3 | +Date: Thu, 23 Nov 2023 23:28:32 +0200 |
| 4 | +Subject: [PATCH] cookie: lowercase the domain names before PSL checks |
| 5 | + |
| 6 | +Reported-by: Harry Sintonen |
| 7 | + |
| 8 | +Closes #12387 |
| 9 | +--- |
| 10 | +diff --git a/lib/cookie.c b/lib/cookie.c |
| 11 | +index c457b2d95..fc3f2bd98 100644 |
| 12 | +--- a/lib/cookie.c |
| 13 | ++++ b/lib/cookie.c |
| 14 | +@@ -1049,15 +1049,23 @@ Curl_cookie_add(struct Curl_easy *data, |
| 15 | + * dereference it. |
| 16 | + */ |
| 17 | + if(data && (domain && co->domain && !Curl_host_is_ipnum(co->domain))) { |
| 18 | +- const psl_ctx_t *psl = Curl_psl_use(data); |
| 19 | +- int acceptable; |
| 20 | +- |
| 21 | +- if(psl) { |
| 22 | +- acceptable = psl_is_cookie_domain_acceptable(psl, domain, co->domain); |
| 23 | +- Curl_psl_release(data); |
| 24 | ++ bool acceptable = FALSE; |
| 25 | ++ char lcase[256]; |
| 26 | ++ char lcookie[256]; |
| 27 | ++ size_t dlen = strlen(domain); |
| 28 | ++ size_t clen = strlen(co->domain); |
| 29 | ++ if((dlen < sizeof(lcase)) && (clen < sizeof(lcookie))) { |
| 30 | ++ const psl_ctx_t *psl = Curl_psl_use(data); |
| 31 | ++ if(psl) { |
| 32 | ++ /* the PSL check requires lowercase domain name and pattern */ |
| 33 | ++ Curl_strntolower(lcase, domain, dlen + 1); |
| 34 | ++ Curl_strntolower(lcookie, co->domain, clen + 1); |
| 35 | ++ acceptable = psl_is_cookie_domain_acceptable(psl, lcase, lcookie); |
| 36 | ++ Curl_psl_release(data); |
| 37 | ++ } |
| 38 | ++ else |
| 39 | ++ acceptable = !bad_domain(domain, strlen(domain)); |
| 40 | + } |
| 41 | +- else |
| 42 | +- acceptable = !bad_domain(domain); |
| 43 | + |
| 44 | + if(!acceptable) { |
| 45 | + infof(data, "cookie '%s' dropped, domain '%s' must not " |
0 commit comments