Repository navigation
iclouddrive: fix 2FA failing with 409 even when the code is valid - #9660
Merged
Merged
Conversation
Since around mid-2026 Apple's idmsa endpoints
POST /verify/trusteddevice/securitycode and
POST /verify/phone/securitycode return HTTP 409 (instead of 2xx) even
when the submitted code is accepted: the response body carries
"securityCode": {..., "valid": true} and - decisively - the response
headers include a fresh X-Apple-Session-Token, scnt and
X-Apple-Auth-Attributes, which are only issued on successful
validation. rclone treated any 409 as failure and aborted before
TrustSession, so configuring an iclouddrive remote always failed after
the 2FA step with:
validate2FACode failed: HTTP error 409 (409 ) returned body:
"{... \"securityCode\": {\"code\": \"...\", \"valid\": true} ...}"
Treat a 409 response that carries X-Apple-Session-Token as success:
absorb the session headers and continue to TrustSession. Applies to
both the trusted-device and SMS validation paths.
Verified against a live account (13 trusted devices, ADP off): config
now completes and lsjson/lsd/copy work.
Fixes rclone#9324
Fixes rclone#9359
Co-Authored-By: Claude Opus 5 <[email protected]>
ncw
approved these changes
Jul 29, 2026
ncw
left a comment
Member
There was a problem hiding this comment.
Thank you for this.
I'm going to merge it now since it has had some user testing.
6 of 7 tasks
5 of 8 tasks
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.
What is the problem you are trying to fix?
Configuring an
iclouddriveremote fails after entering the 2FA code (both trusted-device push and SMS paths) with:Note the body says the code is valid — yet rclone reports failure. Reported in #9324 and #9359 (and several forum threads).
What is the root cause?
Apple changed the semantics of the idmsa validation endpoints (observed ~mid-2026):
POST /verify/trusteddevice/securitycodeandPOST /verify/phone/securitycodenow return HTTP 409 even on successful validation. A--dump headerstrace shows the 409 response carries everything a success used to carry:X-Apple-Session-Token: …(only issued on successful validation)ScntandX-Apple-Auth-AttributesX-Apple-ID-Account-Country"securityCode": {…, "valid": true}rclone's
Session.Requesttreats any non-2xx as an error, so both validate paths abort beforeTrustSession— discarding the session token Apple just issued.What is your fix?
Add
Session.acceptedDespiteConflict(resp): if the response is a 409 and carriesX-Apple-Session-Token, absorb the session headers (extractHeaders) and treat validation as successful, then continue toTrustSessionas before. Applied to bothValidate2FACodeandValidateSMSCode. A plain 409 without the token (e.g. a genuinely wrong/expired code) still fails as before.How was it tested?
Built from master (
c99b2d11e) and verified against a live account (2FA, 13 trusted devices, ADP off, standard recovery): before the patch, config failed with the exact error above on every attempt (device-push and SMS codes, all reportedvalid:true); with the patch,rclone config createcompletes the 2FA step, the trust token is persisted, andlsd/lsjson -R/copyagainst the remote work.Checklist
🤖 Generated with Claude Code