Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(deps): update module github.com/labstack/echo/v5 to v5.3.1 (#20986)

renovate[bot]faacab5a06f1
diff --git a/backend/api/oauth2/oauth2.go b/backend/api/oauth2/oauth2.go
index 89b84d7c45..d91fd09c02 100644
--- a/backend/api/oauth2/oauth2.go
+++ b/backend/api/oauth2/oauth2.go
@@ -15,6 +15,7 @@ import (
"time"
"github.com/labstack/echo/v5"
+ "github.com/labstack/echo/v5/middleware"
"golang.org/x/crypto/bcrypt"
"github.com/bytebase/bytebase/backend/api/auth"
@@ -33,6 +34,13 @@ const (
accessTokenExpiry = 1 * time.Hour
refreshTokenExpiry = 30 * 24 * time.Hour
clientInactiveExpiry = 30 * 24 * time.Hour
+
+ // maxOAuth2BodyBytes caps request bodies on the OAuth2 POST routes. Echo's
+ // default JSON deserializer buffers the whole body in memory before
+ // unmarshalling, and /register is unauthenticated, so bodies must be
+ // bounded before Bind. OAuth2 payloads (RFC 7591 client metadata, RFC 6749
+ // token/revoke forms) are at most a few KB; 64 KB is generous.
+ maxOAuth2BodyBytes = 64 << 10
)
type Service struct {
@@ -60,23 +68,24 @@ func (s *Service) RegisterRoutes(e *echo.Echo) {
// authorization code / refresh token (set at consent time from the
// user's session), not on the URL or the client. Same routes serve
// self-hosted and SaaS.
- e.POST("/api/oauth2/register", s.handleRegister)
+ bodyLimit := middleware.BodyLimit(maxOAuth2BodyBytes)
+ e.POST("/api/oauth2/register", s.handleRegister, bodyLimit)
e.GET("/api/oauth2/authorize", s.handleAuthorizeGet)
- e.POST("/api/oauth2/authorize", s.handleAuthorizePost)
+ e.POST("/api/oauth2/authorize", s.handleAuthorizePost, bodyLimit)
e.GET("/api/oauth2/clients/:clientID", s.handleGetClient)
- e.POST("/api/oauth2/token", s.handleToken)
- e.POST("/api/oauth2/revoke", s.handleRevoke)
+ e.POST("/api/oauth2/token", s.handleToken, bodyLimit)
+ e.POST("/api/oauth2/revoke", s.handleRevoke, bodyLimit)
// Workspace-scoped routes are kept for backward compatibility with any
// client that hardcoded the older URL shape. The :workspaceID segment
// is now informational — workspace resolution comes from the session
// at consent time, just like the unscoped routes above.
- e.POST("/api/workspaces/:workspaceID/oauth2/register", s.handleRegister)
+ e.POST("/api/workspaces/:workspaceID/oauth2/register", s.handleRegister, bodyLimit)
e.GET("/api/workspaces/:workspaceID/oauth2/authorize", s.handleAuthorizeGet)
- e.POST("/api/workspaces/:workspaceID/oauth2/authorize", s.handleAuthorizePost)
+ e.POST("/api/workspaces/:workspaceID/oauth2/authorize", s.handleAuthorizePost, bodyLimit)
e.GET("/api/workspaces/:workspaceID/oauth2/clients/:clientID", s.handleGetClient)
- e.POST("/api/workspaces/:workspaceID/oauth2/token", s.handleToken)
- e.POST("/api/workspaces/:workspaceID/oauth2/revoke", s.handleRevoke)
+ e.POST("/api/workspaces/:workspaceID/oauth2/token", s.handleToken, bodyLimit)
+ e.POST("/api/workspaces/:workspaceID/oauth2/revoke", s.handleRevoke, bodyLimit)
}
// handleGetClient returns public client info for the consent page.
diff --git a/backend/api/oauth2/register_test.go b/backend/api/oauth2/register_test.go
new file mode 100644
index 0000000000..d416d26889
--- /dev/null
+++ b/backend/api/oauth2/register_test.go
@@ -0,0 +1,40 @@
+package oauth2
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+
+ "github.com/labstack/echo/v5"
+ "github.com/stretchr/testify/require"
+
+ "github.com/bytebase/bytebase/backend/component/config"
+)
+
+// TestRegisterBodyLimit verifies that oversized request bodies are rejected
+// before JSON binding. Echo's default JSON deserializer buffers the whole
+// body in memory and /register is unauthenticated, so the route-level
+// BodyLimit middleware is the only thing bounding attacker-controlled
+// allocation on this endpoint.
+func TestRegisterBodyLimit(t *testing.T) {
+ s := &Service{profile: &config.Profile{ExternalURL: "https://bb.example.com"}}
+ e := echo.New()
+ s.RegisterRoutes(e)
+
+ oversized := `{"client_name":"` + strings.Repeat("a", maxOAuth2BodyBytes) + `"}`
+ req := httptest.NewRequest(http.MethodPost, "/api/oauth2/register", strings.NewReader(oversized))
+ req.Header.Set("Content-Type", "application/json")
+ rec := httptest.NewRecorder()
+ e.ServeHTTP(rec, req)
+ require.Equal(t, http.StatusRequestEntityTooLarge, rec.Code)
+
+ // A body under the limit must pass the middleware and reach the handler.
+ // Malformed JSON keeps the handler from touching the (nil) store while
+ // still proving the request was bound rather than rejected on size.
+ req = httptest.NewRequest(http.MethodPost, "/api/oauth2/register", strings.NewReader("{not json"))
+ req.Header.Set("Content-Type", "application/json")
+ rec = httptest.NewRecorder()
+ e.ServeHTTP(rec, req)
+ require.Equal(t, http.StatusBadRequest, rec.Code)
+}
diff --git a/go.mod b/go.mod
index 086f306540..3be299199f 100644
--- a/go.mod
+++ b/go.mod
@@ -321,7 +321,7 @@ require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/klauspost/compress v1.19.0 // indirect
- github.com/labstack/echo/v5 v5.2.1
+ github.com/labstack/echo/v5 v5.3.1
github.com/lufia/plan9stats v0.0.0-20260330125221-c963978e514e // indirect
github.com/openark/golib v0.0.0-20210531070646-355f37940af8
github.com/opentracing/basictracer-go v1.1.0 // indirect
diff --git a/go.sum b/go.sum
index 82fd82bc25..d1426134e5 100644
--- a/go.sum
+++ b/go.sum
@@ -684,8 +684,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/labstack/echo-contrib/v5 v5.0.1 h1:Z23m8p1F9Doax+pa8ek8ll5d6wvzCbvrAn25ZWmSgrE=
github.com/labstack/echo-contrib/v5 v5.0.1/go.mod h1:ajrqEwSloW0vQSTfJ4j9u4tHoS+dg4umCDPxuTvChZs=
-github.com/labstack/echo/v5 v5.2.1 h1:TzpIksY6zLMzV0T0ycYbvTEoj9w6o6AcL5twg182VTY=
-github.com/labstack/echo/v5 v5.2.1/go.mod h1:SyvlSdObGjRXeQfCCXW/sybkZdOOQZBmpKF0bvALaeo=
+github.com/labstack/echo/v5 v5.3.1 h1:75maCxkQVGualckLc/5s/ihgpH1a1Dc6AuGWNVNs6bw=
+github.com/labstack/echo/v5 v5.3.1/go.mod h1:4iEGNQiPPZnkfYpNR/L6fINd3NLiGWUD5+eBotFALas=
github.com/lib/pq v0.0.0-20180327071824-d34b9ff171c2/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=