Skip to content

fix: repair the SMS 2FA flow (active 412 challenge and -22979/-22981 throttling) - #9

Open
BK0STAR wants to merge 1 commit into
nab138:apple-codesign-quickfrom
BK0STAR:fix/sms-2fa-active-challenge
Open

fix: repair the SMS 2FA flow (active 412 challenge and -22979/-22981 throttling)#9
BK0STAR wants to merge 1 commit into
nab138:apple-codesign-quickfrom
BK0STAR:fix/sms-2fa-active-challenge

Conversation

@BK0STAR

@BK0STAR BK0STAR commented Aug 10, 2026

Copy link
Copy Markdown

Problem

The SMS 2FA flow fails (reported in nab138/iloader#319): send_sms_2fa treats every non-2xx response without serviceErrors as fatal. Two cases were mishandled:

  1. HTTP 412 with an active SMS challenge — Apple returns a valid challenge (mode: sms, trusted number, no lockout flags), but the request aborted instead of moving on to code entry.
  2. Throttling -22979 / -22981 ("Too many verification codes…") — routed to NeedsUnknown2FA, which loses the selected phone number and forbids SubmitCode/ResendCode. Yet -22979 explicitly says "Enter the last code you received": a code was already sent and stays valid.

In addition, the phone number ID was hardcoded to 1 instead of loading the trusted phone numbers.

Fix

  • Strict 412 classification (classify_sms_send_response): checks mode, authenticationType: hsa2, matching phone-number id, code length 6, and no lockout flags → SmsSendOutcome::ActiveChallenge (proceeds to verification).
  • -22979 / -22981NeedsSMS2FAVerification(id) with last_error, keeping the selected number and without triggering another send.
  • -28248 → kept as NeedsUnknown2FA (choose another method).
  • Load the trusted phone numbers instead of the hardcoded 1.

Tests

  • Added sms_send_response_tests (10 contract tests: active challenge, wrong number, malformed response, lockout flags, preserved service errors).
  • Added cargo test -p isideload to CI.
  • cargo test -p isideload: 10/10 passing.

Real-world verification

Tested end-to-end with iloader (v2.3.1 + this isideload): at -22979, the UI shows the code-entry field with the selected number kept; a code generated from a trusted device completes the login. ✅

Fixes nab138/iloader#319

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes edge cases in the Apple SMS 2FA flow by correctly handling “active SMS challenge” (HTTP 412) and SMS throttling service errors (-22979/-22981), while avoiding a hard-coded trusted phone number ID by requiring selection from the retrieved trusted numbers.

Changes:

  • Add strict classification for SMS send responses to treat HTTP 412 as an already-active SMS challenge when the response matches expected hsa2 + selected number + unlocked 6-digit code constraints.
  • Preserve and route throttling service errors -22979 / -22981 to SMS code entry (NeedsSMS2FAVerification(id)) without losing the selected number or triggering a resend.
  • Add contract-style unit tests for SMS send response classification and run cargo test -p isideload in CI.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
isideload/src/auth/apple_account.rs Improves SMS 2FA send error handling/classification, preserves selected phone number across throttling, adds tests, and removes hard-coded trusted number selection.
.github/workflows/build.yml Adds CI coverage for isideload tests to catch regressions in the auth flow.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 324 to 326
info!(
"The most recently attempted 2FA Method failed, please try a different method."
);
…throttling)

- Classify a 412 response carrying an active SMS challenge instead of
  aborting, so the user can enter the code that was already sent.
- Map -22979/-22981 (throttling) to NeedsSMS2FAVerification(id), keeping the
  selected number and last_error, without triggering another send.
- Keep -28248 mapped to NeedsUnknown2FA (choose another method).
- Stop hardcoding phone number ID 1: load the trusted phone numbers.
- Add the sms_send_response_tests contract tests and a cargo test CI step.
@BK0STAR
BK0STAR force-pushed the fix/sms-2fa-active-challenge branch from e0a5f07 to f560857 Compare August 10, 2026 18:07
@BK0STAR BK0STAR changed the title fix: corriger le flux SMS 2FA (challenge 412 actif et throttling -22979/-22981) fix: repair the SMS 2FA flow (active 412 challenge and -22979/-22981 throttling) Aug 10, 2026
BK0STAR added a commit to BK0STAR/iloader that referenced this pull request Aug 10, 2026
The 2FA bridge only handled SubmitCode; isideload also requires SendSms,
SendToDevices, ResendCode and Abort.

- Tauri backend: a typed async request_two_factor_response exchanging
  TwoFactorCallbackParams/Response over the 2fa-required/2fa-response events,
  with a timeout and a clean Abort path.
- UI: trusted-method and trusted-number pickers, resend code, send to devices,
  last_error display, and associated styles.
- EN/FR locales for the new strings.
- Parsing tests for all TwoFactorCallbackResponse variants.

Depends on nab138/isideload#9 (the isideload-side 2FA logic).
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.

2 participants