trying to fix bug changing in class - #268
Conversation
GideonBa
left a comment
There was a problem hiding this comment.
Thanks for working on the replay-token handling. I found a few compile blockers that need to be fixed before this can be merged.
| update RefreshToken rt | ||
| set rt.revoked = true | ||
| where rt.user.id = :userId | ||
| where rt.user.id = :userId AND r.revoked = false |
There was a problem hiding this comment.
This JPQL uses alias r, but the update declares rt. Please change this to rt.revoked = false; otherwise the revoke-all query will fail.
| VAULT_UNLOCKED, | ||
| VAULT_LOCKED | ||
| } | ||
| } |
There was a problem hiding this comment.
AuthService now references TOKEN_REPLAY_DETECTED, but this enum still does not define it. Please add the new enum value here.
| import org.slf4j.Logger; | ||
|
|
||
| import static vaultWeb.services.auth.RefreshTokenCleanupService.log; | ||
| private final SecurityEventRepository securityEventRepository; |
There was a problem hiding this comment.
This field is currently outside the AuthService class body, which makes the file invalid Java. Please move it into the class so @RequiredArgsConstructor can inject it.
| } | ||
|
|
||
| String tokenId = claims.getId(); | ||
| RefreshToken storedToken = refreshTokenRepository.findByTokenId(tokenId).orElse(null); |
There was a problem hiding this comment.
tokenId is used here before it is assigned. Please restore String tokenId = claims.getId() after parsing the refresh token.
|
@avdheshpatidar27 please fix the failing workflows |
Summary
Fixed refresh token replay-attack detection in
AuthService. Previously,refresh()andlogout()usedfindByTokenIdAndRevokedFalse(), which excludedalready-revoked tokens from the query — so a revoked (reused/replayed) token,
an expired token, and a token that never existed all returned the same generic
401 response with zero logging.
Changes:
RefreshTokenRepository.findByTokenId(String tokenId)— looks up atoken by id without filtering out revoked tokens.
RefreshTokenRepository.revokeAllByUser(Long userId)— revokes allactive refresh tokens for a user (defense-in-depth on detected replay).
AuthService.refresh()to distinguish three cases:SECURITY ALERT, persists aSecurityEvent(newSecurityEventType.TOKEN_REPLAY_DETECTED), revokes all other sessionsfor the user, returns 401
AuthService.logout().SecurityEventType.TOKEN_REPLAY_DETECTEDenum value.SecurityEventRepositoryintoAuthServiceto persist the auditevent.
Linked issue
Closes #
How to test
refresh_tokenHttpOnly cookie is set.POST /api/auth/refresh