sourcefuse / sourcefuse/loopback4-microservice-catalog
Add TTL to Revoked Access Tokens in Redis
Open
- Dominant language
- TypeScript
- Stars
- 297
- Forks
- 78
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 4
Description
Problem
Revoked access tokens were being written to Redis without a TTL (Time-To-Live) in the authentication service's login.controller.ts. This occurred at two call sites:
resetPasswordmethod – When users reset their password.createTokenPayloadmethod – During token refresh and tenant switching operations.
Solution
Added a TTL to every revoked access token written to Redis.
1. Added revokedTokenTtlMs() Helper
Created a private helper method that:
- Decodes the JWT.
- Extracts the
exp(expiration) claim. - Calculates the remaining lifetime using:
(exp - current_time) + 60 seconds grace period
- Returns the TTL in milliseconds.
- Ensures the TTL is at least 1 second.
- Falls back to 1 hour if:
expis missing.- JWT decoding fails.
Result
- Revoked access tokens now expire automatically after their remaining JWT lifetime.
- Redis no longer retains revoked tokens indefinitely.
- Prevents long-term Redis memory growth.
- Avoids accumulation of stale JWT entries.
- Reduces the risk of Redis memory exhaustion and AOF rewrite failures.
- Prevents recurrence of the production issue caused by permanent revoked-token entries.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.