authlimit

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package authlimit throttles repeated failed authentications, to slow down guessing of passwords. It is shared by every authentication surface (WebSocket group joins, the recordings pages, the administrative API), so failures on one surface escalate the delay on all of them.

Each failed attempt from an address sleeps for an exponentially growing delay, so a guesser is slowed to a crawl while a user who merely mistyped their password a few times is barely affected — and is cleared immediately once they get in. After banThreshold failures the address is refused outright for banDuration; the last BanWarn attempts before that carry a warning, so a legitimate user is never banned without notice. Every failure is logged with the offending address, so an external tool such as fail2ban can ban persistent guessers at the firewall (see contrib/fail2ban/).

NB: the key is the connection's remote address. Behind a reverse proxy that does not preserve it, all clients share one key — and a ban then hits everyone behind it.

Index

Constants

View Source
const (

	// BanWarn is how many attempts before the ban the user should start
	// being warned.
	BanWarn = 3
)

Variables

This section is empty.

Functions

func AddrKey

func AddrKey(addr net.Addr) string

AddrKey reduces a remote address to a stable key: its IP, without the port.

func Banned

func Banned(key string) (bool, time.Duration)

Banned reports whether key is temporarily banned after too many failed authentications and, if so, for how much longer. Callers should check it before evaluating any credentials.

func Failure

func Failure(key, what string) int

Failure records a failed authentication for key on the given surface and sleeps for an exponentially growing delay. It logs the failure in a fail2ban-friendly format and returns the number of attempts left before the address is temporarily banned (0 meaning it now is).

func HostKey

func HostKey(remoteAddr string) string

HostKey reduces a "host:port" remote address (as found in an http.Request's RemoteAddr) to a stable key: the host without the port.

func Reset

func Reset(key string)

Reset clears the throttle for key after a successful authentication.

func SetDisabled

func SetDisabled(v bool)

SetDisabled turns throttling and banning off (or back on). For tests.

Types

This section is empty.

Jump to

Keyboard shortcuts

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