Skip to content

fix(core): canonicalize sign-in URLs and safely handle non-plist replies - #23

Closed
gbgb66 wants to merge 3 commits into
Kosthi:masterfrom
gbgb66:fix/auth-html-diagnostics
Closed

gbgb66 wants to merge 3 commits into
Kosthi:masterfrom
gbgb66:fix/auth-html-diagnostics

Conversation

@gbgb66

@gbgb66 gbgb66 commented Oct 24, 2026 •

Copy link
Copy Markdown

Apple's bag can advertise the bare /wa/authenticate URL. Posting to that path can return an empty HTTP 204 or HTML instead of reaching the Store handler. This PR canonicalizes the validated initial URL to /wa/authenticate/, preserving its host and routing query. It follows upstream's October 5 fix: majd/ipatool@f9aa653.

The accompanying recovery and diagnostics fix handles 0.1.8's Serde("invalid type: string \"<html>\", expected a map"): a 301 without Location previously fell through to plist deserialization, and the existing Store-error retry could never run. Transient non-plist replies (204, 404, 5xx, or redirects without Location) receive at most three total sends, 250 ms apart, with identical signed bytes and the same attempt counter. A Store dictionary remains authoritative at any HTTP status. The helper does not resend 403, 429, or real redirects.

HTML is rejected before plist normalization. Auth parse diagnostics report only status, an allowlisted media type, and byte count; response previews, raw parser values, and full redirect-URL debug output are removed from this path. Endpoint validation remains before normalization and before forwarding credentials. No dependency or lockfile changes.

Related: #17 and #19. This overlaps #19's recovery behavior and adds URL canonicalization, actual HTTP resend tests, and diagnostics without response snippets.

Validation on macOS 27.0.1 (26A434), Apple Silicon, Rust 1.99.1:

  • Actual login path, synthetic credentials only: api::auth::login with a reserved .invalid account reproduced empty HTTP 204 before URL normalization. Adding only the trailing slash returned a structured Store response. A repeated A/B comparison gave HTML 403 on the bare URL and a Store response on the slashed URL. With the fix in parse_bag, the normal login path returned the expected BadLogin rejection for the fictitious account. No user password, 2FA, token, signature, or response body was printed.
  • Regression coverage: the new URL test failed before the fix and passes afterward; it covers bare/slashed initial URLs, pod hosts, and retained Pod/PRH query parameters. The seven earlier new tests cover real loopback HTTP retries, identical signed request bytes, exhaustion, redirects, structured 500 replies, 403/429, HTML 200, HTML preambles, and privacy of Display/Debug errors.
  • cargo test --locked --workspace: 115 passed, 8 opt-in network tests ignored.
  • make check (formatting plus clippy with warnings denied) and cargo build --release --locked passed; ARM64 binary smoke checks passed.
  • A real Apple SAP handshake/signing test passed independently without Apple ID credentials.

The user subsequently verified a successful real-account login with the rebuilt ARM64 binary on macOS 27.0.1: the CLI reported a successful login and account information. This is user-reported end-to-end confirmation; the agent did not receive or use the user's password or 2FA code. Account names, email, DSID, storefront and pod values are omitted from this report. Persistent service rejection still fails after bounded retries.

@gbgb66 gbgb66 changed the title fix(core): safely retry and diagnose non-plist auth responses fix(core): canonicalize sign-in URLs and safely handle non-plist replies Oct 24, 2026

@Kosthi Kosthi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for putting this together! Apple's edge now drops the legacy MZFinance.woa/wa/authenticate endpoint even with the trailing slash, and sign-in routes through auth/v1/native with Store ADI device provisioning (X-Apple-AMD / X-Apple-AMD-M). Closing in favor of #25, which implements the native Store authentication flow and non-plist response handling.

@Kosthi Kosthi closed this Nov 30, 2026
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