Skip to content

feat(auth): rotate refresh tokens atomically - #94

Merged
DJAngel973 merged 3 commits into
mainfrom
fix/sec-003-refresh-token-storage
Oct 28, 2026
Merged

DJAngel973 merged 3 commits into
mainfrom
fix/sec-003-refresh-token-storage

Conversation

@DJAngel973

Copy link
Copy Markdown
Owner

Summary

Implements SEC-004 refresh-token rotation to prevent refresh-token replay.

  • Returns a new access token and refresh token on every successful refresh.
  • Revokes the previous refresh-token session atomically.
  • Uses pessimistic locking so concurrent requests cannot both consume the same refresh token.
  • Adds a unique JWT jti to guarantee newly generated tokens are distinct.
  • Audits successgul refreshes and rejected reuse attempts without logging raw tokens or hashes.
  • Adds the TOKEN_REFRESH audit action and PostgreSQL migtration.

Security

  • Refresh tokens remain stored only as SHA-256 hashes.
  • Reused, revoked, or expired refresh tokens are rejected.
  • Session rotation is transactional to prevent inconsistent token state.
  • Audit records include outcome, IP, and User-Agent, never token values.

Tests

  • Updated AuthServiceTest for successful rotation and rejected token reuse.
  • Added SessionServiceTest coverage for session rotation and consumed-token rejection.

Follow-up

  • Apply database/08-migrations.sql and perform Docker/PostgreSQL end-to-end verification of rotation, replay rejection, and logout.

@DJAngel973
DJAngel973 merged commit 75c2fc8 into main Oct 28, 2026
4 checks passed
@DJAngel973
DJAngel973 deleted the fix/sec-003-refresh-token-storage branch November 4, 2026 00:49
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