Skip to content

Commit

Permalink
Ensure proxy passed in X-Upstream-Https-Proxy is parsable
Browse files Browse the repository at this point in the history
  • Loading branch information
gauthamw-stripe committed Sep 4, 2024
1 parent 85c4c64 commit 5903b15
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/smokescreen/smokescreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,9 @@ func checkACLsForRequest(config *Config, req *http.Request, destination hostport

if connectProxyHost != "" {
connectProxyUrl, err := url.Parse(connectProxyHost)
if err == nil && connectProxyUrl.Hostname() == "" {
err = errors.New("proxy header contains invalid URL. The correct format is https://[username:password@]my.proxy.srv:12345")
}

if err != nil {
config.Log.WithFields(logrus.Fields{
Expand Down
28 changes: 28 additions & 0 deletions pkg/smokescreen/smokescreen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,34 @@ func TestCONNECTProxyACLs(t *testing.T) {
r.Equal(false, entry.Data["allow"])
})

t.Run("Blocks if proxy can't be parsed when the X-Upstream-Https-Proxy header is set", func(t *testing.T) {
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("OK"))
})
r := require.New(t)
l, err := net.Listen("tcp", "localhost:0")
r.NoError(err)
cfg, err := testConfig("test-external-connect-proxy-blocked-srv")
r.NoError(err)
cfg.Listener = l

err = cfg.SetAllowAddresses([]string{"127.0.0.1"})
r.NoError(err)

internalToStripeProxy := proxyServer(cfg)
remote := httptest.NewTLSServer(h)

client, err := proxyClientWithConnectHeaders(internalToStripeProxy.URL, http.Header{"X-Upstream-Https-Proxy": []string{"google.com"}})
r.NoError(err)

req, err := http.NewRequest("GET", remote.URL, nil)
r.NoError(err)

_, err = client.Do(req)
r.Error(err)
r.Contains(err.Error(), "Request rejected by proxy")
})

t.Run("Allows an approved proxy when the X-Upstream-Https-Proxy header is set", func(t *testing.T) {
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("OK"))
Expand Down

0 comments on commit 5903b15

Please sign in to comment.