CVE-2022-29188 (published 2022-05-21T00:15Z)

Smokescreen is an HTTP proxy. The primary use case for Smokescreen is to prevent server-side request forgery (SSRF) attacks in which external attackers leverage the behavior of applications to connect to or scan internal infrastructure. Smokescreen also offers an option to deny access to additional (e.g., external) URLs by way of a deny list. There was an issue in Smokescreen that made it possible to bypass the deny list feature by surrounding the hostname with square brackets (e.g. `[example.com]`). This only impacted the HTTP proxy functionality of Smokescreen. HTTPS requests were not impacted. Smokescreen version 0.0.4 contains a patch for this issue.

Severity: MEDIUM
CVSS v2 base score: 6.4 (AV:N/AC:L/Au:N/C:P/I:P/A:N)
CVSS v3 base score: 6.5, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-918
cwe_name: Server-Side Request Forgery (SSRF)
description: The web server receives a URL or similar request from an upstream component and retrieves the contents of this URL, but it does not sufficiently ensure that the request is being sent to the expected destination.
extended_description: By providing URLs to unexpected hosts or ports, attackers can make it appear that the server is sending the request, possibly bypassing access controls such as firewalls that prevent the attackers from accessing the URLs directly. The server can be used as a proxy to conduct port scanning of hosts in internal networks, use other URLs such as that can access documents on the system (using file://), or use other protocols such as gopher:// or tftp://, which may provide greater control over the contents of requests.
         

Fix information:
repo_url: https://github.com/stripe/smokescreen
commit_details: repo_url: https://github.com/stripe/smokescreen
author: Jessica Jiang
author_date: 2022-04-27 19:11:50-07:00
msg: Fix hostname parsing for square brackets
repository: repo_url: https://github.com/stripe/smokescreen
repo_name: stripe/smokescreen
description: A simple HTTP proxy that fogs over naughty URLs    
repo_language: Go
owner: stripe
file_changes: filename: smokescreen.go
change_type: ModificationType.MODIFY
diff: @@ -457,7 +457,7 @@ func BuildProxy(config *Config) *goproxy.ProxyHttpServer {
 		pctx.RoundTripper = rtFn
 
 		// Build an address parsable by net.ResolveTCPAddr
-		remoteHost := req.Host
+		remoteHost := req.URL.Hostname()
 		if strings.LastIndex(remoteHost, ":") <= strings.LastIndex(remoteHost, "]") {
 			switch req.URL.Scheme {
 			case "http":
@@ -600,7 +600,7 @@ func handleConnect(config *Config, pctx *goproxy.ProxyCtx) error {
 	sctx := pctx.UserData.(*smokescreenContext)
 
 	// Check if requesting role is allowed to talk to remote
-	sctx.decision, sctx.lookupTime, pctx.Error = checkIfRequestShouldBeProxied(config, pctx.Req, pctx.Req.Host)
+	sctx.decision, sctx.lookupTime, pctx.Error = checkIfRequestShouldBeProxied(config, pctx.Req, pctx.Req.URL.Hostname())
 	if pctx.Error != nil {
 		return pctx.Error
 	}

programming_language: Go
filename: smokescreen_test.go
change_type: ModificationType.MODIFY
diff: @@ -107,11 +107,11 @@ func TestClassifyAddr(t *testing.T) {
 	}
 }
 
-func TestUnsafeAllowPrivateRanges (t *testing.T) {
+func TestUnsafeAllowPrivateRanges(t *testing.T) {
 	a := assert.New(t)
 
 	conf := NewConfig()
-	a.NoError(conf.SetDenyRanges([]string {"192.168.0.0/24", "10.0.0.0/8"}))
+	a.NoError(conf.SetDenyRanges([]string{"192.168.0.0/24", "10.0.0.0/8"}))
 	conf.ConnectTimeout = 10 * time.Second
 	conf.ExitTimeout = 10 * time.Second
 	conf.AdditionalErrorMessageOnDeny = "Proxy denied"
@@ -160,7 +160,6 @@ func TestUnsafeAllowPrivateRanges (t *testing.T) {
 		}
 	}
 
-
 }
 
 // TestClearsErrors tests that we are correctly preserving/removing the X-Smokescreen-Error header.
@@ -443,6 +442,52 @@ func TestInvalidHost(t *testing.T) {
 	}
 }
 
+var hostSquareBracketsCases = []struct {
+	scheme    string
+	proxyType string
+}{
+	{"http", "http"},
+	{"https", "connect"},
+}
+
+func TestHostSquareBrackets(t *testing.T) {
+	for _, testCase := range hostSquareBracketsCases {
+		t.Run(testCase.scheme, func(t *testing.T) {
+			a := assert.New(t)
+			r := require.New(t)
+
+			cfg, err := testConfig("test-open-srv")
+			require.NoError(t, err)
+			logHook := proxyLogHook(cfg)
+
+			proxySrv := proxyServer(cfg)
+			defer proxySrv.Close()
+
+			// Create a http.Client that uses our proxy
+			client, err := proxyClient(proxySrv.URL)
+			r.NoError(err)
+
+			resp, err := client.Get(fmt.Sprintf("%s://[stripe.com]", testCase.scheme))
+			if err != nil {
+				r.Contains(err.Error(), "Request rejected by proxy")
+			} else {
+				r.Equal(http.StatusProxyAuthRequired, resp.StatusCode)
+			}
+
+			entry := findCanonicalProxyDecision(logHook.AllEntries())
+			r.NotNil(entry)
+
+			if a.Contains(entry.Data, "allow") {
+				a.Equal(false, entry.Data["allow"])
+				a.Equal("host matched rule in global deny list", entry.Data["decision_reason"])
+			}
+			if a.Contains(entry.Data, "proxy_type") {
+				a.Contains(entry.Data["proxy_type"], testCase.proxyType)
+			}
+		})
+	}
+}
+
 func TestErrorHeader(t *testing.T) {
 	a := assert.New(t)
 	r := require.New(t)

programming_language: Go
filename: acl.yaml
change_type: ModificationType.MODIFY
diff: @@ -1,14 +1,20 @@
 ---
-    version: v1
-    services:
-      - name: test-trusted-srv
-        project: security
-        action: enforce
-        allowed_domains:
-          - notarealhost.test
-          - httpbin.org
-      - name: test-local-srv
-        project: security
-        action: open
-        allowed_domains:
-          - 127.0.0.1
+version: v1
+services:
+  - name: test-trusted-srv
+    project: security
+    action: enforce
+    allowed_domains:
+      - notarealhost.test
+      - httpbin.org
+  - name: test-local-srv
+    project: security
+    action: open
+    allowed_domains:
+      - 127.0.0.1
+  - name: test-open-srv
+    project: security
+    action: open
+
+global_deny_list:
+  - stripe.com

programming_language: Markdown