Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http, vauth: always provide Curl_allow_auth_to_host() functionality #9600

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 2 additions & 17 deletions lib/http.c
Expand Up @@ -721,21 +721,6 @@ CURLcode Curl_http_auth_act(struct Curl_easy *data)
return result;
}

/*
* Curl_allow_auth_to_host() tells if authentication, cookies or other
* "sensitive data" can (still) be sent to this host.
*/
bool Curl_allow_auth_to_host(struct Curl_easy *data)
{
struct connectdata *conn = data->conn;
return (!data->state.this_is_a_follow ||
data->set.allow_auth_to_other_hosts ||
(data->state.first_host &&
strcasecompare(data->state.first_host, conn->host.name) &&
(data->state.first_remote_port == conn->remote_port) &&
(data->state.first_remote_protocol == conn->handler->protocol)));
}

#ifndef CURL_DISABLE_HTTP_AUTH
/*
* Output the correct authentication header depending on the auth type
Expand Down Expand Up @@ -934,7 +919,7 @@ Curl_http_output_auth(struct Curl_easy *data,

/* To prevent the user+password to get sent to other than the original host
due to a location-follow */
if(Curl_allow_auth_to_host(data)
if(Curl_auth_allowed_to_host(data)
#ifndef CURL_DISABLE_NETRC
|| conn->bits.netrc
#endif
Expand Down Expand Up @@ -1988,7 +1973,7 @@ CURLcode Curl_add_custom_headers(struct Curl_easy *data,
checkprefix("Cookie:", compare)) &&
/* be careful of sending this potentially sensitive header to
other hosts */
!Curl_allow_auth_to_host(data))
!Curl_auth_allowed_to_host(data))
;
else {
#ifdef USE_HYPER
Expand Down
6 changes: 0 additions & 6 deletions lib/http.h
Expand Up @@ -392,10 +392,4 @@ Curl_http_output_auth(struct Curl_easy *data,
bool proxytunnel); /* TRUE if this is the request setting
up the proxy tunnel */

/*
* Curl_allow_auth_to_host() tells if authentication, cookies or other
* "sensitive data" can (still) be sent to this host.
*/
bool Curl_allow_auth_to_host(struct Curl_easy *data);

#endif /* HEADER_CURL_HTTP_H */
17 changes: 17 additions & 0 deletions lib/vauth/vauth.c
Expand Up @@ -27,6 +27,8 @@
#include <curl/curl.h>

#include "vauth.h"
#include "urldata.h"
#include "strcase.h"
#include "curl_multibyte.h"
#include "curl_printf.h"

Expand Down Expand Up @@ -144,3 +146,18 @@ bool Curl_auth_user_contains_domain(const char *user)

return valid;
}

/*
* Curl_auth_ollowed_to_host() tells if authentication, cookies or other
* "sensitive data" can (still) be sent to this host.
*/
bool Curl_auth_allowed_to_host(struct Curl_easy *data)
{
struct connectdata *conn = data->conn;
return (!data->state.this_is_a_follow ||
data->set.allow_auth_to_other_hosts ||
(data->state.first_host &&
strcasecompare(data->state.first_host, conn->host.name) &&
(data->state.first_remote_port == conn->remote_port) &&
(data->state.first_remote_protocol == conn->handler->protocol)));
}
6 changes: 6 additions & 0 deletions lib/vauth/vauth.h
Expand Up @@ -54,6 +54,12 @@ struct gsasldata;
#define GSS_ERROR(status) ((status) & 0x80000000)
#endif

/*
* Curl_auth_allowed_to_host() tells if authentication, cookies or other
* "sensitive data" can (still) be sent to this host.
*/
bool Curl_auth_allowed_to_host(struct Curl_easy *data);

/* This is used to build a SPN string */
#if !defined(USE_WINDOWS_SSPI)
char *Curl_auth_build_spn(const char *service, const char *host,
Expand Down
3 changes: 2 additions & 1 deletion lib/vtls/gtls.c
Expand Up @@ -45,6 +45,7 @@
#include "inet_pton.h"
#include "gtls.h"
#include "vtls.h"
#include "vauth/vauth.h"
#include "parsedate.h"
#include "connect.h" /* for the connect timeout */
#include "select.h"
Expand Down Expand Up @@ -448,7 +449,7 @@ gtls_connect_step1(struct Curl_easy *data,

#ifdef USE_GNUTLS_SRP
if((SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP) &&
Curl_allow_auth_to_host(data)) {
Curl_auth_allowed_to_host(data)) {
infof(data, "Using TLS-SRP username: %s",
SSL_SET_OPTION(primary.username));

Expand Down
3 changes: 2 additions & 1 deletion lib/vtls/openssl.c
Expand Up @@ -55,6 +55,7 @@
#include "slist.h"
#include "select.h"
#include "vtls.h"
#include "vauth/vauth.h"
#include "keylog.h"
#include "strcase.h"
#include "hostcheck.h"
Expand Down Expand Up @@ -2833,7 +2834,7 @@ static CURLcode ossl_connect_step1(struct Curl_easy *data,

#ifdef USE_OPENSSL_SRP
if((ssl_authtype == CURL_TLSAUTH_SRP) &&
Curl_allow_auth_to_host(data)) {
Curl_auth_allowed_to_host(data)) {
char * const ssl_username = SSL_SET_OPTION(primary.username);
char * const ssl_password = SSL_SET_OPTION(primary.password);
infof(data, "Using TLS-SRP username: %s", ssl_username);
Expand Down