Repository navigation
Conversation
Sign-in fails outright when Apple answers with something that never reached MZFinance. Issue #17 reports a 301 carrying an HTML body and no Location header; the same report also saw a contentless 204, and majd/ipatool#520 saw both, with which endpoint misbehaved swapping between attempts from the same host minutes apart. None of those replies carry Apple's backend headers, so they are the edge dropping the request rather than a verdict on the account -- the reporter's own bag probe still lists MZFinance/authenticate under sign-sap-request, and sign-in works from other hosts at the same moment. The existing retry loop cannot help: it only fires on a StoreError parsed out of a plist body, so a reply that is empty or is HTML fails before it is reached. A 301 without a Location also falls past the redirect branch into the plist parser, which is why the failure surfaces as `invalid type: string "<html>", expected a map`. Resend the identical signed bytes up to three times, 250ms apart, while the reply carries no store response. Signing happens once per attempt, outside the resend loop: Apple signs the exact bytes it receives and those do not change between sends. The `attempt` value in the body is Apple's own counter and stays put -- a resend is not a new attempt. The retryable set is 204, 404, 5xx and a 3xx with no Location, but a body that parses as a property list settles the request whatever the status: Apple reports real failures under a 5xx, and dispatching on the status alone would swallow them. Two statuses are deliberately excluded. 403 is the application tier rejecting an unsigned request, and resending it would bury the SapSignatureRequired diagnosis. 429 is a rate limit, and hammering it is the one response guaranteed to make it worse. When all three sends are dropped, report every status seen and say the network path is the suspect, so the next reader does not go looking for a bug in the request. A non-plist body now reports its status and a snippet instead of reaching the parser at all. Upstream took the same approach in majd/ipatool@30d19a6, but keys only off the status and leaves the Location-less 3xx unhandled, which is the exact shape #17 hit. Refs #17
The User-Agent is load-bearing and nothing said so. `bag.xml` hands out a different `authenticateAccount` depending on who asks, so the endpoint allowlist and the SAP setup URL both follow from this constant -- with the iTunes UA the setup URL loses its `/legacy` suffix, which may well be a different handshake variant. Issue #17 read a bag dump taken with a different UA as evidence that Apple had migrated sign-in for everyone, which is the mistake this table is here to prevent. Refs #17
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.
Closes the failure reported in #17.
What is happening
Sign-in fails outright when Apple answers with something that never reached MZFinance. #17 reports a
301carrying an HTML body and noLocationheader; the same report also saw a contentless204. majd/ipatool#520 saw both, and — the useful part — watched which endpoint misbehaved swap between attempts from the same host minutes apart:None of those replies carry Apple's backend headers (
apple-originating-system,x-responding-instance), so they are the edge dropping the request, not a verdict on the account. An unsigned probe from a working host still gets the application tier's403+x-responding-instance: MZFinance:…, and #17's own bag dump still listsMZFinance: [authenticate]undersign-sap-request. The endpoint is alive; the request is not arriving.So this does not move sign-in to
auth.itunes.apple.com/auth/v1/native/fast, which #17 proposes. Upstream tried that route (majd/ipatool#507, #514) and removed it again in majd/ipatool@abd86cb when SAP signing landed; its endpoint allowlist matches ours today.Why the existing retry never fired
login()'s loop only retries on aStoreErrorparsed out of a plist body, so a reply that is empty or is HTML fails before it is reached. A301with noLocationalso falls past the redirect branch straight into the plist parser — which is why the user-visible error isinvalid type: string "<html>", expected a map.The change
Resend the identical signed bytes up to 3 times, 250ms apart, while the reply carries no store response.
attemptvalue in the body is Apple's own counter and stays put — a resend is not a new attempt.204,404,5xx, and a3xxwith noLocation. But a body that parses as a property list settles the request whatever the status — Apple reports real failures under a5xx, and dispatching on status alone would swallow them.403(the application tier rejecting an unsigned request; resending buries theSapSignatureRequireddiagnosis) and429(hammering a rate limit is the one response guaranteed to make it worse).Upstream took the same approach in majd/ipatool@30d19a6, but keys only off the status and leaves the
Location-less3xxunhandled (pkg/http/client.gopasses every3xxstraight through) — the exact shape #17 hit.Testing
is_dropped_requestandlooks_like_plistare pure and unit-tested: bare301, pod302,204, HTML404,5xx,5xxcarrying a plist,403,429, plus the HTML-vs-plist discrimination.cargo clippy --workspace --all-targetsis clean;cargo test --workspacepasses 109 + 7.The resend loop itself is not covered — the workspace has no HTTP mock dev-dependency, and adding one felt out of scope here.
Not addressed
StoreError::RateLimitedstill has no construction site, so a429reports as a non-plist body rather than as a rate limit. Small, but separate.