]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cookies: make bad_domain() not consider a trailing dot fine
authorDaniel Stenberg <daniel@haxx.se>
Mon, 9 May 2022 14:47:06 +0000 (16:47 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 9 May 2022 14:47:28 +0000 (16:47 +0200)
The check for a dot in the domain must not consider a single trailing
dot to be fine, as then TLD + trailing dot is fine and curl will accept
setting cookies for it.

CVE-2022-27779

Reported-by: Axel Chong
Bug: https://curl.se/docs/CVE-2022-27779.html
Closes #8820

lib/cookie.c

index 451881f578eccd3959b182565717e805bec649d6..0c2d49b478ca3ee1093b1d66764061e24518b69c 100644 (file)
@@ -427,7 +427,15 @@ static void remove_expired(struct CookieInfo *cookies)
 /* Make sure domain contains a dot or is localhost. */
 static bool bad_domain(const char *domain)
 {
-  return !strchr(domain, '.') && !strcasecompare(domain, "localhost");
+  if(strcasecompare(domain, "localhost"))
+    return FALSE;
+  else {
+    /* there must be a dot present, but that dot must not be a trailing dot */
+    char *dot = strchr(domain, '.');
+    if(dot)
+      return dot[1] ? FALSE : TRUE;
+  }
+  return TRUE;
 }
 
 /*