fix: update auth endpoint + stale lock file cleanup#486
Conversation
Apple's authentication service moved the endpoint from buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/authenticate to auth.itunes.apple.com/auth/v1/native/fast, and simultaneously moved the `authenticateAccount` key in the Bag XML from inside the `urlBag` dict to the root level. Changes: - bagResult: add root-level `authenticateAccount` plist field so the Bag() function reads it before falling back to urlBag (backward compat) - Bag(): append /fast suffix when the resolved endpoint uses the new auth.itunes.apple.com domain, matching what the Bag XML signals via `auth/v1/native: ["fast"]` - constants: add PrivateAuthDomain / PrivateAuthPathNative for the new endpoint - loginRequest: use the new auth endpoint as the hardcoded fallback (replaces the implicit empty-string which caused "something went wrong" when Bag lookup returned nothing) Without this fix every login attempt returns HTTP 200 with an empty body in ~1 ms, which the code surfaces as "something went wrong".
The juju/persistent-cookiejar library (via juju/go4/lock) creates a lock file at <cookies>.lock, writing the owner PID as JSON. If a process is killed between file creation (O_TRUNC) and the PID write, a 0-byte file remains. On the next startup the library skips PID-based stale detection (only runs when fi.Size() > 0) and falls back to os.OpenFile with O_EXCL, which fails because the file already exists. The result is "cannot load cookies: file locked for too long; giving up" on every subsequent invocation until the file is manually removed. Fix: in newCookieJar(), stat the lock path before opening the jar and remove the file if it is zero bytes. Zero-byte lock files are always stale because a live process always writes its PID immediately after creating the file.
|
pulled these changes into a local clone and tested against my Apple ID. The auth endpoint fix is clearly working now, the request actually reaches Apple's auth server instead of returning the old empty-body "something went wrong" error. I did hit a rate limit on the 2FA step though: To be clear, this 429 is coming from Apple's side (mzauth|global|all), not from anything in the patch. Before these changes the login never got far enough to even talk to the new endpoint, so reaching the point where Apple rate-limits us is actually a good sign that the new auth.itunes.apple.com/auth/v1/native/fast path is being used correctly. I'd been retrying logins a fair bit while testing, which probably tripped the limit. I'll wait it out and retry to confirm a clean end-to-end login. Thanks for putting this together. |
|
also getting the "Rate limit has been exceeded" error, even on a fresh account that hasn't been logged into for... weeks. |
With a residential proxy IP or my real residential IP, I have successfully logged in and downloaded IPA. No 429 error. With the following command you can test if your IP is being restricted or rate limited by Apple: If you get the following response and a 429 error, your IP is rate limited. Otherwise the response body will be empty (with 404 status code). |
|
thx u bro |
|
Got weird results. Other times with this: And others times results in an empty body with 204, causing this: That 204 looks like a success but it doesn't provide a password token or anything to use the API... |
Same 500 and 204 error for me: Also 404 and 403: And 301: |
|
Bad news: it looks like Apple changed their endpoint again. I'm getting this error for new login sessions. It doesn't matter which IP address or account I'm using. Existing login sessions aren't affected. |
|
I opened #490 with a smaller auth-only follow-up. It keeps the Bag root / One detail from testing: Validated with:
|
…st/) Without the trailing slash Apple returns 301 + an HTML redirect page, so the Configurator UA appears "blocked" at login and the plist parser fails. With the slash, the default Configurator/2.17 UA logs in and mints a commerce-grade passwordToken that buyProduct accepts end-to-end (purchase + download) with no anisette / kbsync / X-Apple-ActionSignature / device signature. - normalize the Bag-resolved auth endpoint to always end with /fast/ - PrivateAuthPathNative fallback gains the trailing slash - surface AMD-Action::SP as a clear "account requires browser sign-in" error
Problem
Apple's
26HOTFIX24(June 2026) brokeipatoollogin for all accounts, and the obvious "switch to the appstored User-Agent" workaround silently breaks purchase afterward.Two things changed:
authenticateAccountkey moved to the Bag root (it used to live underurlBag).https://auth.itunes.apple.com/auth/v1/native/fast/. Without it Apple returns301+ an HTML redirect page, which surfaces assomething went wrong/unexpected hex digit 'h'. The Bag now advertises…/auth/v1/native(no/fastat all), so the client must append/fast/.The trailing slash is the load-bearing fix: with it, the default
Configurator/2.17UA logs in and mints a commerce-gradepasswordTokenthatbuyProductaccepts. (Dodging the 301 by switching tocom.apple.appstored/1.0makes login look fixed but yields a download-grade token thatbuyProductrejects withfailureType 2034.)Changes
pkg/appstore/appstore_bag.go: readauthenticateAccountfrom the Bag root andurlBag, and normalize the resolved endpoint to always end with/fast/.pkg/appstore/constants.go:PrivateAuthPathNativefallback gains the trailing slash; add theAMD-Action::SPcustomer-message constant.pkg/appstore/appstore_login.go: surfaceAMD-Action::SPas a clear "account requires browser sign-in" error.cmd/common.go: remove a stale zero-byte cookie lock file on startup (independent bug).Validation
Verified end-to-end (login + purchase + download) across many accounts with the stock Configurator UA — no anisette / kbsync / device signature needed. See #485 for the detailed write-up.