DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
auth_lockout.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file auth_lockout.h
6 * @brief Per-peer brute-force lockout for HTTP auth (DETWS_ENABLE_AUTH_LOCKOUT).
7 *
8 * Tracks consecutive failed authentications per source address in a fixed BSS
9 * table (no heap). The key is the full family-tagged address (DetIp), so an IPv4
10 * and an IPv6 peer are always distinct buckets and no attacker can share or poison
11 * another address's state through a lossy hash collision. After
12 * DETWS_AUTH_LOCKOUT_THRESHOLD consecutive failures an address is locked out for
13 * DETWS_AUTH_LOCKOUT_BASE_MS, doubling on each further failure up to
14 * DETWS_AUTH_LOCKOUT_MAX_MS; a successful auth clears the address. Compiled only
15 * when DETWS_ENABLE_AUTH_LOCKOUT is set (the host unit tests enable it and drive
16 * it with a synthetic millisecond clock). An unspecified address (family
17 * DetIpFamily::DET_IP_NONE or all-zero) is untrackable and is never locked.
18 *
19 * @author Douglas Quigg (dstroy0)
20 * @date 2026
21 */
22
23#ifndef DETERMINISTICESPASYNCWEBSERVER_AUTH_LOCKOUT_H
24#define DETERMINISTICESPASYNCWEBSERVER_AUTH_LOCKOUT_H
25
26#include "ServerConfig.h"
27
28#if DETWS_ENABLE_AUTH_LOCKOUT
29
30#include <stdint.h>
31
33
34/**
35 * @brief Remaining lockout time for @p ip at @p now_ms, in milliseconds.
36 *
37 * @return 0 if the address is not currently locked out (or is unspecified /
38 * untrackable); otherwise the milliseconds until the lockout expires. The
39 * window math is unsigned so it survives a millis() rollover.
40 */
41uint32_t auth_lockout_remaining_ms(const DetIp *ip, uint32_t now_ms);
42
43/** @brief Record a failed authentication from @p ip at @p now_ms (may start or escalate a lockout). */
44void auth_lockout_fail(const DetIp *ip, uint32_t now_ms);
45
46/** @brief Clear @p ip's failure / lockout state after a successful authentication. */
47void auth_lockout_succeed(const DetIp *ip);
48
49/** @brief Reset the whole lockout table (e.g. between tests). */
50void auth_lockout_reset(void);
51
52#endif // DETWS_ENABLE_AUTH_LOCKOUT
53
54#endif // DETERMINISTICESPASYNCWEBSERVER_AUTH_LOCKOUT_H
User-facing configuration for DeterministicESPAsyncWebServer.
Layer 3 (Network) - a family-tagged IP address (IPv4 or IPv6) with RFC-faithful text parsing,...
A v4 or v6 address in network (big-endian) byte order.
Definition ip.h:52