mirror of
https://github.com/moparisthebest/curl
synced 2025-02-28 17:31:46 -05:00
hsts: ignore numberical IP address hosts
Also, use a single function library-wide for detecting if a given hostname is a numerical IP address. Reported-by: Harry Sintonen Fixes #7146 Closes #7149
This commit is contained in:
parent
9097843e8f
commit
1c1d9f1aff
33
lib/cookie.c
33
lib/cookie.c
@ -146,31 +146,6 @@ static bool tailmatch(const char *cooke_domain, const char *hostname)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* isip
|
||||
*
|
||||
* Returns true if the given string is an IPv4 or IPv6 address (if IPv6 has
|
||||
* been enabled while building libcurl, and false otherwise.
|
||||
*/
|
||||
static bool isip(const char *domain)
|
||||
{
|
||||
struct in_addr addr;
|
||||
#ifdef ENABLE_IPV6
|
||||
struct in6_addr addr6;
|
||||
#endif
|
||||
|
||||
if(Curl_inet_pton(AF_INET, domain, &addr)
|
||||
#ifdef ENABLE_IPV6
|
||||
|| Curl_inet_pton(AF_INET6, domain, &addr6)
|
||||
#endif
|
||||
) {
|
||||
/* domain name given as IP address */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* matching cookie path and url path
|
||||
* RFC6265 5.1.4 Paths and Path-Match
|
||||
@ -303,7 +278,7 @@ static size_t cookiehash(const char * const domain)
|
||||
const char *top;
|
||||
size_t len;
|
||||
|
||||
if(!domain || isip(domain))
|
||||
if(!domain || Curl_host_is_ipnum(domain))
|
||||
return 0;
|
||||
|
||||
top = get_top_domain(domain, &len);
|
||||
@ -645,7 +620,7 @@ Curl_cookie_add(struct Curl_easy *data,
|
||||
domain = ":";
|
||||
#endif
|
||||
|
||||
is_ip = isip(domain ? domain : whatptr);
|
||||
is_ip = Curl_host_is_ipnum(domain ? domain : whatptr);
|
||||
|
||||
if(!domain
|
||||
|| (is_ip && !strcmp(whatptr, domain))
|
||||
@ -996,7 +971,7 @@ Curl_cookie_add(struct Curl_easy *data,
|
||||
* must also check that the data handle isn't NULL since the psl code will
|
||||
* dereference it.
|
||||
*/
|
||||
if(data && (domain && co->domain && !isip(co->domain))) {
|
||||
if(data && (domain && co->domain && !Curl_host_is_ipnum(co->domain))) {
|
||||
const psl_ctx_t *psl = Curl_psl_use(data);
|
||||
int acceptable;
|
||||
|
||||
@ -1355,7 +1330,7 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
|
||||
remove_expired(c);
|
||||
|
||||
/* check if host is an IP(v4|v6) address */
|
||||
is_ip = isip(host);
|
||||
is_ip = Curl_host_is_ipnum(host);
|
||||
|
||||
co = c->cookies[myhash];
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
#include "hostcheck.h"
|
||||
#include "strcase.h"
|
||||
#include "inet_pton.h"
|
||||
#include "hostip.h"
|
||||
|
||||
#include "curl_memory.h"
|
||||
/* The last #include file should be: */
|
||||
@ -67,10 +67,6 @@ static int hostmatch(char *hostname, char *pattern)
|
||||
const char *pattern_label_end, *pattern_wildcard, *hostname_label_end;
|
||||
int wildcard_enabled;
|
||||
size_t prefixlen, suffixlen;
|
||||
struct in_addr ignored;
|
||||
#ifdef ENABLE_IPV6
|
||||
struct sockaddr_in6 si6;
|
||||
#endif
|
||||
|
||||
/* normalize pattern and hostname by stripping off trailing dots */
|
||||
size_t len = strlen(hostname);
|
||||
@ -86,12 +82,8 @@ static int hostmatch(char *hostname, char *pattern)
|
||||
CURL_HOST_MATCH : CURL_HOST_NOMATCH;
|
||||
|
||||
/* detect IP address as hostname and fail the match if so */
|
||||
if(Curl_inet_pton(AF_INET, hostname, &ignored) > 0)
|
||||
if(Curl_host_is_ipnum(hostname))
|
||||
return CURL_HOST_NOMATCH;
|
||||
#ifdef ENABLE_IPV6
|
||||
if(Curl_inet_pton(AF_INET6, hostname, &si6.sin6_addr) > 0)
|
||||
return CURL_HOST_NOMATCH;
|
||||
#endif
|
||||
|
||||
/* We require at least 2 dots in pattern to avoid too wide wildcard
|
||||
match. */
|
||||
|
19
lib/hostip.c
19
lib/hostip.c
@ -460,6 +460,25 @@ Curl_cache_addr(struct Curl_easy *data,
|
||||
return dns;
|
||||
}
|
||||
|
||||
/*
|
||||
* Curl_host_is_ipnum() returns TRUE if the given string is a numerical IPv4
|
||||
* (or IPv6 if supported) address.
|
||||
*/
|
||||
bool Curl_host_is_ipnum(const char *hostname)
|
||||
{
|
||||
struct in_addr in;
|
||||
#ifdef ENABLE_IPV6
|
||||
struct in6_addr in6;
|
||||
#endif
|
||||
if(Curl_inet_pton(AF_INET, hostname, &in) > 0
|
||||
#ifdef ENABLE_IPV6
|
||||
|| Curl_inet_pton(AF_INET6, hostname, &in6) > 0
|
||||
#endif
|
||||
)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Curl_resolv() is the main name resolve function within libcurl. It resolves
|
||||
* a name and returns a pointer to the entry in the 'entry' argument (if one
|
||||
|
@ -71,6 +71,8 @@ struct Curl_dns_entry {
|
||||
long inuse;
|
||||
};
|
||||
|
||||
bool Curl_host_is_ipnum(const char *hostname);
|
||||
|
||||
/*
|
||||
* Curl_resolv() returns an entry with the info for the specified host
|
||||
* and port.
|
||||
|
@ -138,6 +138,11 @@ CURLcode Curl_hsts_parse(struct hsts *h, const char *hostname,
|
||||
struct stsentry *sts;
|
||||
time_t now = time(NULL);
|
||||
|
||||
if(Curl_host_is_ipnum(hostname))
|
||||
/* "explicit IP address identification of all forms is excluded."
|
||||
/ RFC 6797 */
|
||||
return CURLE_OK;
|
||||
|
||||
do {
|
||||
while(*p && ISSPACE(*p))
|
||||
p++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user