mirror of
https://github.com/curl/curl.git
synced 2026-07-26 09:47:18 +03:00
http: clear the proxy credentials as well on port or scheme change
Add tests 2009-2011 to verify switching between proxies with credentials when the switch is driven by a redirect Reported-by: Dwij Mehta Closes #21304
This commit is contained in:
parent
9ceb3ff46a
commit
188c2f166a
7 changed files with 262 additions and 16 deletions
12
lib/http.c
12
lib/http.c
|
|
@ -1278,12 +1278,24 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl,
|
|||
curlx_free(scheme);
|
||||
}
|
||||
if(clear) {
|
||||
CURLcode result = Curl_reset_userpwd(data);
|
||||
if(result) {
|
||||
curlx_free(follow_url);
|
||||
return result;
|
||||
}
|
||||
curlx_safefree(data->state.aptr.user);
|
||||
curlx_safefree(data->state.aptr.passwd);
|
||||
}
|
||||
}
|
||||
}
|
||||
DEBUGASSERT(follow_url);
|
||||
{
|
||||
CURLcode result = Curl_reset_proxypwd(data);
|
||||
if(result) {
|
||||
curlx_free(follow_url);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if(type == FOLLOW_FAKE) {
|
||||
/* we are only figuring out the new URL if we would have followed locations
|
||||
|
|
|
|||
|
|
@ -438,6 +438,40 @@ void Curl_init_CONNECT(struct Curl_easy *data)
|
|||
data->state.upload = (data->state.httpreq == HTTPREQ_PUT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Restore the user credentials to those set in options.
|
||||
*/
|
||||
CURLcode Curl_reset_userpwd(struct Curl_easy *data)
|
||||
{
|
||||
CURLcode result;
|
||||
if(data->set.str[STRING_USERNAME] || data->set.str[STRING_PASSWORD])
|
||||
data->state.creds_from = CREDS_OPTION;
|
||||
result = Curl_setstropt(&data->state.aptr.user,
|
||||
data->set.str[STRING_USERNAME]);
|
||||
if(!result)
|
||||
result = Curl_setstropt(&data->state.aptr.passwd,
|
||||
data->set.str[STRING_PASSWORD]);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Restore the proxy credentials to those set in options.
|
||||
*/
|
||||
CURLcode Curl_reset_proxypwd(struct Curl_easy *data)
|
||||
{
|
||||
#ifndef CURL_DISABLE_PROXY
|
||||
CURLcode result = Curl_setstropt(&data->state.aptr.proxyuser,
|
||||
data->set.str[STRING_PROXYUSERNAME]);
|
||||
if(!result)
|
||||
result = Curl_setstropt(&data->state.aptr.proxypasswd,
|
||||
data->set.str[STRING_PROXYPASSWORD]);
|
||||
return result;
|
||||
#else
|
||||
(void)data;
|
||||
return CURLE_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Curl_pretransfer() is called immediately before a transfer starts, and only
|
||||
* once for one transfer no matter if it has redirects or do multi-pass
|
||||
|
|
@ -586,23 +620,10 @@ CURLcode Curl_pretransfer(struct Curl_easy *data)
|
|||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if(data->set.str[STRING_USERNAME] ||
|
||||
data->set.str[STRING_PASSWORD])
|
||||
data->state.creds_from = CREDS_OPTION;
|
||||
if(!result)
|
||||
result = Curl_setstropt(&data->state.aptr.user,
|
||||
data->set.str[STRING_USERNAME]);
|
||||
result = Curl_reset_userpwd(data);
|
||||
if(!result)
|
||||
result = Curl_setstropt(&data->state.aptr.passwd,
|
||||
data->set.str[STRING_PASSWORD]);
|
||||
#ifndef CURL_DISABLE_PROXY
|
||||
if(!result)
|
||||
result = Curl_setstropt(&data->state.aptr.proxyuser,
|
||||
data->set.str[STRING_PROXYUSERNAME]);
|
||||
if(!result)
|
||||
result = Curl_setstropt(&data->state.aptr.proxypasswd,
|
||||
data->set.str[STRING_PROXYPASSWORD]);
|
||||
#endif
|
||||
result = Curl_reset_proxypwd(data);
|
||||
|
||||
data->req.headerbytecount = 0;
|
||||
Curl_headers_cleanup(data);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ char *Curl_checkheaders(const struct Curl_easy *data,
|
|||
|
||||
void Curl_init_CONNECT(struct Curl_easy *data);
|
||||
|
||||
CURLcode Curl_reset_userpwd(struct Curl_easy *data);
|
||||
CURLcode Curl_reset_proxypwd(struct Curl_easy *data);
|
||||
CURLcode Curl_pretransfer(struct Curl_easy *data);
|
||||
|
||||
CURLcode Curl_sendrecv(struct Curl_easy *data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue