Skip to content

Fix expiring code redemption - #4011

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

Fix expiring code redemption#4011
joemahady-comm wants to merge 1 commit into
cloudfoundry:developfrom
joemahady-comm:TNZGOV-14856

Conversation

@joemahady-comm

Copy link
Copy Markdown
Contributor

Fix: Addressed a Time-of-Check to Time-of-Use (TOCTOU) race condition in JdbcExpiringCodeStore that could allow multiple concurrent requests to consume the same expiring code.

Details: Modified the retrieveCode method to verify the result of the DELETE SQL statement. It now ensures that exactly one row is deleted (jdbcTemplate.update(delete, ...) == 1). If the delete operation affects 0 rows, it safely returns null, preventing race conditions.

…isted=yes

Co-authored-by: Cursor <cursoragent@cursor.com>

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 expiring code redemption in JdbcExpiringCodeStore to reduce a TOCTOU window where concurrent requests could potentially consume the same code.

Changes:

  • Update retrieveCode to check the row-count returned by the DELETE and return null when the code was not actually deleted (already consumed).

Comment on lines +145 to +148
int deleted = jdbcTemplate.update(delete, code, zoneId);
if (deleted == 0) {
return null;
}
Comment on lines +145 to +147
int deleted = jdbcTemplate.update(delete, code, zoneId);
if (deleted == 0) {
return null;
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