Priyansusahoo / Priyansusahoo/security_core
feat: Implement Redis-based Refresh Token, Multi-Device Session Management & Token Blacklist
Open
@Priyansusahoo is already working on this.
Since Aug 16, 2026.
enhancement
- Dominant language
- Java
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
π Overview
This issue tracks the implementation of a production-grade stateless JWT security upgrade.
The current implementation issues a 24-hour access token with no refresh mechanism, no logout
capability, and no multi-device session management.
π¨ Current Problems
- Access token lifetime is 24 hours β a stolen token is valid for an entire day
- No logout endpoint β once issued, a token cannot be revoked
- Single-device only β a second login overwrites the first device's session
loadUserByUsername()hits PostgreSQL on every API request β no caching- No CORS configuration β frontend applications cannot call this API from a browser
β What We Will Implement
1. Redis Infrastructure
-
docker-compose.ymlwith Redis (AOF persistence + volume mount) -
spring-boot-starter-data-redisdependency - Redis connection configuration in
application.yml
2. Refresh Token (Multi-Device)
- Reduce Access Token lifetime:
24 hours β 15 minutes - Issue a Refresh Token (7 days) on login/register
- Store Refresh Token in Redis:
refresh:<userId>:<sessionId> -
POST /v1/api/auth/refreshendpoint β validates + rotates refresh token -
sessionIdembedded as a claim inside the Access Token
3. Token Blacklist (Logout)
-
POST /v1/api/auth/logoutβ blacklists current access token in Redis - Blacklisted token TTL = remaining lifetime of the access token
-
JwtAuthenticationFilterupdated to check blacklist on every request
4. Logout From All Devices
-
POST /v1/api/auth/logout-allendpoint - Stores
invalidated_before:<userId>timestamp in Redis - Deletes ALL
refresh:<userId>:*keys from Redis - Filter rejects any token issued before the
invalidated_beforetimestamp
5. Password/Email Update Handling
- On credential update β trigger "logout from all devices" automatically
6. CORS Configuration
-
CorsConfigurationSourcebean inSecurityConfiguration - Profile-based allowed origins (local vs prod)
7. Flyway Migration
-
V2__add_session_tracking.sqlβ (if any DB changes needed)
ποΈ Files To Be Created
New:
βββ docker-compose.yml
βββ src/main/java/.../token/RefreshTokenService.java
βββ src/main/java/.../token/TokenBlacklistService.java
βββ src/main/java/.../auth/dto/RefreshTokenRequest.java
βββ src/main/java/.../auth/dto/LogoutRequest.java
Modified:
βββ pom.xml (add Redis dependency)
βββ application.yml (Redis config)
βββ application-local.yml (Redis local config)
βββ AuthController.java (new endpoints)
βββ AuthService.java (refresh + blacklist logic)
βββ AuthResponse.java (add refreshToken + sessionId fields)
βββ JwtService.java (reduce expiry, add sessionId claim)
βββ JwtAuthenticationFilter.java (blacklist + invalidatedBefore checks)
βββ SecurityConfiguration.java (CORS config)
π Security Improvements Summary
| Threat | Before | After |
|---|---|---|
| Token theft | 24hr window | 15min window |
| Logout | Not possible | Immediate blacklist |
| Multi-device | Broken | Full session management |
| All-device logout | Not possible | invalidated_before timestamp |
| DB load per request | 1 query/request | Redis cache (sub-millisecond) |
| Browser CORS | Blocked | Properly configured |
π·οΈ Labels
enhancement security redis jwt
Contributor guide
No contributing guide indexed for this repository
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.