Skip to content

Commit

Permalink
Always bypass localhost addresses when using manual proxy.
Browse files Browse the repository at this point in the history
Previously if the proxy bypass is not set, then localhost proxies would not
be bypassed. This ignores whether or not the proxy bypass is set and still
continues to check if the proxy needs to be bypassed for localhost addresses.
  • Loading branch information
nmoinvaz committed Feb 3, 2023
1 parent 6451d51 commit a051187
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
6 changes: 3 additions & 3 deletions resolver_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ bool proxy_resolver_mac_get_proxies_for_url(void *ctx, const char *url) {
} else if ((proxy = proxy_config_get_proxy(url)) != NULL) {
// Check to see if we need to bypass the proxy for the url
bool should_bypass = false;
if ((bypass_list = proxy_config_get_bypass_list()) != NULL)
should_bypass = should_bypass_proxy(url, bypass_list);
bypass_list = proxy_config_get_bypass_list();
should_bypass = should_bypass_proxy(url, bypass_list);
if (should_bypass) {
// Bypass the proxy for the url
LOG_INFO("Bypassing proxy for %s (%s)\n", url, bypass_list);
LOG_INFO("Bypassing proxy for %s (%s)\n", url, bypass_list ? bypass_list : "null");
proxy_resolver->list = strdup("direct://");
} else {
// Use proxy from settings
Expand Down
6 changes: 3 additions & 3 deletions resolver_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ bool proxy_resolver_posix_get_proxies_for_url(void *ctx, const char *url) {
if ((proxy = proxy_config_get_proxy(scheme)) != NULL) {
// Check to see if we need to bypass the proxy for the url
bool should_bypass = false;
if ((bypass_list = proxy_config_get_bypass_list()) != NULL)
should_bypass = should_bypass_proxy(url, bypass_list);
bypass_list = proxy_config_get_bypass_list();
should_bypass = should_bypass_proxy(url, bypass_list);
if (should_bypass) {
// Bypass the proxy for the url
LOG_INFO("Bypassing proxy for %s (%s)\n", url, bypass_list);
LOG_INFO("Bypassing proxy for %s (%s)\n", url, bypass_list ? bypass_list : "null");
proxy_resolver->list = strdup("direct://");
} else {
// Use proxy from settings
Expand Down
6 changes: 3 additions & 3 deletions resolver_win8.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ bool proxy_resolver_win8_get_proxies_for_url(void *ctx, const char *url) {
if ((proxy = proxy_config_get_proxy(scheme)) != NULL) {
// Check to see if we need to bypass the proxy for the url
bool should_bypass = false;
if ((bypass_list = proxy_config_get_bypass_list()) != NULL)
should_bypass = should_bypass_proxy(url, bypass_list);
bypass_list = proxy_config_get_bypass_list();
should_bypass = should_bypass_proxy(url, bypass_list);
if (should_bypass) {
// Bypass the proxy for the url
LOG_INFO("Bypassing proxy for %s (%s)\n", url, bypass_list);
LOG_INFO("Bypassing proxy for %s (%s)\n", url, bypass_list ? bypass_list : "null");
proxy_resolver->list = strdup("direct://");
} else {
// Use proxy from settings
Expand Down
6 changes: 3 additions & 3 deletions resolver_winxp.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ bool proxy_resolver_winxp_get_proxies_for_url(void *ctx, const char *url) {
if ((proxy = proxy_config_get_proxy(scheme)) != NULL) {
// Check to see if we need to bypass the proxy for the url
bool should_bypass = false;
if ((bypass_list = proxy_config_get_bypass_list()) != NULL)
should_bypass = should_bypass_proxy(url, bypass_list);
bypass_list = proxy_config_get_bypass_list();
should_bypass = should_bypass_proxy(url, bypass_list);
if (should_bypass) {
// Bypass the proxy for the url
LOG_INFO("Bypassing proxy for %s (%s)\n", url, bypass_list);
LOG_INFO("Bypassing proxy for %s (%s)\n", url, bypass_list ? bypass_list : "null");
proxy_resolver->list = strdup("direct://");
} else {
// Use proxy from settings
Expand Down
5 changes: 4 additions & 1 deletion test/test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,18 @@ struct should_bypass_list_param {
bool expected;

friend std::ostream &operator<<(std::ostream &os, const should_bypass_list_param &param) {
return os << "url: " << param.url << std::endl << "bypass list: " << param.bypass_list;
return os << "url: " << param.url << std::endl
<< "bypass list: " << (param.bypass_list ? param.bypass_list : "<null>");
}
};

constexpr should_bypass_list_param should_bypass_list_tests[] = {
// Bypass due to localhost hostname
{"http://localhost/", "", true},
{"http://localhost/", nullptr, true},
// Bypass due to localhost ip
{"http://127.0.0.1/", "", true},
{"http://127.0.0.1/", nullptr, true},
// Bypass due to <local> on simple hostnames
{"http://apple/", "<local>", true},
// Don't bypass due to <local> only applying to simple hostnames
Expand Down
13 changes: 8 additions & 5 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ bool should_bypass_proxy(const char *url, const char *bypass_list) {
bool is_simple = false;
bool should_bypass = false;

if (!url || !bypass_list)
if (!url)
return true;

// Chromium documentation for proxy bypass rules:
Expand All @@ -443,14 +443,17 @@ bool should_bypass_proxy(const char *url, const char *bypass_list) {
if (strcmp(host, "127.0.0.1") == 0 || strcasecmp(host, "localhost") == 0)
is_local = true;

// Check for simple hostnames
if (strchr(host, '.') == NULL)
is_simple = true;

// By default don't allow localhost urls to go through proxy
if (is_local)
should_bypass = true;

if (!bypass_list)
return should_bypass;

// Check for simple hostnames
if (strchr(host, '.') == NULL)
is_simple = true;

// Enumerate through each bypass expression in the bypass list
const char *bypass_list_end = bypass_list + strlen(bypass_list);
const char *rule_start = bypass_list;
Expand Down

0 comments on commit a051187

Please sign in to comment.