mirror of
https://github.com/curl/curl.git
synced 2026-08-25 06:03:32 +03:00
url: use same credentials on redirect
Previously it could lose the username and only use the password. Added test 998 and 999 to verify. Reported-by: Tobias Bora Fixes #15262 Closes #15282
This commit is contained in:
parent
eb77297ccc
commit
9bee39bfed
6 changed files with 257 additions and 73 deletions
19
lib/url.c
19
lib/url.c
|
|
@ -1860,10 +1860,10 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data,
|
|||
return result;
|
||||
|
||||
/*
|
||||
* username and password set with their own options override the
|
||||
* credentials possibly set in the URL.
|
||||
* username and password set with their own options override the credentials
|
||||
* possibly set in the URL, but netrc does not.
|
||||
*/
|
||||
if(!data->set.str[STRING_PASSWORD]) {
|
||||
if(!data->state.aptr.passwd || (data->state.creds_from != CREDS_OPTION)) {
|
||||
uc = curl_url_get(uh, CURLUPART_PASSWORD, &data->state.up.password, 0);
|
||||
if(!uc) {
|
||||
char *decoded;
|
||||
|
|
@ -1876,12 +1876,13 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data,
|
|||
result = Curl_setstropt(&data->state.aptr.passwd, decoded);
|
||||
if(result)
|
||||
return result;
|
||||
data->state.creds_from = CREDS_URL;
|
||||
}
|
||||
else if(uc != CURLUE_NO_PASSWORD)
|
||||
return Curl_uc_to_curlcode(uc);
|
||||
}
|
||||
|
||||
if(!data->set.str[STRING_USERNAME]) {
|
||||
if(!data->state.aptr.user || (data->state.creds_from != CREDS_OPTION)) {
|
||||
/* we do not use the URL API's URL decoder option here since it rejects
|
||||
control codes and we want to allow them for some schemes in the user
|
||||
and password fields */
|
||||
|
|
@ -1895,13 +1896,10 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data,
|
|||
return result;
|
||||
conn->user = decoded;
|
||||
result = Curl_setstropt(&data->state.aptr.user, decoded);
|
||||
data->state.creds_from = CREDS_URL;
|
||||
}
|
||||
else if(uc != CURLUE_NO_USER)
|
||||
return Curl_uc_to_curlcode(uc);
|
||||
else if(data->state.aptr.passwd) {
|
||||
/* no user was set but a password, set a blank user */
|
||||
result = Curl_setstropt(&data->state.aptr.user, "");
|
||||
}
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
|
|
@ -2685,7 +2683,8 @@ static CURLcode override_login(struct Curl_easy *data,
|
|||
int ret;
|
||||
bool url_provided = FALSE;
|
||||
|
||||
if(data->state.aptr.user) {
|
||||
if(data->state.aptr.user &&
|
||||
(data->state.creds_from != CREDS_NETRC)) {
|
||||
/* there was a username in the URL. Use the URL decoded version */
|
||||
userp = &data->state.aptr.user;
|
||||
url_provided = TRUE;
|
||||
|
|
@ -2733,6 +2732,7 @@ static CURLcode override_login(struct Curl_easy *data,
|
|||
result = Curl_setstropt(&data->state.aptr.user, *userp);
|
||||
if(result)
|
||||
return result;
|
||||
data->state.creds_from = CREDS_NETRC;
|
||||
}
|
||||
}
|
||||
if(data->state.aptr.user) {
|
||||
|
|
@ -2750,6 +2750,7 @@ static CURLcode override_login(struct Curl_easy *data,
|
|||
CURLcode result = Curl_setstropt(&data->state.aptr.passwd, *passwdp);
|
||||
if(result)
|
||||
return result;
|
||||
data->state.creds_from = CREDS_NETRC;
|
||||
}
|
||||
if(data->state.aptr.passwd) {
|
||||
uc = curl_url_set(data->state.uh, CURLUPART_PASSWORD,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue