Documentation
¶
Index ¶
Constants ¶
View Source
const ( CSRFTokenContextKey contextKey = "csrf_token" SessionIDContextKey contextKey = "session_id" )
Variables ¶
View Source
var ( ErrTokenMismatch = errors.New("csrf token mismatch") ErrTokenNotFound = errors.New("csrf token not found") ErrTokenExpired = errors.New("csrf token expired") ErrKeyOrTokenEmpty = errors.New("key or token must not be empty") DefaultSessionID = "session_id" DefaultExpirationTime = 10 * time.Minute DefaultCleanupIntervalTime = 10 * time.Minute )
Functions ¶
func GenerateCSRFToken ¶
GenerateCSRFToken creates a secure random token for CSRF protection
Types ¶
type DefaultMemoryCSRFStore ¶
type DefaultMemoryCSRFStore struct {
// contains filtered or unexported fields
}
DefaultMemoryCSRFStore includes token expiration and cleanup
func NewDefaultMemoryCSRFStore ¶
func NewDefaultMemoryCSRFStore(durations ...time.Duration) *DefaultMemoryCSRFStore
NewDefaultMemoryCSRFStore creates a store with periodic cleanup
func (*DefaultMemoryCSRFStore) Store ¶
func (s *DefaultMemoryCSRFStore) Store(key, token string) error
Store saves a token with expiration
func (*DefaultMemoryCSRFStore) Validate ¶
func (s *DefaultMemoryCSRFStore) Validate(key, token string) error
type MemoryCSRFStore ¶
type MemoryCSRFStore struct {
// contains filtered or unexported fields
}
MemoryCSRFStore is a simple in-memory implementation of CSRFStore
func NewMemoryCSRFStore ¶
func NewMemoryCSRFStore() *MemoryCSRFStore
NewMemoryCSRFStore creates a new MemoryCSRFStore
func (*MemoryCSRFStore) Store ¶
func (s *MemoryCSRFStore) Store(key, token string) error
Store saves a token with the given key
func (*MemoryCSRFStore) Validate ¶
func (s *MemoryCSRFStore) Validate(key, token string) error
Validate checks if the provided token matches the one stored under the given key
type Store ¶
type Store interface {
// Store saves a token with the given key
Store(key, token string) error
// Validate checks if the token is valid for the key
Validate(key, token string) error
}
Store defines an interface for storing and retrieving CSRF tokens. Implementations can use any session storage mechanism.
type TokenEntry ¶
TokenEntry stores a token with its expiration time
Click to show internal directories.
Click to hide internal directories.