Skip to content

Conversation

mats-stripe
Copy link
Collaborator

@mats-stripe mats-stripe commented Sep 24, 2025

Summary

This makes a few tweaks to the StripeAttest client to better handle client and server state mismatches. There are two scenarios this addresses:

  1. Client thinks it's not attested, but server has attestation
    • Action: Client updates its local state to match server
  2. Client thinks it's attested, but server needs attestation
    • Action: Client resets and re-attests

I'm adding a feature flag link_mobile_attestation_state_sync_enabled to control this new behavior, as we don't know yet if it is a risky change.

I'm also adding new analytic events for those two scenarios,

Motivation

More details here https://docs.google.com/document/d/1NMQoDpCOv4dvYjMmwfrsezGhc---wKy2eFkeH_DBjAQ/edit?usp=sharing

Testing

Unit tests added

Changelog

N/a

@mats-stripe mats-stripe force-pushed the mats/attestation_improvements branch from b45c7d8 to a499cec Compare September 24, 2025 19:37
@mats-stripe mats-stripe force-pushed the mats/attestation_improvements branch from dfe6012 to 09901b9 Compare September 24, 2025 21:13
} else {
// Reset and retry
resetKey()
try await self.attest()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The one thing I wasn't totally sure of is if we should re-attest here, since the client has keys that the server doesn't have. Curious what you think @davidme-stripe @tillh-stripe

Copy link
Collaborator

Choose a reason for hiding this comment

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

resetKey() resets successfullyAttested to false, so we can probably skip attest() and just call _assert(isRetry: true).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh duh! Will remove this line

let linkDefaultOptIn = (response["link_default_opt_in"] as? String).flatMap { LinkDefaultOptIn(rawValue: $0) }
let linkEnableDisplayableDefaultValuesInECE = response["link_enable_displayable_default_values_in_ece"] as? Bool ?? false
let linkShowPreferDebitCardHint = response["link_show_prefer_debit_card_hint"] as? Bool ?? false
let attestationStateSyncEnabled = response["link_mobile_attestation_state_sync_enabled"] as? Bool
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment on lines +263 to +264
// Server has attestation but client doesn't know - update client
successfullyAttested = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

This feels like a band-aid, since attest would set successfullyAttested = true. Do you strongly feel that we need it?

(If you think so, let's also instrument it, so that we know if this ever occurs.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is reasonable, as it will let the client assert when the server thinks it has successfully attested. No super strong opinions on where we go with this though.

I can add logs for the two cases here!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added logs here ec4645e

} else {
// Reset and retry
resetKey()
try await self.attest()
Copy link
Collaborator

Choose a reason for hiding this comment

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

resetKey() resets successfullyAttested to false, so we can probably skip attest() and just call _assert(isRetry: true).

@mats-stripe mats-stripe marked this pull request as ready for review September 26, 2025 15:01
@mats-stripe mats-stripe requested review from a team as code owners September 26, 2025 15:01
@mats-stripe mats-stripe changed the title Improve error handling in StripeAttest Improve state mismatch issues in StripeAttest Sep 26, 2025
@mats-stripe mats-stripe force-pushed the mats/attestation_improvements branch from 79b07b2 to eb64767 Compare September 26, 2025 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants