csrf

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderName = "X-CSRF-Token"

HeaderName - the request header scripts send the token in (forms send the csrf_token field).

View Source
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

func ValidateSubmittedToken(store *sessions.CookieStore, r *http.Request, formToken string) bool

ValidateSubmittedToken checks a CSRF token from JSON or other non-form sources.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL