Skip to content
This repository was archived by the owner on Feb 13, 2026. It is now read-only.

Commit 06b282f

Browse files
authored
frontend: bypass auth middleware for favicon and icon assets in root (#3240)
Updated the `ServeHTTP` function in the `assetHandler` to add caching headers for `.ico`, `.svg`, and `.webp` files, serving these files with a `Cache-Control` header set to cache for one day. This change bypasses the authentication middleware for favicon and icon assets in the root directory. The bypass is limited to image assets in the root path to maintain security. Key changes: - Added early path check for image file extensions (.ico, .svg, .webp) - Added security check to only serve files from root directory - Set Cache-Control header to cache assets for 24 hours - Serve files directly without going through auth middleware
1 parent e02a57c commit 06b282f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

backend/gateway/mux/mux.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"regexp"
1414
"strconv"
1515
"strings"
16+
"time"
1617

1718
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
1819
"golang.org/x/net/http2"
@@ -60,6 +61,19 @@ func copyHTTPResponse(resp *http.Response, w http.ResponseWriter) {
6061
}
6162

6263
func (a *assetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
64+
if strings.HasSuffix(r.URL.Path, ".ico") ||
65+
strings.HasSuffix(r.URL.Path, ".svg") ||
66+
strings.HasSuffix(r.URL.Path, ".webp") {
67+
if !strings.Contains(r.URL.Path[1:], "/") {
68+
if f, err := a.fileSystem.Open(r.URL.Path); err == nil {
69+
defer f.Close()
70+
w.Header().Set("Cache-Control", "public, max-age=86400")
71+
http.ServeContent(w, r, r.URL.Path, time.Time{}, f)
72+
return
73+
}
74+
}
75+
}
76+
6377
if apiPattern.MatchString(r.URL.Path) || r.URL.Path == "/healthcheck" {
6478
// Serve from the embedded API handler.
6579
a.next.ServeHTTP(w, r)

0 commit comments

Comments
 (0)