Key rate limiter on client IP and add verifiedTokens cleanup#2157
Merged
Conversation
felladrin
marked this pull request as ready for review
July 22, 2026 20:38
- Key the rate limiter on client IP (from X-Forwarded-For rightmost entry, X-Real-IP, or socket.remoteAddress) instead of the client- rotatable argon2 hash, which allowed bypassing the limit by rotating the token each request - Validate extracted IPs with net.isIP() to prevent unbounded key injection from malformed headers - Add periodic cleanup (every 60s) to verifiedTokens Set to prevent unbounded memory growth - Pass IncomingMessage through handleTokenVerification to both server hooks so the IP can be extracted Note: users behind the same IP will now share a rate-limit bucket.
felladrin
force-pushed
the
rate-limit-by-ip-2126
branch
from
July 22, 2026 20:38
3e04761 to
5a0057b
Compare
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.
Summary
Fixes #2126. The rate limiter was keyed on a client-rotatable argon2 hash — each request generated a fresh hash with a new random salt, so the rate limiter never actually limited. The
verifiedTokensSet also grew unbounded with no cleanup.Changes
getClientIp()to extract the real client IP from the rightmost X-Forwarded-For entry (the one our proxy appended), X-Real-IP, or socket.remoteAddress. Rate limiter now keyed on IP instead of token. IPs validated withnet.isIP()to prevent unbounded key injection.IncomingMessageparameter, passes it through toverifyTokenAndRateLimit.handleTokenVerification.Verification
npm run lintpasses cleanNote
Users behind the same IP will now share a rate-limit bucket (10 req/10s).