Summary
Better Auth's HTTP rate limiter keyed requests by the raw textual IP address taken from headers such as x-forwarded-for, without normalizing IPv6 representations.
Attackers with control over an IPv6 /64 range, or even just the textual form of a single IPv6 address, could rotate addresses or encodings to bypass per-IP rate limits on sensitive endpoints like sign-in, sign-up, and password reset.
Affected context
This vulnerability affects applications using Better Auth's built-in HTTP rate limiter in deployments where:
- IP-based rate limiting is enabled and relied upon to throttle abusive traffic.
- Client IPs are obtained from
x-forwarded-foror a similar proxy/header-based source. - A significant portion of users connect over IPv6, especially where clients may control large address blocks (e.g., /64).
In such environments, rate limiting decisions are made per textual IP string rather than per logical client or network segment, allowing adversaries to evade abuse controls.
Exploit preconditions
- Attack surface: Any HTTP endpoint protected by Better Auth's rate limiter, including
/sign-in/email,/sign-up/email, and/forget-password. - Required access: Network-level access to send HTTP requests to the target service (e.g., over the public internet or internal network).
- IP control: Ability to:
- Rotate source IPv6 addresses within a controllable block (common for some ISPs, cloud, or botnets), or
- Manipulate the textual representation of a stable IPv6 address (case changes, compression forms, IPv4-mapped forms, etc.).
- Trigger point: Sending repeated requests with varying IPv6 addresses or encodings so each is treated as a distinct key by the rate limiter.
- Why exploitation is possible: The limiter uses the literal header string as the key, without canonicalizing or normalizing IPv6 addresses, so logically identical or closely related addresses are tracked as independent clients.
Why this happens
The underlying issue is an improper implementation of rate limiting logic that treats the textual IP string as the unique identifier for client identity and quota enforcement.
Instead of:
- Normalizing IP addresses (especially IPv6) into a canonical binary or textual representation, or
- Grouping addresses by appropriate network prefixes (e.g., /64 for IPv6) or alternative client identifiers,
the rate limiter directly uses the unprocessed header value. For IPv6, multiple syntactically different strings can represent the same address, and typical allocations grant large address spaces to a single endpoint.
This maps to CWE-307: Improper Restriction of Excessive Authentication Attempts, because the intended throttling of repeated authentication or sensitive actions can be bypassed by trivial variations in the IP key, effectively removing the practical limit on attempts.
Potential impact
- Attackers may bypass rate limits on authentication endpoints, enabling high-volume credential stuffing or password spraying.
- Automated sign-up abuse could proceed at scale, leading to fake account creation and downstream fraud.
- Password reset flows could be probed repeatedly, aiding account takeover attempts or user enumeration.
- Application-layer denial-of-service (DoS) attacks may become more feasible as abusive traffic is not effectively throttled.
- Security controls and monitoring that assume per-IP enforcement may provide a false sense of protection.
General mitigation guidance
Effective mitigation centers on robust client identification and proper IP normalization in rate limiting strategies:
- Normalize IP addresses: Convert all client IPs to a canonical form before keying, using well-tested IP parsing utilities that handle IPv4, IPv6, and IPv4-mapped IPv6 addresses consistently.
- Use network-prefix limits: For IPv6, consider grouping by a configured prefix (e.g., /64 or /56) instead of individual addresses, acknowledging that many addresses may belong to a single logical client.
- Diversify identifiers: Combine IP-based limits with other signals such as account ID, user agent, device identifiers, or session cookies, where privacy and policy allow.
- Separate control planes: Apply stricter and more conservative limits on sensitive endpoints (login, registration, password reset) than on general API traffic.
- Least-privilege assumptions: Do not rely solely on IP-based throttling for abuse prevention; treat it as one layer in a broader defense-in-depth strategy that includes robust authentication, anomaly detection, and business-logic checks.
How teams detect issues like this
Detection typically involves both code-level review and runtime monitoring:
- Static analysis & code review:
- Look for rate limiting code that keys directly on raw header values such as
x-forwarded-forwithout parsing or normalization. - Flag implementations where IPv6 handling is absent, naive, or treated identically to IPv4 without considering address space and formatting differences.
- Review middleware and reverse proxy configurations to ensure a single, trusted source of client IP is used.
- Configuration and policy checks:
- Enforce policies that require canonicalization of IP addresses at ingress or within a gateway layer before rate limiting is applied.
- Validate that limits are defined per logical client or network segment, not just per raw string token.
- Runtime signals:
- Monitor for unusually high aggregate request rates from broad IPv6 ranges with low apparent per-IP rates.
- Analyze logs to detect many distinct IP strings associated with similar request patterns or identifiers (e.g., same user-agent, same accounts targeted).
- Automated tooling:
- Incorporate security linting or SAST tools that recognize common rate limiting pitfalls.
- Use integration tests or security tests that attempt to exceed rate limits using varied IPv6 encodings or addresses.

