Conversation
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements single-use enforcement for authorization codes as per RFC 6749 §4.1.2. It introduces a new AuthCode domain model, a PostgreSQL repository for tracking consumed codes, and logic within the OAuthService to detect replays and revoke associated tokens. Feedback focuses on addressing a potential race condition during replay detection, handling persistence errors more robustly when storing token metadata, ensuring errors are not ignored during token introspection for revocation, and improving performance by executing token revocation asynchronously.
There was a problem hiding this comment.
Code Review
This pull request implements single-use enforcement for authorization codes per RFC 6749 §4.1.2. It introduces a new AuthCode domain model and repository to track consumed codes, adds logic to the OAuthService to detect and reject replays, and ensures that tokens issued from a replayed code are revoked. The changes also include database migrations, cleanup tasks for expired records, and updates to integration tests to handle response body closing more robustly. Feedback was provided regarding the handling of errors during token introspection in the revocation logic.
Summary
fix: enforce single-use authorization codes (RFC 6749 §4.1.2)
Problem
Authorization codes were stateless HS256 JWTs with no consumption tracking. The same valid code could be exchanged multiple times before its 5-minute TTL expired, allowing an attacker who intercepts it to obtain multiple valid sessions.
Fix
Track consumed auth codes in a new auth_codes table. On exchange, an atomic INSERT ON CONFLICT determines whether the code has been used before. Replays are rejected with invalid_grant and all tokens from the original exchange are revoked.
Key design decisions:
Changes
New files:
Modified:
Lint cleanup (pre-existing):
Test plan
replay