Skip to content

Conversation

@relaxolotl
Copy link
Contributor

@relaxolotl relaxolotl commented Oct 21, 2021

Hitting https://idmsa.apple.com/appleauth/auth when an account has zero trusted devices and one trusted phone number will request a new code. This endpoint is being requested twice during 2FA auth. The second request is sent right before the first code is verified, making it impossible for the user to submit a valid code.

For users with different configurations, such as a single trusted device and a trusted phone number, the aforementioned endpoint merely returns information about trusted phone numbers.

This PR contains two primary changes which fix this issue:

  • Removing the second request to https://idmsa.apple.com/appleauth/auth, and caching its results so it can be used during verification.
  • Skipping an extra request to create and send an SMS code to a user if https://idmsa.apple.com/appleauth/auth has already sent a code

@relaxolotl relaxolotl requested review from a team, Swatinem, flub and loewenheim October 21, 2021 22:55
push_mode=info["pushMode"],

# The code has already been sent to the only trusted phone number
sms_automatically_sent = len(info.get("trustedPhoneNumbers", [])) == 1 and info.get(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this logic is basically pulled from fastlane's implementation.

they also have more complex logic to handle other cases, such as when a user has multiple trusted phone numbers, etc.

in the same file, they also skip hitting https://idmsa.apple.com/appleauth/auth/verify/phone when these two checks are true.

self.state = ClientState.AUTHENTICATED

def _request_trusted_phone_info(self) -> TrustedPhoneInfo:
def _request_trusted_phone_info(self) -> Tuple[TrustedPhoneInfo, bool]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'm not particularly married to this return type.

Copy link
Contributor

@flub flub left a comment

Choose a reason for hiding this comment

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

Nice find!

Might as well try and merge this still before the weekend. (or you can wait till Mon if like me you don't like deploying on Fridays)


if sms_automatically_sent:
self.state = ClientState.SMS_AUTH_REQUESTED
self._trusted_phone = trusted_phone
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems a bit odd together with the new assert on line 378?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry about that, this is a little strange. i'm pretty sure this assert is supposed to sit inside of sms_code 🤔 i'll fix this.

raise ITunesError(f"Unexpected response status: {response.status_code}")

self.state = ClientState.SMS_AUTH_REQUESTED
self._trusted_phone = trusted_phone
Copy link
Contributor

Choose a reason for hiding this comment

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

can't we be already sure this is already set by now?

@relaxolotl relaxolotl enabled auto-merge (squash) October 22, 2021 16:13
@relaxolotl relaxolotl merged commit 3429181 into master Oct 22, 2021
@relaxolotl relaxolotl deleted the fix/double-sms-2fa branch October 22, 2021 16:30
@github-actions github-actions bot locked and limited conversation to collaborators Nov 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants