Charge the rate limit to the client, and stop the map growing without bound - #144
Merged
Merged
Conversation
This was referenced Aug 23, 2026
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 limiter keyed its buckets on the leftmost
X-Forwarded-Forentry, taken straight off the request:That entry is written by the client. A fresh forged value per request bought a fresh bucket per request, so the limiter never fired on the traffic it exists to hold back — and
resolve_client_ipwas right there, already used byip_allow_list, which only believes the header when the peer is a trusted proxy. The limiter now goes through it, so a header from an untrusted peer is ignored and one from a proxy we trust is still honoured.Every forged value also left a permanent entry behind.
cleanupexisted to prevent exactly that, carried a comment saying so, and was marked#[allow(dead_code)]— nothing called it.checknow sweeps once the map crosses 10k sources: idle buckets first, and if a flood of fresh addresses leaves nothing idle, the buckets closest to full. A source at full tokens has spent nothing, so forgetting it grants it nothing; a depleted bucket — the one that is being held back — outlives it.The tests fail against the old behaviour, showing two forged headers resolving to two identities, and 15000 sources tracked against a 10000 cap.
Fifth of the findings from a full audit, after #140 to #143.