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