fix(security): in-process rate-limit fallback when Redis is unreachable#11
Merged
Conversation
The fixed-window limiter previously failed fully open on a Redis error, so an outage disabled the login/register/token rate limits entirely. Add a per-instance, volatile in-process fallback window that keeps throttling abuse while Redis is down, preserving availability without leaving the door wide open. Covered by unit tests for the fallback path, in-process enforcement, and window reset.
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
The fixed-window rate limiter (
lib/server/rateLimit.ts) previously failed fully open on any Redis error — returningsuccess: truewhenmulti.exec()threw or returned null. A Redis outage therefore disabled the login (5/15m), register (5/1h), and token (300/1m) limits entirely. This adds a per-instance, volatile in-process fallback window that keeps throttling while Redis is down, preserving availability (the original intent) without leaving the door wide open.Change
rateLimit()now routes tofallbackRateLimit()(an in-memory fixed-window map) when Redis is unreachable, instead of returning unconditional success. The map prunes expired windows past a cap so a long outage can't grow memory unbounded.Audit context
This came out of a 5-item hardening audit. Findings:
getdel), 15-min TTL, uniform response.profile:read) — deferred: rejecting empty scope is a breaking change for integrators; it's least-privilege today, so it's an OIDC-conformance call for the owner, not shipped here.No schema or API changes.