Skip to content

Modern Docker Management, Designed for Everyone

fix: strip `TE: trailers` header to prevent false grpc requests (#2026)

Kyle Mendell20692cccd1fe
diff --git a/backend/internal/bootstrap/bootstrap.go b/backend/internal/bootstrap/bootstrap.go
index c405d420c..01b0298a4 100644
--- a/backend/internal/bootstrap/bootstrap.go
+++ b/backend/internal/bootstrap/bootstrap.go
@@ -402,12 +402,5 @@ func isTunnelGRPCRequestInternal(r *http.Request) bool {
}
contentType := strings.ToLower(strings.TrimSpace(r.Header.Get("Content-Type")))
- if strings.HasPrefix(contentType, "application/grpc") ||
- strings.HasPrefix(contentType, "application/grpc+") ||
- strings.HasPrefix(contentType, "application/grpc-web") {
- return true
- }
-
- te := strings.ToLower(strings.TrimSpace(r.Header.Get("Te")))
- return r.ProtoMajor >= 2 && strings.Contains(te, "trailers")
+ return strings.HasPrefix(contentType, "application/grpc")
}
diff --git a/backend/internal/bootstrap/bootstrap_test.go b/backend/internal/bootstrap/bootstrap_test.go
index e63055d98..354472621 100644
--- a/backend/internal/bootstrap/bootstrap_test.go
+++ b/backend/internal/bootstrap/bootstrap_test.go
@@ -97,4 +97,20 @@ func TestIsTunnelGRPCRequestInternal(t *testing.T) {
req.Header.Set("Content-Type", "application/grpc")
assert.False(t, isTunnelGRPCRequestInternal(req))
})
+
+ t.Run("does not match http2 post with te trailers and json content-type", func(t *testing.T) {
+ req := httptest.NewRequest(http.MethodPost, "/api/auth/login", nil)
+ req.Header.Set("Content-Type", "application/json")
+ req.Header.Set("Te", "trailers")
+ req.ProtoMajor = 2
+ assert.False(t, isTunnelGRPCRequestInternal(req))
+ })
+
+ t.Run("does not match http2 post with te trailers and form content-type", func(t *testing.T) {
+ req := httptest.NewRequest(http.MethodPost, "/logout", nil)
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ req.Header.Set("Te", "trailers")
+ req.ProtoMajor = 2
+ assert.False(t, isTunnelGRPCRequestInternal(req))
+ })
}