v1
This commit is contained in:
22
internal/pkg/mid/csrf.go
Normal file
22
internal/pkg/mid/csrf.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package mid
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/justinas/nosurf"
|
||||
)
|
||||
|
||||
func NoSurf(next http.Handler) http.Handler {
|
||||
return nosurf.New(next)
|
||||
}
|
||||
|
||||
func NoSurfContext(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
token := nosurf.Token(r)
|
||||
|
||||
ctx := setCsrfToken(r.Context(), token)
|
||||
ctx = setHtmlCsrfToken(ctx, fmt.Sprintf(`<input type="hidden" name="csrf_token" value="%s" />`, token))
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user