Repository navigation
fix(rate-limit): key IPv6 clients on their /56 in the flow limiters - #461
Merged
Merged
Conversation
The magic link, OTP and OAuth flow key generators fell back to the full client address, so a client holding an IPv6 range got a fresh bucket per address.
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.
The magic link, OTP and OAuth flow limiters have custom key generators. When a request carries no email or phone (and always, for the OAuth flow), they fell back to the full
req.ip. A host typically holds a whole IPv6 /64, so it could rotate addresses and get a fresh bucket each time. express-rate-limit warns about exactly this at runtime (ERR_ERL_KEY_GEN_IPV6), and its own default key generator already groups IPv6 by /56. So the general limiter, the per-IP flow limiters, slow-down and the JWKS limiter were not affected.The fallback now goes through the library's
ipKeyGenerator(/56, the library default). IPv4 and IPv4-mapped addresses are keyed as before, and email- or phone-keyed requests are unchanged. Account lockout is per account in Postgres and was never affected.Found while writing the production checklist (fells-code/seamless-auth-docs#121).
Checks:
npm run typecheck,npm run lintand Prettier pass.npm run test:runpasses 1877 tests (1 todo), including a new case showing rotated addresses in one /56 share a key across all three generators.npm run coveragemeets the thresholds (lines 99.16%). CI's audit step needs #456 first.