fix(auth): persist login bookkeeping atomically - #458
Merged
Merged
Conversation
Update only login counters, lockout and timestamps so an in-flight login cannot restore stale account security fields. Increment failed attempts in PostgreSQL to preserve concurrent failures. Verify service routing, concurrent security updates, mixed login ordering, lockout expiry and persistence errors against local PostgreSQL.
Contributor
|
Warning Review limit reached
This review includes 13 billable files and costs up to $3.25.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 30 minutes for your next included review. View limit detailsLimit details: You’ve used the included review currently available. Your 70 included PR review attempts over the past 7 days set your current allowance at 1 review per hour. Review configuration: ⚙️ Run configurationConfiguration used: Repository: LeanerCloud/cloud-commitments-platform/.coderabbit.yaml Review profile: CHILL Plan: Essentials Run ID: 📒 Files selected for processing (13)
Comment |
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.
Failed and successful login bookkeeping previously wrote a stale copy of the entire user row. A concurrent login could restore an old password, MFA configuration, group membership or activation state, and parallel failures could lose increments.
Replace those writes with two targeted PostgreSQL updates. Failure accounting increments the stored counter atomically; successful login resets the counter and lock and records its timestamp. Existing lockout duration, error responses and best-effort success bookkeeping remain unchanged. Recovery-code consumption remains separately tracked in #228.
Validation on Go 1.26.6:
go test -race ./..., build, vet and golangci-lint 2.10.1 passed. Normal commit hooks passed.Independent final verdict: approved with no actionable findings at
f1685d14d67faec8c98c84d6e72d01aab276cb29. A fresh PostgreSQL run of the committed login scenarios plus service/store error and enumeration tests passed with race detection in 22.680s. Removing only the production service fix at that same revision reproduced all four security rollback failures and the lost counter increment (expected-red exit 1, 1.746s).The larger test diff moves lockout assertions from mutable mock-user pointers to database readback. Added comments: 2 of 531 nonblank added lines (0.38%).
Closes #229.