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.4.4 (#21812)

renovate[bot]ce4eafd36ea0
diff --git a/backend/server/server_frontend_routes.go b/backend/server/server_frontend_routes.go
index c3de219fe7..e3604a51b1 100644
--- a/backend/server/server_frontend_routes.go
+++ b/backend/server/server_frontend_routes.go
@@ -3,8 +3,6 @@ package server
import (
"io/fs"
"net/http"
- "net/url"
- "path"
"strings"
"github.com/labstack/echo/v5"
@@ -35,17 +33,28 @@ func registerFrontendRoutes(e *echo.Echo, distFS fs.FS) {
}
cacheImmutable := func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c *echo.Context) error {
- // Only mark an asset immutable once we've confirmed it exists. In an HA
- // rolling deploy, an older replica can 404 a new hashed asset briefly;
- // we must not let browsers or CDNs cache "does not exist" for a year.
- p := c.Param("*")
- if unescaped, err := url.PathUnescape(p); err == nil {
- p = unescaped
- }
- name := path.Clean(strings.TrimPrefix(p, "/"))
- if info, err := fs.Stat(assetsFS, name); err == nil && !info.IsDir() {
- c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=31536000, immutable")
+ // Mark an asset immutable only once the response is known to be a
+ // success. In an HA rolling deploy an older replica can 404 a new
+ // hashed asset briefly, and the static handler rejects a path with a
+ // dot or empty segment outright, so a year of cached "does not exist"
+ // has to be impossible. Reading the status rather than re-deriving the
+ // file from the path also leaves echo's path rules to echo: deciding
+ // from a cleaned path is what put the header on those 404s.
+ //
+ // 304 keeps the directive so a revalidating CDN does not shorten its
+ // TTL; WriteHeader sets Status before it runs these hooks.
+ res, err := echo.UnwrapResponse(c.Response())
+ if err != nil {
+ // Without echo's response the status is not observable, and guessing
+ // from the path is exactly what put immutable on those 404s. Serve
+ // the asset uncached instead.
+ return next(c)
}
+ res.Before(func() {
+ if res.Status == http.StatusOK || res.Status == http.StatusNotModified {
+ res.Header().Set(echo.HeaderCacheControl, "public, max-age=31536000, immutable")
+ }
+ })
return next(c)
}
}
diff --git a/backend/server/server_frontend_routes_test.go b/backend/server/server_frontend_routes_test.go
index d72aca8c23..13e5055ed2 100644
--- a/backend/server/server_frontend_routes_test.go
+++ b/backend/server/server_frontend_routes_test.go
@@ -44,6 +44,16 @@ func TestRegisterFrontendRoutes_AssetCacheHeaders(t *testing.T) {
wantCacheCtrl: "",
bodyMustNotBe: "<!doctype html",
},
+ {
+ // echo v5.4 rejects a path with a dot or empty segment outright
+ // (GHSA-3pmx-cf9f-34xr). Deciding the header from the cleaned path
+ // instead of the response saw an existing file here and shipped a
+ // year-long immutable directive on the handler's 404.
+ name: "escaped dot segment returns 404 with no immutable cache",
+ path: "/assets/x/%2e%2e/app-1234.js",
+ wantStatus: http.StatusNotFound,
+ wantCacheCtrl: "",
+ },
{
name: "spa route falls back to index.html with no immutable",
path: "/projects/foo",
diff --git a/go.mod b/go.mod
index 030de5008c..3ba3b98128 100644
--- a/go.mod
+++ b/go.mod
@@ -66,7 +66,7 @@ require (
github.com/jackc/pgtype v1.14.4
github.com/jackc/pgx/v5 v5.11.0
github.com/labstack/echo-contrib/v5 v5.0.1
- github.com/labstack/echo/v5 v5.3.1
+ github.com/labstack/echo/v5 v5.4.4
github.com/lib/pq v1.12.3
github.com/lor00x/goldap v0.0.0-20240304151906-8d785c64d1c8
github.com/microsoft/go-mssqldb v1.11.2
diff --git a/go.sum b/go.sum
index 5a801bcc9c..79877d90a4 100644
--- a/go.sum
+++ b/go.sum
@@ -682,8 +682,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.3.1 h1:75maCxkQVGualckLc/5s/ihgpH1a1Dc6AuGWNVNs6bw=
-github.com/labstack/echo/v5 v5.3.1/go.mod h1:4iEGNQiPPZnkfYpNR/L6fINd3NLiGWUD5+eBotFALas=
+github.com/labstack/echo/v5 v5.4.4 h1:Nag9Mee0M9sOcKjProYuDNiw60QisysgfbIgz5US5Cw=
+github.com/labstack/echo/v5 v5.4.4/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=