Conversation
There was a problem hiding this comment.
Code Review
This pull request implements Refresh Token Rotation (RTR) by introducing Redis Lua scripts for atomic operations and refactoring the RefreshTokenService. Key changes include adding a reverse lookup for tokens, a new RotateResult enum, and migrating to IConnectionMultiplexer for Redis access. Feedback identifies a logical flaw where immediate deletion of old tokens bypasses reuse detection and suggests implementing a grace period to handle race conditions during rotation.
Fantasy-server/Fantasy.Server/Domain/Auth/Service/RefreshTokenService.cs
Outdated
Show resolved
Hide resolved
Fantasy-server/Fantasy.Server/Domain/Auth/Repository/RefreshTokenRedisRepository.cs
Show resolved
Hide resolved
4 tasks
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.
📚작업 내용
RotateResult열거형 도입 (NotFound,Reused,Success)으로 토큰 로테이션 결과를 타입 안전하게 표현RefreshTokenRedisRepository에 Lua 스크립트 기반 원자적 로테이션(RotateAsync) 구현 — 토큰 불일치 시 forward/reverse 키 동시 삭제로 재사용 공격 방어RefreshTokenService에서RotateResult를 기반으로NotFound→UnauthorizedException,Reused→ 토큰 도용 감지 후 전체 세션 무효화 처리IRefreshTokenRedisRepository에RotateAsync메서드 추가 및 관련 인터페이스 확장RefreshTokenServiceTests를RotateResult기반으로 전면 업데이트 (재사용 감지, 성공, 미존재 시나리오 포함)Lua 스크립트 내에서 forward 키(계정ID → 토큰)와 reverse 키(토큰 → 계정ID)를 원자적으로 교체하므로 Redis 레벨에서 경쟁 조건이 발생하지 않습니다. 토큰 재사용이 감지된 경우(
Reused) 두 키를 즉시 삭제하여 탈취된 세션을 무효화합니다.✅체크리스트