authratelimit

package
v0.42.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package authratelimit implements failed-login blocking. Failed attempts are counted per IP and per account email; past the configured threshold within the window, auth is refused for the block duration. Successful logins reset both keys.

State is in-memory per server; Event/ApplyEvent exist so servers gossip failures, blocks and clears over the cluster, making tracking and blocking cluster-wide: an attacker spreading failures across servers behind a load balancer still trips one shared budget.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyEvent

func ApplyEvent(evt *Event)

ApplyEvent applies a gossiped state change from another server. Failures count towards the shared budget everywhere; blocks are applied as the maximum of local and remote deadlines; clears remove state.

func Blocked

func Blocked(ip, email string) bool

Blocked reports whether either key is currently blocked, refreshing last-use timestamps.

func Clear

func Clear(ip, email string)

Clear resets both keys' state — called on successful login so a user who eventually authenticates isn't left with a near-tripped counter.

func ClearAll

func ClearAll()

ClearAll removes every rate limiter entry (all IPs and emails). It is the in-memory "flush all blocks" used by the admin API; blocks expire on their own otherwise.

func RecordFailure

func RecordFailure(ip, email string) (blockedUntil time.Time, tripped bool)

RecordFailure records a failed login for both keys. Once the configured number of failures occur within the window, the keys are blocked for the configured duration; the tripped block deadline is returned so callers can gossip it cluster-wide.

func StartCleanup

func StartCleanup(stop <-chan struct{})

StartCleanup periodically drops idle limiter state.

Types

type Event

type Event struct {
	IP         string    `msgpack:"ip"`
	Email      string    `msgpack:"email"`
	At         time.Time `msgpack:"at"`
	BlockUntil time.Time `msgpack:"block_until"`
	Clear      bool      `msgpack:"clear"`
	// ClearAll wipes every limiter entry (all IPs and emails); the IP and
	// Email fields are ignored when set.
	ClearAll bool `msgpack:"clear_all"`
}

Event is a rate-limit state change gossiped between servers. Exactly one of the behaviours applies: Clear removes the keys' state; BlockUntil > At applies a block; otherwise the event records a failure at At.

Jump to

Keyboard shortcuts

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