fix(gateway): don't penalise approve_code when all pending entries are legacy format - #30409
Open
AhmetArif0 wants to merge 1 commit into
Open
AhmetArif0 wants to merge 1 commit into
AhmetArif0 wants to merge 1 commit into
Conversation
…e legacy After the hash-storage migration (PR NousResearch#30383), approve_code() skips legacy pending entries (no salt/hash fields) but still called _record_failed_attempt() when matched_key was None — even when the ONLY reason for no match was that every entry in pending was legacy format from before the upgrade. An admin who calls approve_code during the post-upgrade window (before the 1-hour TTL prunes old entries) would accumulate failure counts for calls that were never real brute-force attempts, triggering a lockout after MAX_FAILED_ATTEMPTS such calls. Fix: track any_new_format_checked. Skip failure recording when pending is non-empty but every entry is legacy (any_new_format_checked is False). Empty pending and real hash-format mismatches still count as genuine failures, preserving brute-force protection. Adds a regression test: MAX_FAILED_ATTEMPTS+1 approve_code calls with a legacy-only pending file must not trigger lockout.
Collaborator
|
Thanks for the focused regression fix. The premise remains valid on current main: The legacy fixture on current main has the expected persisted shape at Automated hermes-sweeper review. |
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.
Problem
PR #30383 migrated gateway pairing codes from plaintext storage to salted SHA-256
hashes. The new
approve_code()loop correctly skips legacy pending entries(entries without
salt/hashfields) to avoid crashing on in-place upgrades.However, when
matched_keyisNoneat the end of the loop,_record_failed_attempt()is unconditionally called — even when the only reason for no match is that every
entry in
pendingis a legacy pre-upgrade entry.Impact: An admin who calls
approve_codeduring the post-upgrade window (beforethe 1-hour TTL prunes old entries) silently accumulates failure counts for calls that
are not real brute-force attempts. After
MAX_FAILED_ATTEMPTS(5) such calls theplatform is locked out, blocking all new pairing requests.
Root cause
Fix
Track whether at least one hash-format entry was examined. Skip
_record_failed_attemptonly whenpendingis non-empty but every entry islegacy format. Empty pending and real hash-format mismatches still count as
genuine failures, preserving brute-force protection.
Behaviour matrix
Test
Adds
test_legacy_only_pending_does_not_trigger_lockouttoTestLegacyPendingFileCompat: callsapprove_codeMAX_FAILED_ATTEMPTS + 1times against a legacy-only pending file and asserts no lockout fires, then
confirms a legitimately generated new-format code still approves correctly.
All 41 existing tests pass.
Checklist