csrf

package
v3.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: GPL-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ErrTokenNotFound       = "CSRF token not found"
	ErrTokenMismatch       = "CSRF token mismatch"
	ErrRefererNotSpecified = "Referer not specified"
	ErrRefererMismatch     = "Referer mismatch"
)

Default errors to use

View Source
const (
	CSRF_TOKEN_COOKIE_NAME      = "csrf_token"
	CSRF_TOKEN_HEADER_NAME      = "X-CSRF-Token"
	CSRF_TOKEN_FORMFIELD_NAME   = "csrf_token"
	CSRF_TOKEN_COOKIE_EXPIRE    = time.Hour * 24
	CSRF_TOKEN_COOKIE_MAX_AGE   = 3600
	CSRF_TOKEN_COOKIE_SECURE    = false
	CSRF_TOKEN_COOKIE_HTTP_ONLY = true
)

Variables

This section is empty.

Functions

func Middleware

func Middleware(next router.Handler) router.Handler

func Token

func Token(req *request.Request) string

Get the token for a given request once the middleware has been run If the token is not found, an empty string is returned

func VerifyToken

func VerifyToken(realToken, sentToken string) bool

VerifyToken verifies the sent token equals the real one and returns a bool value indicating if tokens are equal. Supports masked tokens. realToken comes from Token(r) and sentToken is token sent unusual way.

Types

This section is empty.

Jump to

Keyboard shortcuts

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