Skip to content

feat: 리프레시 토큰 로테이션 및 재사용 감지 구현#8

Merged
Sean-mn merged 10 commits intodevelopfrom
feat/refresh-token-rotate
Apr 6, 2026
Merged

feat: 리프레시 토큰 로테이션 및 재사용 감지 구현#8
Sean-mn merged 10 commits intodevelopfrom
feat/refresh-token-rotate

Conversation

@Sean-mn
Copy link
Copy Markdown
Contributor

@Sean-mn Sean-mn commented Apr 6, 2026

📚작업 내용

  • RotateResult 열거형 도입 (NotFound, Reused, Success)으로 토큰 로테이션 결과를 타입 안전하게 표현
  • RefreshTokenRedisRepository에 Lua 스크립트 기반 원자적 로테이션(RotateAsync) 구현 — 토큰 불일치 시 forward/reverse 키 동시 삭제로 재사용 공격 방어
  • RefreshTokenService에서 RotateResult를 기반으로 NotFoundUnauthorizedException, Reused → 토큰 도용 감지 후 전체 세션 무효화 처리
  • IRefreshTokenRedisRepositoryRotateAsync 메서드 추가 및 관련 인터페이스 확장
  • RefreshTokenServiceTestsRotateResult 기반으로 전면 업데이트 (재사용 감지, 성공, 미존재 시나리오 포함)
  • 예외 메시지 한국어로 통일

◀️참고 사항

Lua 스크립트 내에서 forward 키(계정ID → 토큰)와 reverse 키(토큰 → 계정ID)를 원자적으로 교체하므로 Redis 레벨에서 경쟁 조건이 발생하지 않습니다. 토큰 재사용이 감지된 경우(Reused) 두 키를 즉시 삭제하여 탈취된 세션을 무효화합니다.

✅체크리스트

[ ]안에 x를 작성하면 체크박스를 체크할 수 있습니다.

  • 현재 의도하고자 하는 기능이 정상적으로 작동하나요?
  • 변경한 기능이 다른 기능을 깨뜨리지 않나요?

추후 필요한 체크리스트는 업데이트 될 예정입니다.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Sean-mn Sean-mn linked an issue Apr 6, 2026 that may be closed by this pull request
4 tasks
@Sean-mn Sean-mn merged commit f137a9c into develop Apr 6, 2026
3 checks passed
@Sean-mn Sean-mn deleted the feat/refresh-token-rotate branch April 6, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Refresh Token Rotation 구현

1 participant