fix: skip clock skew calculation for cached responses (Age header) - #3431
Open
toller892 wants to merge 1 commit into
Open
fix: skip clock skew calculation for cached responses (Age header)#3431toller892 wants to merge 1 commit into
toller892 wants to merge 1 commit into
Conversation
When a response is served from a cache (e.g. CloudFront), the Date header reflects when the original response was generated, not the current server time. Using it for clock-skew calculation produces incorrect results that cause subsequent requests to fail with signature expiration errors. Check for the standard HTTP Age header and skip skew computation when present, as suggested by the maintainer in aws#3409. Fixes aws#3409.
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.
Problem
When a response is served from a cache (e.g. CloudFront), the
Dateheader reflects when the original response was generated, not when it is being served. The SDK'sRecordResponseTimingmiddleware uses thisDateheader to compute clock skew, which produces incorrect results for cached responses.Once skew is calculated incorrectly, the next AWS call fails with a signature expiration error. The failing response then has a correct
Dateheader, so subsequent calls succeed — but every first call after a cached response fails.See #3409 for full reproduction steps and raw HTTP traces.
Fix
Check for the standard HTTP
Ageheader inRecordResponseTiming.HandleDeserialize. When present, skip clock skew computation entirely, as theDateheader is unreliable for skew calculation on cached responses.This approach was suggested by @lucix-aws in #3409:
Changes
aws/middleware/middleware.go: AddAgeheader check before computing skewaws/middleware/middleware_test.go: Add test case for cached response withAgeheaderFixes #3409