]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
hsts: handle adding the same host name again
authorDaniel Stenberg <daniel@haxx.se>
Tue, 27 Dec 2022 10:50:23 +0000 (11:50 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 27 Dec 2022 14:22:32 +0000 (15:22 +0100)
It will then use the largest expire time of the two entries.

lib/hsts.c

index 339237be1c621aa1c5bd0b8d5df87378d6f3b088..8d6723ee587d28bc4c6d2923db552570626f5e35 100644 (file)
@@ -426,14 +426,23 @@ static CURLcode hsts_add(struct hsts *h, char *line)
   if(2 == rc) {
     time_t expires = strcmp(date, UNLIMITED) ? Curl_getdate_capped(date) :
       TIME_T_MAX;
-    CURLcode result;
+    CURLcode result = CURLE_OK;
     char *p = host;
     bool subdomain = FALSE;
+    struct stsentry *e;
     if(p[0] == '.') {
       p++;
       subdomain = TRUE;
     }
-    result = hsts_create(h, p, subdomain, expires);
+    /* only add it if not already present */
+    e = Curl_hsts(h, p, subdomain);
+    if(!e)
+      result = hsts_create(h, p, subdomain, expires);
+    else {
+      /* the same host name, use the largest expire time */
+      if(expires > e->expires)
+        e->expires = expires;
+    }
     if(result)
       return result;
   }