This repository has been archived on 2025-08-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
web-app-template/handler/middleware/cross_site_request_forgery.go
2024-12-08 23:19:45 +01:00

26 lines
512 B
Go

package middleware
import (
"me-fit/service"
"net/http"
)
func CrossSiteRequestForgery(auth *service.Auth) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// session := r.Context().Value(SessionKey)
if r.Method == "POST" {
csrfToken := r.FormValue("csrf-token")
if csrfToken == "" {
http.Error(w, "", http.StatusForbidden)
return
}
}
next.ServeHTTP(w, r)
})
}
}