[PR #7470] [MERGED] fix(rate-limit): support IPv6 address normalization and subnet #32936

Closed
opened 2026-04-17 23:38:22 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7470
Author: @himself65
Created: 1/19/2026
Status: Merged
Merged: 1/19/2026
Merged by: @himself65

Base: canaryHead: himself65/2026/01/12/ipv6


📝 Commits (8)

📊 Changes

12 files changed (+996 additions, -119 deletions)

View changed files

📝 docs/content/docs/concepts/rate-limit.mdx (+39 -1)
e2e/smoke/test/fixtures/ipv6/index.ts (+46 -0)
e2e/smoke/test/fixtures/ipv6/package.json (+10 -0)
e2e/smoke/test/fixtures/ipv6/tsconfig.json (+10 -0)
e2e/smoke/test/ipv6.spec.ts (+205 -0)
📝 packages/better-auth/src/api/rate-limiter/index.ts (+2 -1)
📝 packages/better-auth/src/api/rate-limiter/rate-limiter.test.ts (+175 -92)
📝 packages/better-auth/src/utils/get-request-ip.ts (+4 -17)
📝 packages/core/src/types/init-options.ts (+19 -0)
packages/core/src/utils/ip.test.ts (+243 -0)
packages/core/src/utils/ip.ts (+211 -0)
📝 pnpm-lock.yaml (+32 -8)

📄 Description

Upstream: https://github.com/better-auth/better-auth/pull/7300


Summary by cubic

Add IPv6 normalization and optional subnet-based rate limiting to block bypasses and give finer control over IPv6 traffic. Also update rate limit key format to prevent collisions.

  • New Features

    • Normalize IPv6 to a canonical form; convert IPv4-mapped IPv6 (e.g., ::ffff:192.0.2.1) to IPv4.
    • Add ipv6Subnet option (default 128) to rate limit by subnet (/64, /48, /32).
    • Validate and normalize request IPs before applying rate limits.
  • Migration

    • Rate limit keys now use "{ip}|{path}" instead of concatenation. Update any custom storage or tooling that reads keys; existing keys will be recreated automatically.

Written for commit e6f1c0cdb8. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7470 **Author:** [@himself65](https://github.com/himself65) **Created:** 1/19/2026 **Status:** ✅ Merged **Merged:** 1/19/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2026/01/12/ipv6` --- ### 📝 Commits (8) - [`cd97767`](https://github.com/better-auth/better-auth/commit/cd9776780e27e35e6a8c578a145d246ad58c17b1) feat(rate-limit): add IPv6 address normalization and subnet support - [`a931fb3`](https://github.com/better-auth/better-auth/commit/a931fb3cb6c98cf3e76f2dc6e28fe327cea912b1) fix cspell - [`c7dcfe5`](https://github.com/better-auth/better-auth/commit/c7dcfe5259fcf79c1be0ec35317f94a5f9cf3d88) fix: type - [`6379220`](https://github.com/better-auth/better-auth/commit/63792203cedebc2a99171001060ca67796ae808b) test: smoke - [`b17bcad`](https://github.com/better-auth/better-auth/commit/b17bcad8eabaae56ce9de25cede72d355863bc8f) fix: code - [`be84745`](https://github.com/better-auth/better-auth/commit/be847459fff09288df987cc9f3c54712d8645c82) docs: update - [`d4f1d14`](https://github.com/better-auth/better-auth/commit/d4f1d142b243508e7baf67494a6480036363a507) fix: smoke test - [`e6f1c0c`](https://github.com/better-auth/better-auth/commit/e6f1c0cdb8ad5b7ab5b68eec501f7a955c29a65f) refactor ### 📊 Changes **12 files changed** (+996 additions, -119 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/concepts/rate-limit.mdx` (+39 -1) ➕ `e2e/smoke/test/fixtures/ipv6/index.ts` (+46 -0) ➕ `e2e/smoke/test/fixtures/ipv6/package.json` (+10 -0) ➕ `e2e/smoke/test/fixtures/ipv6/tsconfig.json` (+10 -0) ➕ `e2e/smoke/test/ipv6.spec.ts` (+205 -0) 📝 `packages/better-auth/src/api/rate-limiter/index.ts` (+2 -1) 📝 `packages/better-auth/src/api/rate-limiter/rate-limiter.test.ts` (+175 -92) 📝 `packages/better-auth/src/utils/get-request-ip.ts` (+4 -17) 📝 `packages/core/src/types/init-options.ts` (+19 -0) ➕ `packages/core/src/utils/ip.test.ts` (+243 -0) ➕ `packages/core/src/utils/ip.ts` (+211 -0) 📝 `pnpm-lock.yaml` (+32 -8) </details> ### 📄 Description Upstream: https://github.com/better-auth/better-auth/pull/7300 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add IPv6 normalization and optional subnet-based rate limiting to block bypasses and give finer control over IPv6 traffic. Also update rate limit key format to prevent collisions. - **New Features** - Normalize IPv6 to a canonical form; convert IPv4-mapped IPv6 (e.g., ::ffff:192.0.2.1) to IPv4. - Add ipv6Subnet option (default 128) to rate limit by subnet (/64, /48, /32). - Validate and normalize request IPs before applying rate limits. - **Migration** - Rate limit keys now use "{ip}|{path}" instead of concatenation. Update any custom storage or tooling that reads keys; existing keys will be recreated automatically. <sup>Written for commit e6f1c0cdb8ad5b7ab5b68eec501f7a955c29a65f. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 23:38:22 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#32936