domain: redeem_authorization_code deletes the code before loading the user, burning it on transient errors #61
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
rosa/vernier#61
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found during a code review of the
domaincrate.Location:
crates/domain/src/services.rs:833(redeem_authorization_code)Severity: Correctness
Problem
The code is deleted before
find_user_by_idand token issuance. A transient repo error or missing user after the delete permanently burns a valid single-use code with nothing granted, and the client retry gets invalid_grant.Failure scenario
A legitimate client redeems a fresh code; the DELETE succeeds but the following
find_user_by_idreturns a transient Err or None. The client must restart the whole authorization flow even though nothing was granted.Suggested fix
Load the user and issue the token first, deleting/consuming the code only once issuance is guaranteed (ideally folded into the same atomic consume from #49).
Verified during triage: the delete precedes the user load in the redemption flow, so a transient failure after the consume burns the code with nothing granted. This defect shares its fix with issue #49 (the atomic consume must also settle the ordering), so both are covered by the single Agent Brief posted on #49. An agent picking this up should work from that brief; this issue closes with #49's fix.