Skip to content

Fix authorization code consumption - #4006

Open
joemahady-comm wants to merge 1 commit into
cloudfoundry:developfrom
joemahady-comm:TNZGOV-15835
Open

Fix authorization code consumption#4006
joemahady-comm wants to merge 1 commit into
cloudfoundry:developfrom
joemahady-comm:TNZGOV-15835

Conversation

@joemahady-comm

@joemahady-comm joemahady-comm commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Ticket: authorization-code-consumption-ignores-delete-rowcount-toctou

Fix: Validated that JdbcTemplate.update deletes exactly 1 row when consuming an authorization code, preventing TOCTOU races resulting in multiple access tokens per single code.

…-delete-rowcount-toctou / uaa ai-assisted=yes

Co-authored-by: Cursor <cursoragent@cursor.com>
@joemahady-comm joemahady-comm changed the title Implement AI Scan -- MEDIUM -- authorization-code-consumption-ignores… Fix authorization code consumption Jul 29, 2026
@duanemay
duanemay requested a review from Copilot July 29, 2026 20:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens authorization code consumption in UaaTokenStore to prevent TOCTOU-style races that could otherwise allow more than one access token to be minted from a single authorization code.

Changes:

  • Delete the authorization code row before deserializing/returning the stored authentication (so the code can’t be reused if another consumer races).
  • Add a delete row-count check to detect “code already consumed” scenarios.

Comment on lines +146 to +150
int deletedRows = template.update(SQL_DELETE_STATEMENT, code);
if (deletedRows == 0) {
throw new InvalidGrantException("Invalid authorization code: " + code);
}

Comment on lines +146 to +151
int deletedRows = template.update(SQL_DELETE_STATEMENT, code);
if (deletedRows == 0) {
throw new InvalidGrantException("Invalid authorization code: " + code);
}

if (tokenCode.isExpired()) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants