throttle

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 12 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 throttle makes an address wait longer after each try in a row: wrong passwords at the login and on the OAuth consent page, accounts created from one address at the public sign-up. The failures are kept in the base (login_failures): a restart forgets none, and /authorize faces the Internet.

Index

Constants

View Source
const GlobalKey = "global consent"

GlobalKey counts the wrong passwords of every address on the OAuth consent page, which faces the Internet: an attacker rotating addresses still waits. The login stays on the tailnet and does not count it.

Variables

This section is empty.

Functions

func AddressKey

func AddressKey(r *http.Request) string

AddressKey is the key of the request's client: its IPv4 address, or the /64 of an IPv6 one, which one client usually holds whole.

Types

type Throttle

type Throttle struct {
	// contains filtered or unexported fields
}

Throttle counts the tries in a row of each key, under its name.

func New added in v0.6.0

func New(db bun.IDB, name, message string) *Throttle

New gives a throttle whose keys are counted under name, and whose 429 says message.

func Passwords

func Passwords(db bun.IDB) *Throttle

Passwords counts the wrong passwords: the login and the OAuth consent page share the count of an address. No name: its keys stay those the base already holds.

func Signups added in v0.6.0

func Signups(db bun.IDB) *Throttle

Signups counts the accounts an address creates in the public mode: one address cannot fill the server.

func (*Throttle) Blocked

func (t *Throttle) Blocked(w http.ResponseWriter, r *http.Request, key string) bool

Blocked answers 429 with Retry-After while key waits, else counts the try (Try).

func (*Throttle) Forgive

func (t *Throttle) Forgive(ctx context.Context, key string)

Forgive takes back the try Try counted, when it did not count.

func (*Throttle) Reset

func (t *Throttle) Reset(ctx context.Context, key string)

Reset forgets the tries of key.

func (*Throttle) Try

func (t *Throttle) Try(ctx context.Context, key string) (wait time.Duration, err error)

Try counts a try for key before it runs, and gives 0; or, while key waits, how long it has left, without counting. In one transaction: the base has one connection, tries sent at once pass one after the other. The caller resets on a good password, forgives on another error.

Jump to

Keyboard shortcuts

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