fix: microcache error responses instead of pinning long-TTL (closes #5)#8
Merged
Conversation
AuthImagingHandler.finish() applied _cache_control_override to every response regardless of status, so a transient Thumbor 400 (e.g. PIL decompression-bomb rejection) inherited "public, max-age=31536000, immutable" and got pinned in Varnish/CDN for a year — one bad fetch persistently hid the image on every shard that cached it. Gate the long-TTL override on 2xx. For 4xx/5xx apply a short microcache header instead (PGTHUMBOR_CACHE_CONTROL_ERROR, default "public, max-age=10"): decouples transient errors from long-term cache poisoning AND lets downstream caches absorb request floods for broken URLs — a cheap DoS amplification defense. 3xx is left untouched. Closes #5. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
AuthImagingHandler.finish()applied the long-TTLCache-Controloverride to every response, so a transient Thumbor 400 (e.g. PIL decompression-bomb rejection) inheritedpublic, max-age=31536000, immutableand got pinned in Varnish/CDN for a year — one bad fetch persistently hid an image on every shard that cached it.Change
Gate the success override on
2xx. For4xx/5xxapply a short microcache header instead (PGTHUMBOR_CACHE_CONTROL_ERROR, defaultpublic, max-age=10).3xxis left untouched (Thumbor default).max-age=31536000, immutable)public, max-age=10(configurable)Why microcache instead of
no-storeThe issue proposed
no-storefor errors. Using a short-TTL microcache (default 10 s) instead is strictly better under load:no-store, achieved with a 10-s TTL instead of 0.no-storeby settingPGTHUMBOR_CACHE_CONTROL_ERROR="no-store"if they explicitly don't want the absorption behaviour.Test plan
_cache_control_overridestill gets microcache.PGTHUMBOR_CACHE_CONTROL_ERRORenv var override is honoured.Ageheader on repeated GETs tops out at ~10 s instead of the year-long pinning observed today.Docs
README.mdenv-var table updated withPGTHUMBOR_CACHE_CONTROL_ERROR.thumbor.conftemplate updated with default and rationale comment.🤖 Generated with Claude Code