fix: capture request date before network request to prevent clock skew/suspension bugs - #113
Open
paulb777 wants to merge 5 commits into
Open
fix: capture request date before network request to prevent clock skew/suspension bugs#113paulb777 wants to merge 5 commits into
paulb777 wants to merge 5 commits into
Conversation
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.
Description
Fixes #16573
Previously,
AppCheckCorecounted 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 JWTexpclaim 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
_GACURLSessionDataResponseto capture and store arequestDateproperty.NSURLSession+GACPromises.mto snapshot[NSDate date]right before invokingdataTaskWithRequestand passing it to the response object.appCheckTokenWithAPIResponse:inGACAppCheckAPIService.mandGACAppAttestAPIService.mto pass downresponse.requestDatetoinitWithTokenExchangeResponse:requestDate:error:._GACURLSessionDataResponsewith the newrequestDateinitializer correctly.