fix: only skip CSRF for /api/ routes with Bearer tokens
This commit is contained in:
1 parent
ab17ff8b79
commit
5fc208c9da
1 file changed
+6
-1
@@ -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