Skip to content

Commit 7b1cca2

Browse files
fraenkelneild
authored andcommitted
http/httpproxy: match http scheme when selecting http_proxy
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 <[email protected]> Reviewed-by: Damien Neil <[email protected]>
1 parent 4f7140c commit 7b1cca2

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

http/httpproxy/proxy.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ import (
2727
type Config struct {
2828
// HTTPProxy represents the value of the HTTP_PROXY or
2929
// http_proxy environment variable. It will be used as the proxy
30-
// URL for HTTP requests and HTTPS requests unless overridden by
31-
// HTTPSProxy or NoProxy.
30+
// URL for HTTP requests unless overridden by NoProxy.
3231
HTTPProxy string
3332

3433
// HTTPSProxy represents the HTTPS_PROXY or https_proxy
@@ -129,8 +128,7 @@ func (cfg *config) proxyForURL(reqURL *url.URL) (*url.URL, error) {
129128
var proxy *url.URL
130129
if reqURL.Scheme == "https" {
131130
proxy = cfg.httpsProxy
132-
}
133-
if proxy == nil {
131+
} else if reqURL.Scheme == "http" {
134132
proxy = cfg.httpProxy
135133
if proxy != nil && cfg.CGI {
136134
return nil, errors.New("refusing to use HTTP_PROXY value in CGI environment; see golang.org/s/cgihttpproxy")

http/httpproxy/proxy_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ var proxyForURLTests = []proxyForURLTest{{
111111
},
112112
req: "https://secure.tld/",
113113
want: "https://secure.proxy.tld",
114+
}, {
115+
cfg: httpproxy.Config{
116+
HTTPProxy: "http.proxy.tld",
117+
},
118+
req: "https://secure.tld/",
119+
want: "<nil>",
120+
}, {
121+
cfg: httpproxy.Config{
122+
HTTPProxy: "http.proxy.tld",
123+
},
124+
req: "ftp://insecure.tld/",
125+
want: "<nil>",
114126
}, {
115127
// Issue 16405: don't use HTTP_PROXY in a CGI environment,
116128
// where HTTP_PROXY can be attacker-controlled.

0 commit comments

Comments
 (0)