Skip to content

fix: capture request date before network request to prevent clock skew/suspension bugs - #113

Open
paulb777 wants to merge 5 commits into
mainfrom
pb-fix-appcheck-token-expiry2
Open

fix: capture request date before network request to prevent clock skew/suspension bugs#113
paulb777 wants to merge 5 commits into
mainfrom
pb-fix-appcheck-token-expiry2

Conversation

@paulb777

@paulb777 paulb777 commented Sep 1, 2026

Copy link
Copy Markdown
Member

Description

Fixes #16573

Previously, AppCheckCore counted a cached token's time-to-live starting from the moment the token response was processed locally ([NSDate date]). Because we don't trust device clock skew, parsing the JWT exp claim directly is undesirable. However, counting from the response processing time introduces a bug where any delay (e.g., app suspension or a stalled thread) between the token request and the response handler executing is silently converted into extra token lifetime.

This PR implements the recommended fix: taking a snapshot of the device timestamp before sending the token exchange request, and using that timestamp instead of generating a new one after the response is received.

Changes

  • Updated _GACURLSessionDataResponse to capture and store a requestDate property.
  • Updated NSURLSession+GACPromises.m to snapshot [NSDate date] right before invoking dataTaskWithRequest and passing it to the response object.
  • Modified appCheckTokenWithAPIResponse: in GACAppCheckAPIService.m and GACAppAttestAPIService.m to pass down response.requestDate to initWithTokenExchangeResponse:requestDate:error:.
  • Updated all associated unit tests to instantiate _GACURLSessionDataResponse with the new requestDate initializer correctly.

@paulb777
paulb777 requested review from ncooke3 and weixifan September 1, 2026 21:28
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.

1 participant