Documentation
¶
Index ¶
- Constants
- func CSRFTokenFromContext(ctx context.Context) string
- func EnsureCSRFToken(c fiber.Ctx, store *session.Store) (string, error)
- func ExistingCSRFToken(c fiber.Ctx, store *session.Store) (string, error)
- func HasSessionLookup(c fiber.Ctx, store *session.Store) bool
- func HashKey(key string) string
- func NormalizeEmail(email string) string
- func SafeMethod(method string) bool
- func ValidateCSRFToken(c fiber.Ctx, store *session.Store) (bool, error)
- func WithCSRFToken(ctx context.Context, token string) context.Context
- type AbuseDecision
- type AbuseLimit
- type AbuseLimiter
- type MemoryAbuseLimiter
- type Throttle
Constants ¶
const ( CSRFFormField = "_csrf" CSRFHeader = "X-CSRF-Token" )
Variables ¶
This section is empty.
Functions ¶
func CSRFTokenFromContext ¶
CSRFTokenFromContext returns the token installed by WithCSRFToken, if any.
func EnsureCSRFToken ¶
EnsureCSRFToken returns the session token, creating one when the browser session does not have a token yet.
func ExistingCSRFToken ¶
ExistingCSRFToken returns the session token only when the request already carries a session lookup value. It never creates or saves a new session.
func HasSessionLookup ¶
HasSessionLookup reports whether the request includes the configured session lookup value. It lets backend middleware avoid creating sessions for generic API clients that did not send browser cookies.
func HashKey ¶
HashKey returns a short stable hash for audit logs so raw emails and full throttle keys are never logged.
func NormalizeEmail ¶
NormalizeEmail canonicalizes email input for throttle keys without changing the value passed to downstream validation or auth services.
func SafeMethod ¶
SafeMethod reports whether a method is defined as safe for CSRF purposes.
func ValidateCSRFToken ¶
ValidateCSRFToken compares the submitted header or form token with the session token without exposing token values to logs or errors.
Types ¶
type AbuseDecision ¶
AbuseDecision reports whether the operation may proceed and when a denied window resets.
type AbuseLimit ¶
AbuseLimit describes one shared fixed-window budget. Scope must identify the operation class; Key must identify the client or tenant without containing a credential or other secret.
type AbuseLimiter ¶
type AbuseLimiter interface {
Attempt(context.Context, AbuseLimit) (AbuseDecision, error)
}
AbuseLimiter is the storage-independent boundary used by HTTP middleware. Production implementations must share state across replicas and restarts.
type MemoryAbuseLimiter ¶
type MemoryAbuseLimiter struct {
// contains filtered or unexported fields
}
MemoryAbuseLimiter is a deterministic test/local adapter. Production wiring uses the Postgres implementation so replacing a process cannot reset limits.
func NewMemoryAbuseLimiter ¶
func NewMemoryAbuseLimiter() *MemoryAbuseLimiter
NewMemoryAbuseLimiter creates one in-memory limiter.
func (*MemoryAbuseLimiter) Attempt ¶
func (l *MemoryAbuseLimiter) Attempt(_ context.Context, budget AbuseLimit) (AbuseDecision, error)
Attempt atomically records one request against the supplied operation budget.
type Throttle ¶
type Throttle struct {
// contains filtered or unexported fields
}
func NewThrottle ¶
NewThrottle creates a process-local fixed-window throttle. It is deliberately in-memory: reverse proxy limits remain the distributed outer layer.