Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(deps): update module github.com/labstack/echo-contrib to v0.50.0 (#19033)
renovate[bot]eeed418b2ed6
diff --git a/backend/api/directory-sync/webhook.go b/backend/api/directory-sync/webhook.goindex 32c3a98894..898d0b591a 100644--- a/backend/api/directory-sync/webhook.go+++ b/backend/api/directory-sync/webhook.go@@ -16,7 +16,7 @@ import ("github.com/pkg/errors""golang.org/x/crypto/bcrypt"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5"v1api "github.com/bytebase/bytebase/backend/api/v1""github.com/bytebase/bytebase/backend/common"@@ -34,7 +34,7 @@ const (// detectSCIMSource detects the identity provider source based on User-Agent header.// Okta sends "Okta SCIM Client" in User-Agent, Azure sends "Azure" or "Microsoft".-func detectSCIMSource(c echo.Context) string {+func detectSCIMSource(c *echo.Context) string {userAgent := c.Request().Header.Get("User-Agent")userAgentLower := strings.ToLower(userAgent)if strings.Contains(userAgentLower, "okta") {@@ -45,7 +45,7 @@ func detectSCIMSource(c echo.Context) string {// scimAuthMiddleware validates authentication and license for all SCIM endpoints.func (s *Service) scimAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc {- return func(c echo.Context) error {+ return func(c *echo.Context) error {ctx := c.Request().Context()if err := s.validRequestURL(ctx, c); err != nil {return c.String(http.StatusUnauthorized, err.Error())@@ -68,7 +68,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {// ServiceProviderConfig endpoint allows SCIM clients to discover server capabilities.// This is required by Okta and recommended by the SCIM 2.0 specification.// Docs: https://datatracker.ietf.org/doc/html/rfc7644#section-4- g.GET("/workspaces/:workspaceID/ServiceProviderConfig", func(c echo.Context) error {+ g.GET("/workspaces/:workspaceID/ServiceProviderConfig", func(c *echo.Context) error {config := &ServiceProviderConfig{Schemas: []string{"urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig",@@ -106,7 +106,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {return c.JSON(http.StatusOK, config)})- g.POST("/workspaces/:workspaceID/Users", func(c echo.Context) error {+ g.POST("/workspaces/:workspaceID/Users", func(c *echo.Context) error {ctx := c.Request().Context()source := detectSCIMSource(c)@@ -164,7 +164,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {})// Get a single user. The user id is the Bytebase user uid.- g.GET("/workspaces/:workspaceID/Users/:userID", func(c echo.Context) error {+ g.GET("/workspaces/:workspaceID/Users/:userID", func(c *echo.Context) error {ctx := c.Request().Context()slog.Debug("get user", slog.String("source", detectSCIMSource(c)), slog.String("id", c.Param("userID")))@@ -186,7 +186,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {// userName maps to userPrincipalName in Azure or login in Okta, which is typically the user's email.// Docs: https://learn.microsoft.com/en-us/entra/identity/app-provisioning/use-scim-to-provision-users-and-groups#get-user-by-query// Docs: https://developer.okta.com/docs/reference/scim/scim-20/- g.GET("/workspaces/:workspaceID/Users", func(c echo.Context) error {+ g.GET("/workspaces/:workspaceID/Users", func(c *echo.Context) error {ctx := c.Request().Context()response := &ListUsersResponse{Schemas: []string{@@ -250,7 +250,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {return c.JSON(http.StatusOK, response)})- g.DELETE("/workspaces/:workspaceID/Users/:userID", func(c echo.Context) error {+ g.DELETE("/workspaces/:workspaceID/Users/:userID", func(c *echo.Context) error {ctx := c.Request().Context()slog.Debug("delete user", slog.String("source", detectSCIMSource(c)), slog.String("id", c.Param("userID")))@@ -277,7 +277,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {// PUT replaces the entire user resource. Required by SCIM 2.0 (RFC 7644 Section 3.5.1).// Body format is same as POST (full SCIMUser object).- g.PUT("/workspaces/:workspaceID/Users/:userID", func(c echo.Context) error {+ g.PUT("/workspaces/:workspaceID/Users/:userID", func(c *echo.Context) error {ctx := c.Request().Context()slog.Debug("put user", slog.String("source", detectSCIMSource(c)), slog.String("id", c.Param("userID")))@@ -311,7 +311,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {return c.JSON(http.StatusOK, convertToSCIMUser(updatedUser))})- g.PATCH("/workspaces/:workspaceID/Users/:userID", func(c echo.Context) error {+ g.PATCH("/workspaces/:workspaceID/Users/:userID", func(c *echo.Context) error {ctx := c.Request().Context()slog.Debug("patch user", slog.String("source", detectSCIMSource(c)), slog.String("id", c.Param("userID")))@@ -434,7 +434,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {return c.JSON(http.StatusOK, convertToSCIMUser(updatedUser))})- g.POST("/workspaces/:workspaceID/Groups", func(c echo.Context) error {+ g.POST("/workspaces/:workspaceID/Groups", func(c *echo.Context) error {ctx := c.Request().Context()source := detectSCIMSource(c)@@ -510,7 +510,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {})// Get a single group. The group id is the Bytebase group resource id.- g.GET("/workspaces/:workspaceID/Groups/:groupID", func(c echo.Context) error {+ g.GET("/workspaces/:workspaceID/Groups/:groupID", func(c *echo.Context) error {ctx := c.Request().Context()slog.Debug("get group", slog.String("source", detectSCIMSource(c)), slog.String("id", c.Param("groupID")))@@ -536,7 +536,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {// - Legacy mapping: mail -> externalId (for backward compatibility)// Docs: https://learn.microsoft.com/en-us/entra/identity/app-provisioning/use-scim-to-provision-users-and-groups#get-group-by-query// Docs: https://developer.okta.com/docs/reference/scim/scim-20/- g.GET("/workspaces/:workspaceID/Groups", func(c echo.Context) error {+ g.GET("/workspaces/:workspaceID/Groups", func(c *echo.Context) error {ctx := c.Request().Context()response := &ListGroupsResponse{Schemas: []string{@@ -585,7 +585,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {return c.JSON(http.StatusOK, response)})- g.DELETE("/workspaces/:workspaceID/Groups/:groupID", func(c echo.Context) error {+ g.DELETE("/workspaces/:workspaceID/Groups/:groupID", func(c *echo.Context) error {ctx := c.Request().Context()slog.Debug("delete group", slog.String("source", detectSCIMSource(c)), slog.String("id", c.Param("groupID")))@@ -615,7 +615,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {// PUT replaces the entire group resource. Required by SCIM 2.0 (RFC 7644 Section 3.5.1).// Body format is same as POST (full SCIMGroup object).- g.PUT("/workspaces/:workspaceID/Groups/:groupID", func(c echo.Context) error {+ g.PUT("/workspaces/:workspaceID/Groups/:groupID", func(c *echo.Context) error {ctx := c.Request().Context()source := detectSCIMSource(c)slog.Debug("put group", slog.String("source", source), slog.String("id", c.Param("groupID")))@@ -655,7 +655,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {return c.JSON(http.StatusOK, convertToSCIMGroup(updatedGroup))})- g.PATCH("/workspaces/:workspaceID/Groups/:groupID", func(c echo.Context) error {+ g.PATCH("/workspaces/:workspaceID/Groups/:groupID", func(c *echo.Context) error {ctx := c.Request().Context()source := detectSCIMSource(c)slog.Debug("patch group", slog.String("source", source), slog.String("id", c.Param("groupID")))@@ -825,7 +825,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {})}-func (s *Service) validRequestURL(ctx context.Context, c echo.Context) error {+func (s *Service) validRequestURL(ctx context.Context, c *echo.Context) error {authorization := strings.TrimPrefix(c.Request().Header.Get("Authorization"), "Bearer ")if authorization == "" {return errors.Errorf("missing authorization token")@@ -856,7 +856,7 @@ func (s *Service) validRequestURL(ctx context.Context, c echo.Context) error {return nil}-func (s *Service) getUser(ctx context.Context, c echo.Context) (*store.UserMessage, error) {+func (s *Service) getUser(ctx context.Context, c *echo.Context) (*store.UserMessage, error) {uid, err := strconv.Atoi(c.Param("userID"))if err != nil {return nil, errors.Errorf("failed to parse user id %v, error %v", c.Param("userID"), err)@@ -869,7 +869,7 @@ func (s *Service) getUser(ctx context.Context, c echo.Context) (*store.UserMessareturn user, nil}-func (s *Service) getGroup(ctx context.Context, c echo.Context) (*store.GroupMessage, error) {+func (s *Service) getGroup(ctx context.Context, c *echo.Context) (*store.GroupMessage, error) {groupName, err := decodeGroupIdentifier(c.Param("groupID"))if err != nil {return nil, errors.Errorf("failed to parse group %v, error %v", c.Param("groupID"), err)diff --git a/backend/api/lsp/lsp.go b/backend/api/lsp/lsp.goindex eed8444556..7d181295ff 100644--- a/backend/api/lsp/lsp.go+++ b/backend/api/lsp/lsp.go@@ -8,7 +8,7 @@ import ("time""github.com/gorilla/websocket"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5""github.com/pkg/errors""github.com/sourcegraph/jsonrpc2"@@ -29,7 +29,7 @@ var (})-func (s *Server) Router(c echo.Context) error {+func (s *Server) Router(c *echo.Context) error {// Authenticate user before upgrading WebSocket connectionaccessTokenStr, err := auth.GetTokenFromHeaders(c.Request().Header)if err != nil {@@ -48,13 +48,6 @@ func (s *Server) Router(c echo.Context) error {return errors.Wrap(err, "could not upgrade to WebSocket")}defer connection.Close()- // Register the connection to be closed when the server shuts down.- c.Echo().Server.RegisterOnShutdown(func() {- err := connection.Close()- if err != nil {- slog.Error("Failed to close websocket connection", log.BBError(err))- }- })connectionID := s.connectionCount.Add(1)handler, closer := newHandler(s.store, s.profile, s.iamManager, user, tokenExpiry)diff --git a/backend/api/mcp/server.go b/backend/api/mcp/server.goindex e52df0fb49..b070e8916d 100644--- a/backend/api/mcp/server.go+++ b/backend/api/mcp/server.go@@ -6,7 +6,7 @@ import ("strings""github.com/golang-jwt/jwt/v5"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5""github.com/modelcontextprotocol/go-sdk/mcp""github.com/pkg/errors"@@ -64,7 +64,7 @@ func (s *Server) registerTools() {// authMiddleware validates OAuth2 bearer tokens for MCP requests.func (s *Server) authMiddleware(next echo.HandlerFunc) echo.HandlerFunc {- return func(c echo.Context) error {+ return func(c *echo.Context) error {// Extract Authorization headerauthHeader := c.Request().Header.Get("Authorization")if authHeader == "" {diff --git a/backend/api/mcp/server_test.go b/backend/api/mcp/server_test.goindex 3c9c0f1627..3f9ef20627 100644--- a/backend/api/mcp/server_test.go+++ b/backend/api/mcp/server_test.go@@ -8,7 +8,7 @@ import ("time""github.com/golang-jwt/jwt/v5"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5""github.com/stretchr/testify/require""github.com/bytebase/bytebase/backend/api/auth"@@ -72,14 +72,14 @@ func TestMCPAuthMiddleware(t *testing.T) {// Create server with auths, err := NewServer(nil, profile, secret)require.NoError(t, err)- handler := s.authMiddleware(func(c echo.Context) error {+ handler := s.authMiddleware(func(c *echo.Context) error {return c.String(http.StatusOK, "success")})err = handler(c)if err != nil {// Echo error handler- e.HTTPErrorHandler(err, c)+ echo.DefaultHTTPErrorHandler(true)(c, err)}require.Equal(t, tc.expectedStatus, rec.Code)@@ -103,7 +103,7 @@ func TestMCPAuthMiddlewareValidToken(t *testing.T) {// A full integration test would require a real stores, err := NewServer(nil, profile, secret)require.NoError(t, err)- handler := s.authMiddleware(func(c echo.Context) error {+ handler := s.authMiddleware(func(c *echo.Context) error {// Verify access token is set in request contextctx := c.Request().Context()token := getAccessToken(ctx)diff --git a/backend/api/oauth2/authorize.go b/backend/api/oauth2/authorize.goindex 1d1cf8031c..4e1d9a18a9 100644--- a/backend/api/oauth2/authorize.go+++ b/backend/api/oauth2/authorize.go@@ -9,7 +9,7 @@ import ("time""github.com/golang-jwt/jwt/v5"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5""github.com/pkg/errors""github.com/bytebase/bytebase/backend/api/auth"@@ -18,7 +18,7 @@ import ("github.com/bytebase/bytebase/backend/store")-func (s *Service) handleAuthorizeGet(c echo.Context) error {+func (s *Service) handleAuthorizeGet(c *echo.Context) error {ctx := c.Request().Context()// Parse query parameters@@ -74,7 +74,7 @@ func (s *Service) handleAuthorizeGet(c echo.Context) error {return c.Redirect(http.StatusFound, consentURL)}-func (s *Service) handleAuthorizePost(c echo.Context) error {+func (s *Service) handleAuthorizePost(c *echo.Context) error {ctx := c.Request().Context()// Parse form valuesdiff --git a/backend/api/oauth2/discovery.go b/backend/api/oauth2/discovery.goindex a20417db92..140536f056 100644--- a/backend/api/oauth2/discovery.go+++ b/backend/api/oauth2/discovery.go@@ -6,7 +6,7 @@ import ("net/http""strings"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5""github.com/bytebase/bytebase/backend/common/log""github.com/bytebase/bytebase/backend/utils"@@ -35,7 +35,7 @@ type protectedResourceMetadata struct {// getBaseURL returns the base URL to use for OAuth2 endpoints.// It uses externalURL from profile/setting if configured, otherwise derives from the request.-func (s *Service) getBaseURL(c echo.Context) string {+func (s *Service) getBaseURL(c *echo.Context) string {ctx := c.Request().Context()externalURL, err := utils.GetEffectiveExternalURL(ctx, s.store, s.profile)@@ -59,7 +59,7 @@ func (s *Service) getBaseURL(c echo.Context) string {return fmt.Sprintf("%s://%s", scheme, req.Host)}-func (s *Service) handleDiscovery(c echo.Context) error {+func (s *Service) handleDiscovery(c *echo.Context) error {baseURL := s.getBaseURL(c)metadata := &authorizationServerMetadata{Issuer: baseURL,@@ -77,7 +77,7 @@ func (s *Service) handleDiscovery(c echo.Context) error {// handleProtectedResourceMetadata returns RFC 9728 protected resource metadata.// This tells clients which authorization server protects this resource.-func (s *Service) handleProtectedResourceMetadata(c echo.Context) error {+func (s *Service) handleProtectedResourceMetadata(c *echo.Context) error {baseURL := s.getBaseURL(c)metadata := &protectedResourceMetadata{Resource: baseURL,diff --git a/backend/api/oauth2/oauth2.go b/backend/api/oauth2/oauth2.goindex a8eaab6abe..54960dfe7d 100644--- a/backend/api/oauth2/oauth2.go+++ b/backend/api/oauth2/oauth2.go@@ -12,7 +12,7 @@ import ("slices""time"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5""golang.org/x/crypto/bcrypt""github.com/bytebase/bytebase/backend/api/auth"@@ -63,7 +63,7 @@ func (s *Service) RegisterRoutes(e *echo.Echo) {}// handleGetClient returns public client info for the consent page.-func (s *Service) handleGetClient(c echo.Context) error {+func (s *Service) handleGetClient(c *echo.Context) error {ctx := c.Request().Context()clientID := c.Param("clientID")@@ -155,14 +155,14 @@ func isLocalhostURI(uri string) bool {return host == "localhost" || host == "127.0.0.1" || host == "::1"}-func oauth2Error(c echo.Context, statusCode int, errorCode, description string) error {+func oauth2Error(c *echo.Context, statusCode int, errorCode, description string) error {return c.JSON(statusCode, map[string]string{"error": errorCode,"error_description": description,})}-func oauth2ErrorRedirect(c echo.Context, redirectURI, state, errorCode, description string) error {+func oauth2ErrorRedirect(c *echo.Context, redirectURI, state, errorCode, description string) error {u, err := url.Parse(redirectURI)if err != nil {slog.Error("failed to parse redirect URI for OAuth2 error redirect", slog.String("redirectURI", redirectURI), log.BBError(err))diff --git a/backend/api/oauth2/register.go b/backend/api/oauth2/register.goindex 454cd0afc4..b726eb4e71 100644--- a/backend/api/oauth2/register.go+++ b/backend/api/oauth2/register.go@@ -5,7 +5,7 @@ import ("net/url""slices"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/store"@@ -27,7 +27,7 @@ type clientRegistrationResponse struct {TokenEndpointAuthMethod string `json:"token_endpoint_auth_method"`}-func (s *Service) handleRegister(c echo.Context) error {+func (s *Service) handleRegister(c *echo.Context) error {ctx := c.Request().Context()var req clientRegistrationRequestdiff --git a/backend/api/oauth2/revoke.go b/backend/api/oauth2/revoke.goindex 5b554699dc..31db7b88b1 100644--- a/backend/api/oauth2/revoke.go+++ b/backend/api/oauth2/revoke.go@@ -6,7 +6,7 @@ import ("net/http""strings"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5""github.com/bytebase/bytebase/backend/api/auth""github.com/bytebase/bytebase/backend/common/log"@@ -19,7 +19,7 @@ type revokeRequest struct {ClientSecret string `form:"client_secret"`}-func (s *Service) handleRevoke(c echo.Context) error {+func (s *Service) handleRevoke(c *echo.Context) error {ctx := c.Request().Context()var req revokeRequest@@ -65,7 +65,7 @@ func (s *Service) handleRevoke(c echo.Context) error {return c.NoContent(http.StatusOK)}-func extractRevokeClientCredentials(c echo.Context, req *revokeRequest) (clientID, clientSecret string) {+func extractRevokeClientCredentials(c *echo.Context, req *revokeRequest) (clientID, clientSecret string) {// Try Basic auth firstauthHeader := c.Request().Header.Get("Authorization")if strings.HasPrefix(authHeader, "Basic ") {diff --git a/backend/api/oauth2/token.go b/backend/api/oauth2/token.goindex dc8d795aec..5e42967616 100644--- a/backend/api/oauth2/token.go+++ b/backend/api/oauth2/token.go@@ -8,7 +8,7 @@ import ("strings""time"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5""github.com/bytebase/bytebase/backend/api/auth""github.com/bytebase/bytebase/backend/common/log"@@ -32,7 +32,7 @@ type tokenResponse struct {RefreshToken string `json:"refresh_token,omitempty"`}-func (s *Service) handleToken(c echo.Context) error {+func (s *Service) handleToken(c *echo.Context) error {ctx := c.Request().Context()var req tokenRequest@@ -73,7 +73,7 @@ func (s *Service) handleToken(c echo.Context) error {}}-func (*Service) extractClientCredentials(c echo.Context, req *tokenRequest) (clientID, clientSecret string) {+func (*Service) extractClientCredentials(c *echo.Context, req *tokenRequest) (clientID, clientSecret string) {// Try Basic auth firstauthHeader := c.Request().Header.Get("Authorization")if strings.HasPrefix(authHeader, "Basic ") {@@ -89,7 +89,7 @@ func (*Service) extractClientCredentials(c echo.Context, req *tokenRequest) (clireturn req.ClientID, req.ClientSecret}-func (s *Service) handleAuthorizationCodeGrant(c echo.Context, client *store.OAuth2ClientMessage, req *tokenRequest) error {+func (s *Service) handleAuthorizationCodeGrant(c *echo.Context, client *store.OAuth2ClientMessage, req *tokenRequest) error {ctx := c.Request().Context()// Validate grant type is allowed@@ -153,7 +153,7 @@ func (s *Service) handleAuthorizationCodeGrant(c echo.Context, client *store.OAureturn s.issueTokens(c, client, user.Email)}-func (s *Service) handleRefreshTokenGrant(c echo.Context, client *store.OAuth2ClientMessage, req *tokenRequest) error {+func (s *Service) handleRefreshTokenGrant(c *echo.Context, client *store.OAuth2ClientMessage, req *tokenRequest) error {ctx := c.Request().Context()// Validate grant type is allowed@@ -205,7 +205,7 @@ func (s *Service) handleRefreshTokenGrant(c echo.Context, client *store.OAuth2Clreturn s.issueTokens(c, client, user.Email)}-func (s *Service) issueTokens(c echo.Context, client *store.OAuth2ClientMessage, userEmail string) error {+func (s *Service) issueTokens(c *echo.Context, client *store.OAuth2ClientMessage, userEmail string) error {ctx := c.Request().Context()// Generate access token (JWT)diff --git a/backend/component/export/resources.go b/backend/component/export/resources.goindex 02d5d78cb9..f057cca716 100644--- a/backend/component/export/resources.go+++ b/backend/component/export/resources.go@@ -4,7 +4,7 @@ import ("context""connectrpc.com/connect"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5""github.com/pkg/errors"storepb "github.com/bytebase/bytebase/backend/generated-go/store"@@ -91,7 +91,7 @@ func getResourcesForMySQL(DatabaseName: &databaseName,})if err != nil {- if httpErr, ok := err.(*echo.HTTPError); ok && httpErr.Code == echo.ErrNotFound.Code {+ if httpErr, ok := err.(*echo.HTTPError); ok && httpErr.StatusCode() == echo.ErrNotFound.StatusCode() {return nil, nil}return nil, connect.NewError(connect.CodeInternal, errors.Wrap(err, "failed to fetch database"))diff --git a/backend/server/echo_routes.go b/backend/server/echo_routes.goindex 6f4b7f552c..16e89c64c1 100644--- a/backend/server/echo_routes.go+++ b/backend/server/echo_routes.go@@ -5,10 +5,11 @@ import ("net/http""strings"- "github.com/labstack/echo-contrib/prometheus"- "github.com/labstack/echo/v4"- "github.com/labstack/echo/v4/middleware"+ "github.com/labstack/echo-contrib/echoprometheus"+ "github.com/labstack/echo/v5"+ "github.com/labstack/echo/v5/middleware""github.com/pkg/errors"+ "github.com/prometheus/client_golang/prometheus"connectcors "connectrpc.com/cors"@@ -34,8 +35,8 @@ func configureEchoRouters(if profile.Mode == common.ReleaseModeDev {e.Use(middleware.CORSWithConfig(middleware.CORSConfig{- AllowOriginFunc: func(string) (bool, error) {- return true, nil+ UnsafeAllowOriginFunc: func(_ *echo.Context, origin string) (string, bool, error) {+ return origin, true, nil},AllowMethods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodPatch, http.MethodOptions},AllowHeaders: connectcors.AllowedHeaders(),@@ -48,8 +49,7 @@ func configureEchoRouters(LogURI: true,LogMethod: true,LogStatus: true,- LogError: true,- LogValuesFunc: func(_ echo.Context, values middleware.RequestLoggerValues) error {+ LogValuesFunc: func(_ *echo.Context, values middleware.RequestLoggerValues) error {if values.Error != nil {slog.Error("echo request logger", "method", values.Method, "uri", values.URI, "status", values.Status, log.BBError(values.Error))}@@ -57,18 +57,19 @@ func configureEchoRouters(},}))- e.HideBanner = true- e.HidePort = true-registerPprof(e, &profile.RuntimeDebug)- p := prometheus.NewPrometheus("api", nil)- p.RequestCounterURLLabelMappingFunc = func(c echo.Context) string {- return c.Request().URL.Path- }- p.Use(e)+ // Prometheus metrics - use custom registry to avoid duplicate registration in tests+ registry := prometheus.NewRegistry()+ e.Use(echoprometheus.NewMiddlewareWithConfig(echoprometheus.MiddlewareConfig{+ Subsystem: "api",+ Registerer: registry,+ }))+ e.GET("/metrics", echoprometheus.NewHandlerWithConfig(echoprometheus.HandlerConfig{+ Gatherer: registry,+ }))- e.GET("/healthz", func(c echo.Context) error {+ e.GET("/healthz", func(c *echo.Context) error {return c.String(http.StatusOK, "OK")})@@ -90,7 +91,7 @@ func configureEchoRouters(}func recoverMiddleware(next echo.HandlerFunc) echo.HandlerFunc {- return func(c echo.Context) error {+ return func(c *echo.Context) error {defer func() {if r := recover(); r != nil {err, ok := r.(error)@@ -99,7 +100,13 @@ func recoverMiddleware(next echo.HandlerFunc) echo.HandlerFunc {}slog.Error("Middleware PANIC RECOVER", log.BBError(err), log.BBStack("panic-stack"))- c.Error(err)+ // In Echo v5, send error response directly+ resp, unwrapErr := echo.UnwrapResponse(c.Response())+ if unwrapErr == nil && !resp.Committed {+ _ = c.JSON(http.StatusInternalServerError, map[string]string{+ "error": "Internal server error",+ })+ }}}()return next(c)@@ -127,7 +134,7 @@ func securityHeadersMiddleware(next echo.HandlerFunc) echo.HandlerFunc {"form-action 'self'; " +"frame-ancestors 'self'"- return func(c echo.Context) error {+ return func(c *echo.Context) error {// Allow popups to maintain window.opener for OAuth flowsc.Response().Header().Set("Cross-Origin-Opener-Policy", "same-origin-allow-popups")// Prevent being embedded in iframes from different originsdiff --git a/backend/server/grpc_routes.go b/backend/server/grpc_routes.goindex 9763467e2e..1efac1d2e5 100644--- a/backend/server/grpc_routes.go+++ b/backend/server/grpc_routes.go@@ -15,7 +15,7 @@ import ("connectrpc.com/grpcreflect""connectrpc.com/validate"grpcruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5""github.com/pkg/errors""github.com/tmc/grpc-websocket-proxy/wsproxy"diff --git a/backend/server/pprof.go b/backend/server/pprof.goindex 2dba948495..e908da8f0d 100644--- a/backend/server/pprof.go+++ b/backend/server/pprof.go@@ -5,17 +5,17 @@ import ("net/http/pprof""sync/atomic"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5")func registerPprof(e *echo.Echo, runtimeDebug *atomic.Bool) {router := e.Group("/debug/pprof")handler := func(h http.HandlerFunc) echo.HandlerFunc {- return func(c echo.Context) error {+ return func(c *echo.Context) error {if !runtimeDebug.Load() {- return echo.NewHTTPError(echo.ErrNotFound.Code, "")+ return echo.NewHTTPError(echo.ErrNotFound.StatusCode(), "")}- h.ServeHTTP(c.Response().Writer, c.Request())+ h.ServeHTTP(c.Response(), c.Request())return nil}}diff --git a/backend/server/server.go b/backend/server/server.goindex 36bf7dd08d..df8cb931e1 100644--- a/backend/server/server.go+++ b/backend/server/server.go@@ -11,9 +11,10 @@ import ("sync""time"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5""github.com/pkg/errors""golang.org/x/net/http2"+ "golang.org/x/net/http2/h2c"directorysync "github.com/bytebase/bytebase/backend/api/directory-sync""github.com/bytebase/bytebase/backend/api/lsp"@@ -74,6 +75,7 @@ type Server struct {profile *config.ProfileechoServer *echo.Echo+ httpServer *http.ServerlspServer *lsp.Serverstore *store.StoredbFactory *dbfactory.DBFactory@@ -281,10 +283,14 @@ func (s *Server) Run(ctx context.Context, port int) error {return err}- s.echoServer.Listener = listener+ // Create HTTP server with H2C support (Echo v5)+ s.httpServer = &http.Server{+ Addr: address,+ Handler: h2c.NewHandler(s.echoServer, &http2.Server{}),+ }go func() {- if err := s.echoServer.StartH2CServer(address, &http2.Server{}); err != nil {+ if err := s.httpServer.Serve(listener); err != nil {if !errors.Is(err, http.ErrServerClosed) {slog.Error("http server listen error", log.BBError(err))}@@ -307,10 +313,10 @@ func (s *Server) Shutdown(ctx context.Context) error {s.cancel()}- // Shutdown echo- if s.echoServer != nil {- if err := s.echoServer.Shutdown(ctx); err != nil {- s.echoServer.Logger.Fatal(err)+ // Shutdown HTTP server+ if s.httpServer != nil {+ if err := s.httpServer.Shutdown(ctx); err != nil {+ slog.Error("Failed to shutdown HTTP server", log.BBError(err))}}diff --git a/backend/server/server_frontend_embed.go b/backend/server/server_frontend_embed.goindex a0d7b581e1..fc9ec4df62 100644--- a/backend/server/server_frontend_embed.go+++ b/backend/server/server_frontend_embed.go@@ -10,8 +10,8 @@ import ("net/http""sync"- "github.com/labstack/echo/v4"- "github.com/labstack/echo/v4/middleware"+ "github.com/labstack/echo/v5"+ "github.com/labstack/echo/v5/middleware""github.com/bytebase/bytebase/backend/common")@@ -92,7 +92,7 @@ func embedFrontend(e *echo.Echo) {}))g.Use(func(next echo.HandlerFunc) echo.HandlerFunc {- return func(c echo.Context) error {+ return func(c *echo.Context) error {c.Response().Header().Set(echo.HeaderCacheControl, "max-age=31536000, immutable")return next(c)}diff --git a/backend/server/server_frontend_not_embed.go b/backend/server/server_frontend_not_embed.goindex 18be0ca799..d78dca251d 100644--- a/backend/server/server_frontend_not_embed.go+++ b/backend/server/server_frontend_not_embed.go@@ -6,7 +6,7 @@ import ("log/slog""net/http"- "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v5")// loadCSPHashes returns empty hashes in dev mode since frontend is served separately.@@ -17,7 +17,7 @@ func loadCSPHashes() []string {func embedFrontend(e *echo.Echo) {slog.Info("Skip embedding frontend, build with 'embed_frontend' tag if you want embedded frontend.")- e.GET("/*", func(c echo.Context) error {+ e.GET("/*", func(c *echo.Context) error {return c.HTML(http.StatusOK, "This Bytebase build does not bundle frontend and backend together.")})}diff --git a/go.mod b/go.modindex 442004fdbb..eae2e3cc51 100644--- a/go.mod+++ b/go.mod@@ -61,8 +61,7 @@ require (github.com/jackc/pgconn v1.14.3github.com/jackc/pgtype v1.14.4github.com/jackc/pgx/v5 v5.8.0- github.com/labstack/echo-contrib v0.17.4- github.com/labstack/echo/v4 v4.13.3+ github.com/labstack/echo-contrib v0.50.0github.com/lestrrat-go/jwx/v3 v3.0.13github.com/lib/pq v1.10.9github.com/lor00x/goldap v0.0.0-20240304151906-8d785c64d1c8@@ -266,7 +265,7 @@ require (go.opentelemetry.io/otel/sdk/metric v1.39.0 // indirectgo.opentelemetry.io/proto/otlp v1.7.0 // indirectgo.uber.org/zap v1.27.0 // indirect- go.yaml.in/yaml/v2 v2.4.2 // indirect+ go.yaml.in/yaml/v2 v2.4.3 // indirectgo.yaml.in/yaml/v3 v3.0.4 // indirectgo.yaml.in/yaml/v4 v4.0.0-rc.3 // indirectgolang.org/x/exp v0.0.0-20251125195548-87e1e737ad39 // indirect@@ -333,12 +332,10 @@ require (github.com/jackc/pgpassfile v1.0.0 // indirectgithub.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirectgithub.com/klauspost/compress v1.18.1 // indirect- github.com/labstack/gommon v0.4.2 // indirect+ github.com/labstack/echo/v5 v5.0.0github.com/lestrrat-go/blackmagic v1.0.4 // indirectgithub.com/lestrrat-go/httpcc v1.0.1 // indirectgithub.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a // indirect- github.com/mattn/go-colorable v0.1.14 // indirect- github.com/mattn/go-isatty v0.0.20 // indirectgithub.com/openark/golib v0.0.0-20210531070646-355f37940af8github.com/opentracing/basictracer-go v1.1.0 // indirectgithub.com/opentracing/opentracing-go v1.2.0 // indirect@@ -354,8 +351,8 @@ require (github.com/pquerna/otp v1.5.0github.com/prometheus/client_golang v1.23.2github.com/prometheus/client_model v0.6.2 // indirect- github.com/prometheus/common v0.66.1 // indirect- github.com/prometheus/procfs v0.16.1 // indirect+ github.com/prometheus/common v0.67.5 // indirect+ github.com/prometheus/procfs v0.19.2 // indirectgithub.com/segmentio/asm v1.2.1 // indirectgithub.com/shirou/gopsutil/v3 v3.24.5 // indirectgithub.com/siddontang/go v0.0.0-20180604090527-bdc77568d726 // indirect@@ -364,8 +361,6 @@ require (github.com/spf13/pflag v1.0.9 // indirectgithub.com/tikv/client-go/v2 v2.0.8-0.20251028065425-b7d4dfd8520e // indirectgithub.com/tikv/pd/client v0.0.0-20250703091733-dfd345b89500 // indirect- github.com/valyala/bytebufferpool v1.0.0 // indirect- github.com/valyala/fasttemplate v1.2.2 // indirectgithub.com/xdg-go/pbkdf2 v1.0.0 // indirectgithub.com/xdg-go/scram v1.1.2 // indirectgithub.com/xdg-go/stringprep v1.0.4 // indirectdiff --git a/go.sum b/go.sumindex f87f5e1b23..105a93c1b4 100644--- a/go.sum+++ b/go.sum@@ -1447,12 +1447,10 @@ github.com/ks3sdklib/aws-sdk-go v1.2.9 h1:Eg0fM56r4Gjp9PiK1Bg9agJUxCAWCk236qq9DIgithub.com/ks3sdklib/aws-sdk-go v1.2.9/go.mod h1:xBNbOrxSnd36AQpZ8o99mGGu+blblUd9rI0MKGmeufo=github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=-github.com/labstack/echo-contrib v0.17.4 h1:g5mfsrJfJTKv+F5uNKCyrjLK7js+ZW6HTjg4FnDxxgk=-github.com/labstack/echo-contrib v0.17.4/go.mod h1:9O7ZPAHUeMGTOAfg80YqQduHzt0CzLak36PZRldYrZ0=-github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY=-github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g=-github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=-github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=+github.com/labstack/echo-contrib v0.50.0 h1:MLTQdqME3BEBczV2thYz9yPT5sBhzkoUEpwAOY9llds=+github.com/labstack/echo-contrib v0.50.0/go.mod h1:oftqJL4enNg9ao1VLpVZmisVE5/8uwHtIYE4zTpqyWU=+github.com/labstack/echo/v5 v5.0.0 h1:JHKGrI0cbNsNMyKvranuY0C94O4hSM7yc/HtwcV3Na4=+github.com/labstack/echo/v5 v5.0.0/go.mod h1:SyvlSdObGjRXeQfCCXW/sybkZdOOQZBmpKF0bvALaeo=github.com/lestrrat-go/blackmagic v1.0.4 h1:IwQibdnf8l2KoO+qC3uT4OaTWsW7tuRQXy9TRN9QanA=github.com/lestrrat-go/blackmagic v1.0.4/go.mod h1:6AWFyKNNj0zEXQYfTMPfZrAXUWUfTIZ5ECEUEJaijtw=github.com/lestrrat-go/dsig v1.0.0 h1:OE09s2r9Z81kxzJYRn07TFM9XA4akrUdoMwr0L8xj38=@@ -1653,10 +1651,10 @@ github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tgithub.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=-github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs=-github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA=-github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg=-github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is=+github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4=+github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw=+github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws=+github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw=github.com/qri-io/jsonpointer v0.1.1 h1:prVZBZLL6TW5vsSB9fFHFAMBLI4b0ri5vribQlTJiBA=github.com/qri-io/jsonpointer v0.1.1/go.mod h1:DnJPaYgiKu56EuDp8TU5wFLdZIcAnb/uH9v37ZaMV64=github.com/qri-io/jsonschema v0.2.1 h1:NNFoKms+kut6ABPf6xiKNM5214jzxAhDBrPHCJ97Wg0=@@ -1806,12 +1804,8 @@ github.com/uber/jaeger-client-go v2.30.0+incompatible h1:D6wyKGCecFaSRUpo8lCVbaOgithub.com/uber/jaeger-client-go v2.30.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg=github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=-github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=-github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=github.com/valyala/fastjson v1.6.7 h1:ZE4tRy0CIkh+qDc5McjatheGX2czdn8slQjomexVpBM=github.com/valyala/fastjson v1.6.7/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=-github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=-github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=github.com/vcaesar/cedar v0.20.2 h1:TDx7AdZhilKcfE1WvdToTJf5VrC/FXcUOW+KY1upLZ4=github.com/vcaesar/cedar v0.20.2/go.mod h1:lyuGvALuZZDPNXwpzv/9LyxW+8Y6faN7zauFezNsnik=github.com/vcaesar/tt v0.20.1 h1:D/jUeeVCNbq3ad8M7hhtB3J9x5RZ6I1n1eZ0BJp7M+4=@@ -1940,8 +1934,8 @@ go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=-go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=-go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=+go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=+go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=go.yaml.in/yaml/v4 v4.0.0-rc.3 h1:3h1fjsh1CTAPjW7q/EMe+C8shx5d8ctzZTrLcs/j8Go=