fix(cache): validate TTL bounds to prevent immediate or infinite expiration (#445)#463
Conversation
|
Warning Review limit reached
More reviews will be available in 8 minutes and 35 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Contributed as part of GSSoC '26. Implemented strict input validation boundaries on cache lifetime configurations to eradicate resource leaks and unstable cache states.
Problem Description
Within
internal/cache/cache.go, theCacheConfigstruct accepted rawtime.Durationvalues for itsTTLfield without evaluating sanity bounds. Consequently, users or configuration Parsers could supply negative durations, zero durations, or abnormally large parameters.When zero or negative fields are used, items expire instantly, completely defeating the purpose of the layer and triggering high computational overhead. Conversely, overly massive parameters prevent stale entries from being collected, leaking memory resources indefinitely. Fixes #445.
Solution Implemented
1 * time.Minute) and an upper ceiling of 7 days (7 * 24 * time.Hour).CacheConfigdefinitions prior to engine initialization. Invalid lifetimes now trigger explicit errors rather than poisoning runtime states.internal/cache/cache_test.go. The test suite profiles edge cases including negative values (-5m), zero durations (0s), micro-values (10s), standard durations (2h), and out-of-bound configurations (10d) to ensure robust safety guarantees.Verification & Test Logs
go test -v ./internal/cache/...: PASSEDgo build ./...: PASSED