feat: implement memory-bounded bucket eviction for rate limiter and a… - #232
Open
GiftedGiftB wants to merge 1 commit into
Open
Conversation
…dd operational documentation
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.
Closed #223
Description
This PR addresses the high-priority vulnerability regarding the
rateLimitermiddleware, specifically mitigating the unbounded memory growth (memory-pressure vector) while formalizing the operational behavior for multi-instance deployments.1. Store Decision (Explicit Deferral)
After evaluation, I have deliberately deferred the introduction of a shared distributed store (like Redis) for rate limiting. This service currently has no external storage dependencies and no persistence layer. Introducing one strictly for rate limiting would prematurely bloat the operational footprint of the service. This explicit deferral is now documented in
README.md, and it will be revisited when the broader persistence layer issue is resolved.2. Fail-Open / Fail-Closed Reasoning
Because the shared store decision has been deferred and rate limiting remains completely in-memory, network failure policies regarding a cache store are not applicable at this stage. The limiter operates entirely locally within the Node.js process and does not suffer from external store outages.
3. Read-Path Conclusion
We are continuing to leave standard
GETreads unlimited. The only computationally expensive "read" operation (POST /api/v1/quote) is already independently bounded by its own stricter rate limiter instance insrc/app.ts. Standard statelessGETrequests are extremely fast and do not mutate state, so leaving them unlimited is acceptable for now.4. Memory Bounds Implementation (Fixing Unbounded Growth)
To defend against the memory-pressure attack vector, a hard capacity limit (
MAX_BUCKETS = 5000) has been added to the local Map state. If an attacker cycles distinct IPs, the limiter will:Verification
The following tests were successfully added and pass with no external dependencies:
5000) under a flood of distinct IP keys by evicting the oldest entries.npm run lint,npm run build, andnpm testsuites pass fully with0regressions, preserving default limits and windows.