Skip to content

docs(rate-limit): correct IPv6 subnet width — /56 not /64#170

Merged
CryptoJones merged 1 commit into
masterfrom
docs/rate-limit-key-ipv6-prefix-accuracy
May 19, 2026
Merged

docs(rate-limit): correct IPv6 subnet width — /56 not /64#170
CryptoJones merged 1 commit into
masterfrom
docs/rate-limit-key-ipv6-prefix-accuracy

Conversation

@CryptoJones
Copy link
Copy Markdown
Owner

Closes #169.

Summary

Docstring + inline comment in app/middleware/rate-limit-key.js
claimed express-rate-limit's ipKeyGenerator collapses IPv6 to a
/64 prefix. The helper's actual signature is
ipKeyGenerator(ip, ipv6Subnet = 56) and we don't override the
default, so the real bucket width is /56.

The behavior is correct — /56 is the right granularity. The docs
just lied about the width, and the helper-signature mention was
off too ((req, res) vs the real (ip)).

Test plan

  • npm run lint clean
  • npm test — 615 passed → 617 passed (+2 IPv6 tests pinning the /56 boundary)
  • new tests assert: addresses inside one /56 collapse to one key, addresses in different /56s diverge

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

… /56 not /64

The docstring and inline comment claimed express-rate-limit's
ipKeyGenerator collapses IPv6 source IPs to a /64 prefix, but the
helper's default is actually /56 (per its `ipv6Subnet = 56` default
parameter). The code calls `ipKeyGenerator(ip)` without overriding,
so /56 is what we get — meaning a single IPv6 client could in theory
rotate through 256 distinct /64 prefixes inside their /56 allocation
and all still bucket to the same rate-limit budget. That's the
correct behavior; the docs just lied about the width.

Also fixed a smaller inaccuracy: the doc claimed the helper takes
`(req, res)` but the real signature is `(ip, ipv6Subnet = 56)`.

Added two unit tests pinning the actual /56 behavior — addresses
inside one /56 collapse to one key, addresses in different /56s
diverge. This makes the boundary observable so a future helper
upgrade that quietly changes the default surfaces as a test failure
instead of silent rate-limit drift.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CryptoJones CryptoJones merged commit 9f0b3da into master May 19, 2026
3 checks passed
@CryptoJones CryptoJones deleted the docs/rate-limit-key-ipv6-prefix-accuracy branch May 19, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rate-limit-key: docstring claims IPv6 /64 prefix, but ipKeyGenerator's default is /56

1 participant