Every plugin limiter counts IPv6 per /64 (setIpv6Grouping)

clientIp() returns the whole IPv6 address and every limiter keyed on it, so
one host with a /64 had 2^64 budgets: 50 addresses of one /64 against a
limit of 5 all passed (IAWL idea 9, owner's Q4). consumeRateLimit and
checkRateLimit now count an IPv6 key by its /64 (an IPv4-mapped address by
its IPv4); the mail service's per-visitor account-mail key too. A second
counter per /48 at 10x the limit is available and off by default
(setIpv6Grouping({ wide: 48 })); setIpv6Grouping({ prefix: 128 }) counts
per address as before. ipRateKey(ip) is exported for own limiters.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 10:42:02 +01:00
co-authored by Claude Opus 5.5
parent 15b5c6258d
commit 97c62f21f0
8 changed files with 238 additions and 17 deletions
+3 -1
View File
@@ -3,9 +3,11 @@ export {
checkRateLimit,
clientIp,
consumeRateLimit,
ipRateKey,
retryAfterSeconds,
setIpv6Grouping,
setRateLimitStore,
setUnknownIpFactor,
tooManyRequests,
} from '../shared/rateLimit.js'
export type { ClientIpOptions, RateLimitArgs, RateLimitStore } from '../shared/rateLimit.js'
export type { ClientIpOptions, Ipv6Grouping, RateLimitArgs, RateLimitStore } from '../shared/rateLimit.js'