Documentation
¶
Index ¶
- Constants
- func EnsureToken(store *sessions.CookieStore, w http.ResponseWriter, r *http.Request) string
- func Token(store *sessions.CookieStore, r *http.Request) string
- func Validate(store *sessions.CookieStore, r *http.Request) bool
- func ValidateRequest(store *sessions.CookieStore, r *http.Request) bool
- func ValidateSubmittedToken(store *sessions.CookieStore, r *http.Request, formToken string) bool
Constants ¶
const HeaderName = "X-CSRF-Token"
HeaderName - the request header scripts send the token in (forms send the csrf_token field).
const SessionName = "user-session"
SessionName - the session cookie the token lives in (the site's session).
Variables ¶
This section is empty.
Functions ¶
func EnsureToken ¶
func EnsureToken(store *sessions.CookieStore, w http.ResponseWriter, r *http.Request) string
EnsureToken returns the CSRF token from the session, generating a new one if needed. If a new token was generated, the session is saved to persist it in the cookie.
func Token ¶
func Token(store *sessions.CookieStore, r *http.Request) string
Token reads the CSRF token from the session without generating a new one.
func Validate ¶
func Validate(store *sessions.CookieStore, r *http.Request) bool
Validate checks if the provided form token matches the session token using constant-time comparison.
func ValidateRequest ¶
func ValidateRequest(store *sessions.CookieStore, r *http.Request) bool
ValidateRequest checks the token sent with a state-changing request: the X-CSRF-Token header (fetch/XHR) or the csrf_token form field.
func ValidateSubmittedToken ¶
ValidateSubmittedToken checks a CSRF token from JSON or other non-form sources.
Types ¶
This section is empty.