Blame SOURCES/0029-curl-7.61.1-CVE-2021-22876.patch

c3d52c
From 239f8d93866605b05f4e6b551f4327dc7fcb922b Mon Sep 17 00:00:00 2001
c3d52c
From: Viktor Szakats <commit@vsz.me>
c3d52c
Date: Tue, 23 Feb 2021 14:54:46 +0100
c3d52c
Subject: [PATCH 1/2] transfer: strip credentials from the auto-referer header
c3d52c
 field
c3d52c
c3d52c
Added test 2081 to verify.
c3d52c
c3d52c
CVE-2021-22876
c3d52c
c3d52c
Bug: https://curl.se/docs/CVE-2021-22876.html
c3d52c
c3d52c
Upstream-commit: 7214288898f5625a6cc196e22a74232eada7861c
c3d52c
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c3d52c
---
c3d52c
 lib/transfer.c | 25 +++++++++++++++++++++++--
c3d52c
 1 file changed, 23 insertions(+), 2 deletions(-)
c3d52c
c3d52c
diff --git a/lib/transfer.c b/lib/transfer.c
c3d52c
index ecd1063..263b178 100644
c3d52c
--- a/lib/transfer.c
c3d52c
+++ b/lib/transfer.c
c3d52c
@@ -1473,6 +1473,7 @@ CURLcode Curl_follow(struct Curl_easy *data,
c3d52c
   /* Location: redirect */
c3d52c
   bool disallowport = FALSE;
c3d52c
   bool reachedmax = FALSE;
c3d52c
+  CURLUcode uc;
c3d52c
 
c3d52c
   if(type == FOLLOW_REDIR) {
c3d52c
     if((data->set.maxredirs != -1) &&
c3d52c
@@ -1488,6 +1489,9 @@ CURLcode Curl_follow(struct Curl_easy *data,
c3d52c
       data->set.followlocation++; /* count location-followers */
c3d52c
 
c3d52c
       if(data->set.http_auto_referer) {
c3d52c
+        CURLU *u;
c3d52c
+        char *referer;
c3d52c
+
c3d52c
         /* We are asked to automatically set the previous URL as the referer
c3d52c
            when we get the next URL. We pick the ->url field, which may or may
c3d52c
            not be 100% correct */
c3d52c
@@ -1497,9 +1501,26 @@ CURLcode Curl_follow(struct Curl_easy *data,
c3d52c
           data->change.referer_alloc = FALSE;
c3d52c
         }
c3d52c
 
c3d52c
-        data->change.referer = strdup(data->change.url);
c3d52c
-        if(!data->change.referer)
c3d52c
+        /* Make a copy of the URL without crenditals and fragment */
c3d52c
+        u = curl_url();
c3d52c
+        if(!u)
c3d52c
+          return CURLE_OUT_OF_MEMORY;
c3d52c
+
c3d52c
+        uc = curl_url_set(u, CURLUPART_URL, data->change.url, 0);
c3d52c
+        if(!uc)
c3d52c
+          uc = curl_url_set(u, CURLUPART_FRAGMENT, NULL, 0);
c3d52c
+        if(!uc)
c3d52c
+          uc = curl_url_set(u, CURLUPART_USER, NULL, 0);
c3d52c
+        if(!uc)
c3d52c
+          uc = curl_url_set(u, CURLUPART_PASSWORD, NULL, 0);
c3d52c
+        if(!uc)
c3d52c
+          uc = curl_url_get(u, CURLUPART_URL, &referer, 0);
c3d52c
+
c3d52c
+        curl_url_cleanup(u);
c3d52c
+
c3d52c
+        if(uc || referer == NULL)
c3d52c
           return CURLE_OUT_OF_MEMORY;
c3d52c
+        data->change.referer = referer;
c3d52c
         data->change.referer_alloc = TRUE; /* yes, free this later */
c3d52c
       }
c3d52c
     }
c3d52c
-- 
c3d52c
2.30.2
c3d52c
c3d52c
c3d52c
From f7d1d478b87499ce31d6aa3251830b78447ad952 Mon Sep 17 00:00:00 2001
c3d52c
From: Daniel Stenberg <daniel@haxx.se>
c3d52c
Date: Mon, 29 Mar 2021 09:32:14 +0200
c3d52c
Subject: [PATCH 2/2] transfer: clear 'referer' in declaration
c3d52c
c3d52c
To silence (false positive) compiler warnings about it.
c3d52c
c3d52c
Follow-up to 7214288898f5625
c3d52c
c3d52c
Reviewed-by: Marcel Raad
c3d52c
Closes #6810
c3d52c
c3d52c
Upstream-commit: 6bb028dbda6cbfe83f66de773544f71e4813160f
c3d52c
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c3d52c
---
c3d52c
 lib/transfer.c | 4 ++--
c3d52c
 1 file changed, 2 insertions(+), 2 deletions(-)
c3d52c
c3d52c
diff --git a/lib/transfer.c b/lib/transfer.c
c3d52c
index 263b178..ad5a7ba 100644
c3d52c
--- a/lib/transfer.c
c3d52c
+++ b/lib/transfer.c
c3d52c
@@ -1490,7 +1490,7 @@ CURLcode Curl_follow(struct Curl_easy *data,
c3d52c
 
c3d52c
       if(data->set.http_auto_referer) {
c3d52c
         CURLU *u;
c3d52c
-        char *referer;
c3d52c
+        char *referer = NULL;
c3d52c
 
c3d52c
         /* We are asked to automatically set the previous URL as the referer
c3d52c
            when we get the next URL. We pick the ->url field, which may or may
c3d52c
@@ -1518,7 +1518,7 @@ CURLcode Curl_follow(struct Curl_easy *data,
c3d52c
 
c3d52c
         curl_url_cleanup(u);
c3d52c
 
c3d52c
-        if(uc || referer == NULL)
c3d52c
+        if(uc || !referer)
c3d52c
           return CURLE_OUT_OF_MEMORY;
c3d52c
         data->change.referer = referer;
c3d52c
         data->change.referer_alloc = TRUE; /* yes, free this later */
c3d52c
-- 
c3d52c
2.30.2
c3d52c