fix(auth): fail-closed JWT denylist check with circuit breaker on Redis outage - #100
Merged
Merged
Conversation
…is outage The non-strict authMiddleware failed open on Redis outage, silently accepting all revoked tokens. A compromised token cannot be reliably revoked during an infra incident — the exact moment revocation matters most. Both authMiddleware and strictAuthMiddleware now fail closed (503) when the denylist Redis lookup cannot complete. A circuit breaker prevents hanging on Redis timeouts: after 3 consecutive failures it fast-fails immediately, then auto-recovers after a 30s cooldown. This is a conscious trade-off — availability is sacrificed to prevent a revoked token from being silently accepted during a Redis outage. Closes ecotask-network#68 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
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.
Description
Closes #68 — JWT denylist revocation check fails open on Redis outage
Problem
In
src/middleware/auth.ts:26-40, the non-strictauthMiddleware(used by the majority of routes —tasks,users,notifications,proofs,validators,audit, etc.) catches Redis errors during thejwt_denylist:{jti}lookup and fails open — proceeding as if the token were not revoked. This means during a Redis outage, all explicitly logged-out tokens are silently accepted, including those of compromised accounts.The strict variant (
strictAuthMiddleware) already fails closed, but it is only used by a small subset of admin routes.Solution: Fail-Closed + Circuit Breaker
Core change: The
authMiddlewarenow fails closed on Redis outage — returning503 Service Unavailableinstead of silently accepting the request. A token whose revocation status we cannot verify is treated as revoked.Circuit breaker (
DenylistCircuitBreaker): To avoid hanging on Redis timeouts during an outage and to auto-recover:Files Changed
Configuration
Trade-off
During a sustained Redis outage, all authenticated requests return `503` instead of `200`. This is the conscious security-vs-availability trade-off: we sacrifice availability to prevent compromised/revoked tokens from being silently accepted. The circuit breaker limits the blast radius of transient Redis blips to `failureThreshold` slow requests before fast-fail kicks in, and auto-recovers once Redis is back.
Type of Change
How Has This Been Tested?
New Tests (10)
Checklist
Additional Context