Skip to content

Add missing access token JTI claim to prevent replay attacks after blacklist bypass #878

Description

@RUKAYAT-CODER

Overview

src/auth/auth.service.ts generates access tokens with only {sub, email, role}. Without a jti (JWT ID) claim, the token blacklist cannot selectively revoke individual tokens — it can only revoke all tokens for a user. This makes targeted logout (e.g. "log out this specific device") impossible and forces a coarse-grained revocation strategy.

Specifications

Features:

  • Include a unique jti (UUID) in every access token payload.
  • Use jti as the blacklist key instead of userId.

Tasks:

  • Import randomUUID from crypto in auth.service.ts.
  • Add jti: randomUUID() to the access token payload in generateTokens().
  • Update TokenBlacklistService to blacklist by jti with TTL equal to token remaining lifetime.
  • Update JwtStrategy.validate() to check the jti against the blacklist on every request.
  • Add unit tests verifying jti uniqueness and blacklist behavior.

Impacted Files:

  • src/auth/auth.service.ts
  • src/auth/jwt.strategy.ts
  • src/security/token-blacklist/token-blacklist.service.ts

Acceptance Criteria

  • Every issued access token contains a unique jti.
  • Blacklisting a jti only invalidates that specific token, not all tokens for the user.
  • Unit tests verify the blacklist lookup occurs on each authenticated request.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions