Skip to content

Reload one-time-use tokens to prevent cache reuse - #3279

Open
CydeWeys wants to merge 1 commit into
google:masterfrom
CydeWeys:fix-register-bsa-cache-reload
Open

CydeWeys wants to merge 1 commit into
google:masterfrom
CydeWeys:fix-register-bsa-cache-reload

Conversation

@CydeWeys

@CydeWeys CydeWeys commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Update AllocationTokenFlowUtils.loadAndValidateToken() to check
tokenEntity.getTokenType().isOneTimeUse() instead of checking only
TokenType.SINGLE_USE when reloading tokens from the database.

PR #3157 added an uncached database reload for SINGLE_USE tokens to
prevent double-redemption within the 10-minute ALLOCATION_TOKENS_CACHE
TTL, but omitted TokenType.REGISTER_BSA (which also has
isOneTimeUse() == true). As a result, a REGISTER_BSA token already
redeemed in Cloud SQL remained unredeemed in JVM heap cache for up to 10
minutes and could be redeemed a second time without recording a
PostgreSQL SERIALIZABLE read dependency.

  • Replace equals(TokenType.SINGLE_USE) with isOneTimeUse() in
    AllocationTokenFlowUtils.loadAndValidateToken() so all one-time-use
    token types (SINGLE_USE and REGISTER_BSA) reload fresh database state
    inside the active transaction before validation.
  • Add unit tests in AllocationTokenFlowUtilsTest and
    DomainCreateFlowTest verifying that a cached REGISTER_BSA token
    already redeemed in the database is rejected with
    AlreadyRedeemedAllocationTokenException.

BUG= http://b/534931178


This change is Reviewable

Update AllocationTokenFlowUtils.loadAndValidateToken() to check
tokenEntity.getTokenType().isOneTimeUse() instead of checking only
TokenType.SINGLE_USE when reloading tokens from the database.

PR google#3157 added an uncached database reload for SINGLE_USE tokens to
prevent double-redemption within the 10-minute ALLOCATION_TOKENS_CACHE
TTL, but omitted TokenType.REGISTER_BSA (which also has
isOneTimeUse() == true). As a result, a REGISTER_BSA token already
redeemed in Cloud SQL remained unredeemed in JVM heap cache for up to 10
minutes and could be redeemed a second time without recording a
PostgreSQL SERIALIZABLE read dependency.

- Replace equals(TokenType.SINGLE_USE) with isOneTimeUse() in
  AllocationTokenFlowUtils.loadAndValidateToken() so all one-time-use
  token types (SINGLE_USE and REGISTER_BSA) reload fresh database state
  inside the active transaction before validation.
- Add unit tests in AllocationTokenFlowUtilsTest and
  DomainCreateFlowTest verifying that a cached REGISTER_BSA token
  already redeemed in the database is rejected with
  AlreadyRedeemedAllocationTokenException.

BUG= http://b/534931178
@CydeWeys
CydeWeys requested a review from jicelhay November 18, 2026 20:20
@CydeWeys
CydeWeys enabled auto-merge November 18, 2026 20:20

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant