feat: make direct-edit token consumption transactional and race-safe; defer deletion to successful open paths#5465
Draft
joshtrichards wants to merge 5 commits intomainfrom
Draft
Conversation
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
- strict_types - parameter type hints - function return typing Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes one-time direct-edit token handling in
DirectViewController::show()transactional and race-safe.Previously, tokens were deleted immediately after lookup, so transient failures later in the flow could burn a valid link. This change adds transactional row-level locking (
getByToken(..., forUpdate)) and moves deletion to success paths:Result: better resilience to transient failures and stronger protection against concurrent replay/race scenarios, with semantics shifted from “consume on first access” to “consume on successful open/redirect.”
Additional Details (Expand)
Changed:
DirectViewController::show()in a DB transactionDirectMapper::getByToken()and used it in the direct-edit flowWhy:
Security impact:
Net: positive hardening, especially for concurrency/replay races, with an intentional UX/security tradeoff.
Transaction impact:
The token row lock may be held longer (through more request work), which can increase lock wait time for concurrent hits on the same token. Expected impact is typically modest and localized to that token. A future token state machine could reduce lock duration while preserving correctness.
TODO
Checklist