Skip to content

Commit 567114a

Browse files
authored
Don't allow use of http.DefaultTransport with secure socks proxy (#1295)
This PR adds a check that stops usage of `http.DefaultTransport` in secure socks proxy connections.
1 parent 304a9d9 commit 567114a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

backend/proxy/secure_socks_proxy.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var (
4141
Name: "secure_socks_requests_duration",
4242
Help: "Duration of requests to the secure socks proxy",
4343
}, []string{"code", "datasource", "datasource_type"})
44+
errUseOfHTTPDefaultTransport = errors.New("use of the http.DefaultTransport is not allowed with secure proxy")
4445
)
4546

4647
// Client is the main Proxy Client interface.
@@ -90,13 +91,17 @@ func (p *cfgProxyWrapper) SecureSocksProxyEnabled() bool {
9091
return true
9192
}
9293

93-
// ConfigureSecureSocksHTTPProxy takes a http.DefaultTransport and wraps it in a socks5 proxy with TLS
94+
// ConfigureSecureSocksHTTPProxy takes a http.Transport and wraps it in a socks5 proxy with TLS
9495
// if it is enabled on the datasource and the grafana instance
9596
func (p *cfgProxyWrapper) ConfigureSecureSocksHTTPProxy(transport *http.Transport) error {
9697
if !p.SecureSocksProxyEnabled() {
9798
return nil
9899
}
99100

101+
if transport == http.DefaultTransport {
102+
return errUseOfHTTPDefaultTransport
103+
}
104+
100105
dialSocksProxy, err := p.NewSecureSocksProxyContextDialer()
101106
if err != nil {
102107
return err

backend/proxy/secure_socks_proxy_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ func TestNewSecureSocksProxy(t *testing.T) {
109109
require.NoError(t, cli.ConfigureSecureSocksHTTPProxy(&http.Transport{}))
110110
})
111111

112+
t.Run("New socks proxy should fail with expect error with using http.DefaultTransport", func(t *testing.T) {
113+
defaultHTTPTransport, ok := http.DefaultTransport.(*http.Transport)
114+
require.True(t, ok)
115+
err := cli.ConfigureSecureSocksHTTPProxy(defaultHTTPTransport)
116+
require.Equal(t, errUseOfHTTPDefaultTransport, err)
117+
})
118+
112119
t.Run("Client cert must be valid", func(t *testing.T) {
113120
clientCertBefore := opts.ClientCfg.ClientCertVal
114121
opts.ClientCfg.ClientCertVal = ""

0 commit comments

Comments
 (0)