Skip to content

Commit 99a1f85

Browse files
committed
Match S3 clock skew tolerance
Updates future timestamp validation to match AWS S3 behaviour. AWS tolerates future clock skew of up to 15 minutes for presigned requests.
1 parent 1f3d9f7 commit 99a1f85

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pkg/gateway/sig/v4.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ const (
3333
v4scopeTerminator = "aws4_request"
3434
v4timeFormat = "20060102T150405Z"
3535
v4shortTimeFormat = "20060102"
36-
AmzPresignMaxExpires = 7 * 24 * time.Hour // 7 days or 604800 seconds
36+
37+
AmzPresignMaxExpires = 7 * 24 * time.Hour // 7 days or 604800 seconds
38+
AmzMaxClockSkew = 15 * time.Minute // Maximum allowed clock skew (15 minutes for AWS S3 compatibility)
3739

3840
v4AmzAlgorithm = "X-Amz-Algorithm"
3941
//nolint:gosec
@@ -378,11 +380,12 @@ func (ctx *verificationCtx) verifyExpiration() error {
378380
now := time.Now().UTC()
379381
timeDiff := now.Sub(requestTime)
380382

381-
// Check for requests from the future and allow small clock skew
382-
if timeDiff < 0 && timeDiff.Abs() > 5*time.Minute {
383+
// Check for requests signed more than 15 minutes in the future (matches S3 behavior)
384+
if timeDiff < 0 && timeDiff.Abs() > AmzMaxClockSkew {
383385
return errors.ErrRequestNotReadyYet
384386
}
385387

388+
// Calculate expiration from the signed time, not current time
386389
expirationTime := requestTime.Add(time.Duration(ctx.AuthValue.Expires) * time.Second)
387390
if now.After(expirationTime) {
388391
return errors.ErrExpiredPresignRequest

0 commit comments

Comments
 (0)