Skip to content

Commit 50b3025

Browse files
sangwaclaude
andcommitted
fix: clamp defaultTTL to 24h cap in parseCacheTTL
A configured http.cache.default_ttl >24h would bypass the documented 24h cap because the default return path did not clamp the value. Now parseCacheTTL clamps defaultTTL at entry so all return paths (max-age, Expires, and default) respect the cap. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ad7ddbf commit 50b3025

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

internal/endorsements_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,13 @@ func TestParseCacheTTL(t *testing.T) {
433433
}
434434
})
435435
}
436+
437+
t.Run("defaultTTL capped at 24h", func(t *testing.T) {
438+
got := parseCacheTTL(http.Header{}, 48*time.Hour)
439+
if got != 24*time.Hour {
440+
t.Errorf("parseCacheTTL() with 48h default = %v, want %v", got, 24*time.Hour)
441+
}
442+
})
436443
}
437444

438445
// --- parseByteSize ---

internal/fetch.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ func (s *Server) fetchHTTPClient() *http.Client {
122122
// Cache-Control for max-age and no-cache/no-store, falls back to the
123123
// Expires header, and defaults to defaultTTL. TTL is capped at 24 hours.
124124
func parseCacheTTL(header http.Header, defaultTTL time.Duration) time.Duration {
125+
if defaultTTL > fetchMaxTTL {
126+
defaultTTL = fetchMaxTTL
127+
}
125128
if cc := header.Get("Cache-Control"); cc != "" {
126129
lower := strings.ToLower(cc)
127130
if strings.Contains(lower, "no-cache") || strings.Contains(lower, "no-store") {

0 commit comments

Comments
 (0)