Skip to content

chore: 만료된 refresh token·비밀번호 재설정 토큰을 매일 정리한다 - #154

Merged
ff1451 merged 1 commit into
mainfrom
chore/expired-token-cleanup
Oct 18, 2026
Merged

ff1451 merged 1 commit into
mainfrom
chore/expired-token-cleanup

Conversation

@ff1451

@ff1451 ff1451 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

요약

로그인·토큰 갱신마다 refresh_token에 행이 하나씩 쌓이고(갱신 시 이전 토큰은 revoke만 함), password_reset_token도 지우는 곳이 없었다. refresh_token.expires_at에는 인덱스까지 있지만 쓰는 쿼리가 없었다.

변경

  • auth/schedule/ExpiredTokenCleanupScheduler: 매일 04:00(KST) 만료된 지 30일이 지난 refresh token·비밀번호 재설정 토큰을 지우고 삭제 건수를 로그로 남긴다.
  • RefreshTokenRepository.deleteExpiredBefore, PasswordResetTokenRepository.deleteExpiredBefore(벌크 delete 한 번).

왜 30일 뒤인가

  • 토큰 갱신은 만료 검사를 재사용 검사보다 먼저 한다(AuthService.refresh). 그래서 만료된 토큰은 지워도 재사용 감지(회전된 토큰을 다시 쓰면 전 세션 로그아웃)에 영향이 없다.
  • 만료 직후 지우면 만료된 쿠키로 요청한 사용자가 "로그인이 만료되었습니다" 대신 "다시 로그인해 주세요"(토큰 없음) 안내를 받는다. 이를 피하려고 로그인 유지 기간과 같은 30일을 남긴다.

테스트

  • ExpiredTokenCleanupIntegrationTest: 31일 전 만료 토큰만 지우고, 1일 전 만료·유효 토큰은 남긴다(refresh token·재설정 토큰 모두).
  • 로컬 전체 ./gradlew test: 549건 중 548 통과, 1 스킵.

로그인과 토큰 갱신마다 refresh_token 행이 하나씩 쌓이고, password_reset_token도 지워지지 않았다.
매일 04:00(KST)에 만료된 지 30일이 지난 토큰을 지운다.

만료된 토큰은 갱신 때 재사용 검사보다 먼저 "만료"로 거절되므로 지워도 재사용 감지에는 영향이 없다.
30일 여유는 만료된 쿠키로 요청한 사용자가 "만료" 안내를 받도록 남겨 둔 것이다.
@coderabbitai

coderabbitai Bot commented Oct 16, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 5 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3ab1be96-fafd-4dbd-a3d6-079c3132e91b
📥 Commits

Reviewing files that changed from the base of the PR and between 0690ad0 and 4c20b6e.

📒 Files selected for processing: 4
  • src/main/java/com/bcsdlab/bcsdinternalapiv2/auth/repository/PasswordResetTokenRepository.java
  • src/main/java/com/bcsdlab/bcsdinternalapiv2/auth/repository/RefreshTokenRepository.java
  • src/main/java/com/bcsdlab/bcsdinternalapiv2/auth/schedule/ExpiredTokenCleanupScheduler.java
  • src/test/java/com/bcsdlab/bcsdinternalapiv2/auth/ExpiredTokenCleanupIntegrationTest.java
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ff1451
ff1451 merged commit 92cfd5a into main Oct 18, 2026
2 of 3 checks passed
@ff1451
ff1451 deleted the chore/expired-token-cleanup branch October 18, 2026 13: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.

1 participant