docs(rate-limit): correct IPv6 subnet width — /56 not /64#170
Merged
Conversation
… /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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #169.
Summary
Docstring + inline comment in
app/middleware/rate-limit-key.jsclaimed express-rate-limit's
ipKeyGeneratorcollapses IPv6 to a/64prefix. The helper's actual signature isipKeyGenerator(ip, ipv6Subnet = 56)and we don't override thedefault, so the real bucket width is
/56.The behavior is correct —
/56is the right granularity. The docsjust lied about the width, and the helper-signature mention was
off too (
(req, res)vs the real(ip)).Test plan
npm run lintcleannpm test— 615 passed → 617 passed (+2 IPv6 tests pinning the/56boundary)/56collapse to one key, addresses in different/56s divergeProudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/