fix(pin): coalesce concurrent PIN check/confirm (lockout under-count + torn salt/hash)#669
Open
joshuakrueger-dfx wants to merge 1 commit into
Open
Conversation
26a59cd to
d541f9b
Compare
…-count and torn salt+hash Concurrent VerifyPinCubit.checkPin() calls for one submission shared no serialization, so two parallel wrong attempts both read the same failed-attempts baseline and persisted the same incremented value — under-counting the lockout cascade and widening the brute-force window. SetupPinCubit._confirmPin() could likewise run twice (a confirm re-typed during the slow PBKDF2 hash), interleaving two salt+hash writes into a torn pair that no longer verifies and locks the user out of their own wallet. Both critical sections are now wrapped in a private in-flight Future that coalesces concurrent callers onto one round-trip and clears on completion, so the counter advances exactly once and the salt+hash pair is always written atomically from a single run. No public API added. Regression: test/screens/pin/verify_pin_cubit_test.dart:267 Regression: test/screens/pin/setup_pin_cubit_test.dart:163 Boundary: Tier 1 Architect-spec: fixer/fix-spec.md (loop fleet-20260603-190231-84831-2, iter 1) mandate-hash: b59fe886f6702d4c loop-id: fleet-20260603-190231-84831-2 iteration: 1
d541f9b to
a527c7f
Compare
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.
Addresses Issue #657 — Part 2 Auth & PIN, findings F-01 (HIGH, security) and F-09 (HIGH).
Problem
verify_pin_cubit.dart): concurrentcheckPin()calls for one submission shared no serialization → two parallel wrong attempts read the same failed-attempts baseline and persisted the same incremented value, under-counting the lockout cascade and widening the brute-force window.setup_pin_cubit.dart):_confirmPin()could run twice (confirm re-typed during the slow PBKDF2 hash), interleaving two salt+hash writes into a torn pair that no longer verifies → user locked out of their own wallet.Fix
Both critical sections are wrapped in a private in-flight
Futurethat coalesces concurrent callers onto one round-trip and clears on completion → the lockout counter advances exactly once and the salt+hash pair is always written atomically. No public API added.Tests (RED→GREEN)
verify_pin_cubit_test.dart— F-01: two parallelcheckPinof one submission advance the counter oncesetup_pin_cubit_test.dart— F-09: confirm re-typed during the in-flight hash writes one atomic salt+hashflutter analyzeclean.