fix: only skip CSRF for /api/ routes with Bearer tokens

This commit is contained in:
2026-04-23 13:34:43 +02:00
parent ab17ff8b79
commit 5fc208c9da
+6 -1
View File
@@ -71,7 +71,7 @@ func CSRFMiddleware() func(http.Handler) http.Handler {
return
}
if strings.HasPrefix(r.URL.Path, "/api/") {
if strings.HasPrefix(r.URL.Path, "/api/") && hasBearerToken(r) {
next.ServeHTTP(w, r)
return
}
@@ -86,6 +86,11 @@ func CSRFMiddleware() func(http.Handler) http.Handler {
}
}
func hasBearerToken(r *http.Request) bool {
auth := strings.TrimSpace(r.Header.Get("Authorization"))
return strings.HasPrefix(auth, "Bearer ")
}
func IsHTTPS(r *http.Request) bool {
if r.TLS != nil {
return true