The key was a string. The string was what the proxy wrote down.
packages/better-auth/src/utils/get-request-ip.ts, at the parent commit of the CVE-2026-45364 fix:
export function getIp(
req: Request | Headers,
options: BetterAuthOptions,
): string | null {
if (options.advanced?.ipAddress?.disableIpTracking) {
return null;
}
const headers = "headers" in req ? req.headers : req;
const defaultHeaders = ["x-forwarded-for"];
const ipHeaders =
options.advanced?.ipAddress?.ipAddressHeaders || defaultHeaders;
for (const key of ipHeaders) {
const value = "get" in headers ? headers.get(key) : headers[key];
if (typeof value === "string") {
const ip = value.split(",")[0]!.trim();
if (isValidIP(ip)) {
return ip;
}
}
}
// ...
return null;
}
function isValidIP(ip: string): boolean {
const ipv4 = z.ipv4().safeParse(ip);
if (ipv4.success) return true;
const ipv6 = z.ipv6().safeParse(ip);
if (ipv6.success) return true;
return false;
}
Take the first comma-separated entry of the configured IP header. Trim. Validate as either IPv4 or IPv6 via zod. Return the string. That is the function's entire contract: a string the zod parser admitted as a valid IP. It is also the string that becomes, verbatim, half of the rate-limit key.
packages/better-auth/src/api/rate-limiter/index.ts, same parent commit:
const ip = getIp(req, ctx.options);
if (!ip) {
return;
}
const key = ip + path;
The other half is the request path. There is no separator between them. The concatenation is the lookup key into the rateLimit table, or the secondary-storage key-value store, or the in-memory Map. The store holds one row per key. Each row carries a count and a timestamp.
The data structure does what it is told. It does not know that 2001:db8::1 and 2001:DB8::1 are the same address. It does not know that a residential IPv6 customer is allocated a /64. It has a key, the key is a string, and the string is what arrived.
The counter was per /128. The caller is a /64.
RFC 6177, "IPv6 Address Assignment to End Sites," published March 2011, names the unit of assignment:
The minimum allocation by an RIR should be a /48 to end sites, but smaller assignments to specific subscriber types might be appropriate, e.g., a single /64 when only one subnet is needed.
In practice every major residential ISP, every commercial fiber provider, every consumer VPN, every cloud provider issuing IPv6, and every mobile carrier assigns end sites a /64 at minimum. A /64 contains 2^64 addresses. The end site, the one apartment, the one rented VM, the one phone, picks any of those addresses as the source for an outbound connection. RFC 4941 privacy extensions actively rotate. RFC 8981 temporary addresses rotate by default on every major operating system. The /128 the proxy writes into x-forwarded-for is one of trillions the caller can pick from before the kernel asks for a new one.
The fix's own test for the bypass:
it("should support IPv6 subnet rate limiting", () => {
// Simulate attacker rotating through IPv6 addresses in their /64 allocation
const attackIPs = [
"2001:db8:abcd:1234:0000:0000:0000:0001",
"2001:db8:abcd:1234:1111:2222:3333:4444",
"2001:db8:abcd:1234:ffff:ffff:ffff:ffff",
];
const normalized = attackIPs.map((ip) =>
normalizeIP(ip, { ipv6Subnet: 64 }),
);
const uniqueValues = new Set(normalized);
expect(uniqueValues.size).toBe(1);
expect(normalized[0]).toBe("2001:0db8:abcd:1234:0000:0000:0000:0000");
});
Three of attackIPs's 2^64 possible siblings. Post-fix, with ipv6Subnet: 64, they collapse to one key. Pre-fix, they were three keys with three counters. Each /128 from the same /64 was a separate caller. The pre-fix rate limiter on /sign-in/email allowed three attempts per address per ten seconds, and the attacker rotating through their /64 had three attempts times 18 quintillion.
The paths the limiter protects, from getDefaultSpecialRules in the same file:
function getDefaultSpecialRules() {
return [
{
pathMatcher(path: string) {
return (
path.startsWith("/sign-in") ||
path.startsWith("/sign-up") ||
path.startsWith("/change-password") ||
path.startsWith("/change-email")
);
},
window: 10,
max: 3,
},
{
pathMatcher(path: string) {
return (
path === "/request-password-reset" ||
path === "/send-verification-email" ||
path.startsWith("/forget-password") ||
path === "/email-otp/send-verification-otp" ||
path === "/email-otp/request-password-reset"
);
},
window: 60,
max: 3,
},
];
}
These are the credential-stuffing surfaces. Three sign-in attempts per ten seconds. Three password-reset triggers per minute. Three change-password requests per ten seconds. Each is enforced per /128. For an IPv6 caller, "per /128" is unenforced.
The same /128 has at least six textual spellings.
Six representations of one address, copied verbatim from the fix's bypass-prevention test:
const representations = [
"2001:db8::1",
"2001:DB8::1",
"2001:0db8::1",
"2001:db8:0::1",
"2001:0db8:0:0:0:0:0:1",
"2001:db8::0:1",
];
// post-fix, all six normalizeIP() to:
// "2001:0db8:0000:0000:0000:0000:0000:0001"
Differences: letter case in the hex groups, zero-padding inside a group, choice of where to place the :: zero-compression, and short versus full form. Every representation is a valid IPv6 string per RFC 4291. z.ipv6() accepts all six and returns the input unchanged. Pre-fix, the same /128 was six distinct rate-limit keys.
A more pointed trio, also from the test suite:
"::ffff:c000:0201" // hex-encoded IPv4 inside IPv6 mapped form
"::ffff:192.0.2.1" // dotted-quad IPv4 inside IPv6 mapped form
"192.0.2.1" // plain IPv4
All three are 192.0.2.1. The CVE-2026-45364 description names them all by name: "uppercase, compression, IPv4-mapped, hex-encoded IPv4-in-IPv6."
The textual-variation bypass requires the upstream proxy to pass through the client's chosen form. The common case is a Better Auth deployment behind nginx with X-Forwarded-For appended rather than overwritten, which is nginx's default. The client sends an X-Forwarded-For: <chosen-spelling> header; nginx appends its TCP source after it; Better Auth's getIp reads the first entry, which is the client's. The same caller varies the spelling, the limiter opens a new bucket. This stacks on top of the /64 rotation, which works regardless of the proxy's XFF policy because the source address itself is what changes.
The fix is two patches. The first release named the wrong one.
PR #7470, opened January 19, 2026 by Alex Yang (himself65), titled fix(rate-limit): support IPv6 address normalization and subnet. The diff adds normalizeIP() and createRateLimitKey() to @better-auth/core/utils/ip, threads them through getIp and the rate-limit key construction. The new option type:
/**
* IPv6 subnet prefix length for rate limiting.
*
* IPv6 addresses can be grouped by subnet to prevent attackers from
* bypassing rate limits by rotating through multiple addresses in
* their allocation.
*
* @default 128 (individual address)
*/
ipv6Subnet?: 128 | 64 | 48 | 32 | undefined;
The default is 128. PR #7470 merged and shipped as v1.4.16 on January 20. The v1.4.16 release notes list one rate-limit item: "Support IPv6 address normalization and subnet."
With ipv6Subnet defaulting to 128, what v1.4.16 closed: the textual-variation bypass. 2001:db8::1 and 2001:DB8::1 now produce the same canonical key. The IPv4-mapped variations now collapse to the IPv4 form.
What v1.4.16 did not close: the /64 rotation. With the default at /128, three sign-in attempts per address per ten seconds still ran per /128, and the attacker still held 2^64 addresses per /64. The doc comment on the new option named what ipv6Subnet: 64 would do; the default did not do it.
PR #7509, opened January 21 by the same author, titled fix: set default ipv6 subnet to 64. The functional diff is one constant in one type declaration:
- * @default 128 (individual address)
+ * @default 64 (/64 subnet)
The runtime change is ?? 64 instead of ?? 128 in normalizeIP. The rest of the patch is updating tests that had asserted the old default. Merged and shipped as v1.4.17 the same day. The v1.4.17 release notes list one rate-limit item: "Set default ipv6 subnet to 64."
The GHSA, published May 11, 2026, names 1.4.17 as the fix for CVE-2026-45364. It does not name 1.4.16. The CVE description leads with the /64 bypass: "IPv6 clients controlling a typical /64 allocation could rotate through 2^64 distinct source addresses without exhausting the per-address counter, defeating rate limiting on /sign-in/email, /sign-up/email, /forget-password, and every other path the limiter protects." That bypass survives v1.4.16. v1.4.17 is one line, one day later, and the patch only closes the CVE when both releases are taken together.
The first release named "fix" for an IPv6 rate-limit bypass and the release that actually fixed the IPv6 rate-limit bypass shipped twenty-one hours apart and were written by the same person. The release notes describe them as two separate items.
Convention Is The Allowlist applied to a rate-limit key.
CVE-2026-45364 is the Convention Is The Allowlist shape applied to a rate-limit identity scheme. The catalog's prior exhibits live in HTTP client parsers (Streamlink's M3U8 file-scheme acceptance), TypeScript-typed query DSLs (Kysely's K extends string), and SSH protocol-state dispatch (Erlang/OTP's authenticated-but-never-asked dispatcher).
The convention here is the implicit one that "one IP equals one caller." For IPv4, where end sites are assigned individual addresses or small CIDR blocks billed per address, the convention has historically held well enough to be load-bearing in every per-IP rate limiter ever written. For IPv6, where end sites are assigned /64 or /48 blocks and a single device legitimately uses dozens of source addresses (RFC 4941 privacy extensions, RFC 8981 temporary addresses, server-side outbound rotation), the convention does not hold. The "one IP equals one caller" identity grain is documentation, in the heads of authors who learned rate limiting in the IPv4 era.
The implementation parsed inbound IPv6 at the broad syntactic type, "any string z.ipv6() admits," and used the return value as the caller identity. The pattern's "set of accepted values remains whatever happens to be supported by the surrounding subsystems today" rendered, for this rate limiter, as "every textual form zod accepts, one address per /128." The patch closes the demonstrated chain by narrowing twice: normalizeIP collapses textual forms to a canonical lowercase fully-expanded representation, and the ipv6Subnet: 64 default collapses /128 cardinality to /64.
The narrowing is applied at the rate-limit call site. The same getIp function continues to feed telemetry, audit logging, session-attribution events, and any downstream consumer that imports @better-auth/core/utils. Those consumers now also see the /64-collapsed canonical form, regardless of whether they wanted caller-identity grain or source-address grain. The rate limiter's identity contract is now the contract every consumer of getIp runs with, configured by whatever ipv6Subnet the integrator passes.
PoC: github.com/advisories/GHSA-p6v2-xcpg-h6xw.
The counter ran. The data structure did exactly what its API said it would do. The string was a string.