ipatool icon indicating copy to clipboard operation
ipatool copied to clipboard

fix: resolve login authentication endpoint redirects and redundant bag requests

Open yunusemreyazici opened this issue 5 months ago • 2 comments

This PR resolves issues with the auth login command failing due to changes in Apple's authentication backend and an inefficient retry mechanism.

  1. Fixed Redundant Bag Requests during 2FA Inputs Problem: The AppStore.Bag() call was placed inside the retry.Do loop in cmd/auth.go. When a user was prompted for a 2FA code, the block retried and triggered a second request to https://init.itunes.apple.com/bag.xml, causing rate-limiting/timeouts (read: operation timed out). Fix: Moved the AppStore.Bag() retrieval outside/before the retry.Do loop so it only requests the API bag configuration once.
  2. Added Trailing Slash to Native Authentication Endpoint Problem: The bag configuration returns https://auth.itunes.apple.com/auth/v1/native for authentication. Sending a POST directly to this URL returns a 200 OK with Content-Length: 0 because it redirects the request, stripping the POST body. Fix: Programmatically check the endpoint and append /fast/ (with a trailing slash) to native endpoints so it targets https://auth.itunes.apple.com/auth/v1/native/fast/. This allows Apple's servers to successfully process the credentials.
  3. Adjusted Request Content-Type to match Plist Payload Problem: The authentication request sent plist data but used "Content-Type": "application/x-www-form-urlencoded". Fix: Changed the header to "Content-Type": "application/x-apple-plist" to match the actual XML/plist format of XMLPayload sent to Apple.

Summary by cubic

Fixes login failures by handling Apple’s native auth redirect and preventing duplicate bag requests. Login is now reliable during 2FA and avoids rate limits/timeouts.

  • Bug Fixes
    • Move AppStore.Bag() outside the retry loop to stop redundant bag requests during 2FA.
    • Normalize native auth endpoint to /auth/v1/native/fast/ (ensure trailing slash) to avoid redirect that drops the POST body.
    • Set request header to Content-Type: application/x-apple-plist to match the plist payload.

Written for commit ee99c76c5e228d5f4839133de0d0bced74dc49a1. Summary will update on new commits.

Review in cubic

yunusemreyazici avatar Jun 21 '26 20:06 yunusemreyazici

just wanted to chime in and say that I applied this diff and login is working properly.

charlie632 avatar Jun 22 '26 14:06 charlie632

Worked fine for me yesterday but today I am getting 404 with this diff

4:32PM ERR error="request failed: failed to unmarshal xml (HTTP 404): plist: error parsing text property list: missing = in dictionary at line 0 character 16; response body: {\"errorMessage\":\"Try again later.\",\"status\":-1}" success=false

Gautam010 avatar Jun 24 '26 11:06 Gautam010

Closing in favor of a simpler fix in https://github.com/majd/ipatool/pull/507

majd avatar Jul 05 '26 10:07 majd