csrf

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(options ...Option) route.Middleware

New creates CSRF middleware.

func Token

func Token(ctx *route.Context) string

Token returns the CSRF token stored on the current request.

Types

type Config

type Config struct {
	Next         func(*route.Context) bool
	CookieName   string
	HeaderName   string
	FormField    string
	CookiePath   string
	CookieDomain string
	Secure       bool
	HTTPOnly     bool
	SameSite     http.SameSite
	MaxAge       int
	SkipPaths    []string
	OnError      func(*route.Context) error
}

Config configures CSRF middleware.

type Option

type Option func(*Config)

Option configures CSRF middleware.

func Cookie(name string) Option

Cookie sets the CSRF cookie name.

func Domain

func Domain(domain string) Option

Domain sets the CSRF cookie domain.

func Field

func Field(name string) Option

Field sets the form field used to submit the CSRF token.

func HTTPOnly

func HTTPOnly(value bool) Option

HTTPOnly sets the CSRF cookie HttpOnly flag.

func Header(name string) Option

Header sets the request header used to submit the CSRF token.

func MaxAge

func MaxAge(seconds int) Option

MaxAge sets the CSRF cookie Max-Age in seconds.

func Next

func Next(fn func(*route.Context) bool) Option

Next skips CSRF middleware when fn returns true.

func OnError

func OnError(fn func(*route.Context) error) Option

OnError sets a custom error handler for rejected requests.

func Path

func Path(path string) Option

Path sets the CSRF cookie path.

func SameSite

func SameSite(mode http.SameSite) Option

SameSite sets the CSRF cookie SameSite mode.

func Secure

func Secure(value bool) Option

Secure sets the CSRF cookie Secure flag.

func SkipPaths

func SkipPaths(paths ...string) Option

SkipPaths skips CSRF checks for exact request paths.

Jump to

Keyboard shortcuts

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