fix: only skip CSRF for /api/ routes with Bearer tokens
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user