Skip to content

Commit

Permalink
http/httpproxy: match http scheme when selecting http_proxy
Browse files Browse the repository at this point in the history
Protocol specific proxies must match based on scheme.

If the https proxy is no configured, and the proxy for a https URL is
requested, no proxy should be returned.

Updates golang/go#40909

Change-Id: I62dfcf95d819c634e8f2862e891877a4eb55fca7
Reviewed-on: https://go-review.googlesource.com/c/net/+/249440
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
  • Loading branch information
fraenkel authored and neild committed Oct 16, 2020
1 parent 4f7140c commit 7b1cca2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 2 additions & 4 deletions http/httpproxy/proxy.go
Expand Up @@ -27,8 +27,7 @@ import (
type Config struct {
// HTTPProxy represents the value of the HTTP_PROXY or
// http_proxy environment variable. It will be used as the proxy
// URL for HTTP requests and HTTPS requests unless overridden by
// HTTPSProxy or NoProxy.
// URL for HTTP requests unless overridden by NoProxy.
HTTPProxy string

// HTTPSProxy represents the HTTPS_PROXY or https_proxy
Expand Down Expand Up @@ -129,8 +128,7 @@ func (cfg *config) proxyForURL(reqURL *url.URL) (*url.URL, error) {
var proxy *url.URL
if reqURL.Scheme == "https" {
proxy = cfg.httpsProxy
}
if proxy == nil {
} else if reqURL.Scheme == "http" {
proxy = cfg.httpProxy
if proxy != nil && cfg.CGI {
return nil, errors.New("refusing to use HTTP_PROXY value in CGI environment; see golang.org/s/cgihttpproxy")
Expand Down
12 changes: 12 additions & 0 deletions http/httpproxy/proxy_test.go
Expand Up @@ -111,6 +111,18 @@ var proxyForURLTests = []proxyForURLTest{{
},
req: "https://secure.tld/",
want: "https://secure.proxy.tld",
}, {
cfg: httpproxy.Config{
HTTPProxy: "http.proxy.tld",
},
req: "https://secure.tld/",
want: "<nil>",
}, {
cfg: httpproxy.Config{
HTTPProxy: "http.proxy.tld",
},
req: "ftp://insecure.tld/",
want: "<nil>",
}, {
// Issue 16405: don't use HTTP_PROXY in a CGI environment,
// where HTTP_PROXY can be attacker-controlled.
Expand Down

0 comments on commit 7b1cca2

Please sign in to comment.