Resize Parameters as a Weapon: Hardening Your Image CDN Before the Bill Arrives
Photo: Ana Las Heras, CC BY-SA 4.0, via Wikimedia Commons
The alert that starts these conversations is almost always financial. Someone in finance notices that the image delivery line item tripled in nine days, and the on-call engineer discovers a handful of URLs with tens of thousands of query-string permutations, none of which appear anywhere on the site.
This is not a sophisticated attack. It's mostly arithmetic. Every modern image CDN will resize, crop, convert, and compress on demand from a URL. That's the product. The same flexibility that lets your design team ask for a 480-pixel-wide WebP at quality 78 lets anyone else ask for 481, 482, 483 — and each distinct request produces a distinct derivative, a distinct cache entry, and a distinct unit of compute.
The mechanics of variant explosion
Consider a fairly typical transform grammar: width, height, fit mode, quality, format, and device pixel ratio. Allow widths from 100 to 2000 in single-pixel steps and you have 1,900 values. Multiply by two fit modes, three formats, five quality tiers, and three DPRs and you're past 170,000 unique variants. Allow arbitrary dimensions in both axes and the space becomes effectively unbounded.
Attackers don't need to be clever about it. A short script cycling parameters against one 8 MB source photo will hammer the origin, fill the edge cache with junk, and generate transform charges for every miss. Do it across a few hundred product images and the arithmetic gets ugly fast. The energy footprint is not trivial either — forced transcoding burns CPU you paid for and nobody needed.
Where the real exposure lives
Unbounded transform parameters. If width accepts any integer, you've shipped a compute faucet.
Cache-key design. This is the crux. If the transform parameters are not part of the cache key, different requests collide and users get the wrong image — a correctness bug that looks like a design bug. If the cache key includes parameters that don't affect the output, you get cache-busting for free: every noise parameter creates a new entry that can never be served to anyone else.
Unkeyed request headers. Classic web cache poisoning territory. A header that influences the response but is absent from the key — an original-URL hint, a forwarded host, a user-agent used for format sniffing — lets a single crafted request plant a response in the cache that gets served to everyone else. In an image pipeline that can mean poisoned content, wrong geography, or derivative variants delivered where originals were expected.
Remote fetch parameters. Any feature that accepts a source URL — overlay from, fetch this external image, watermark with — is an open proxy waiting to reach into your internal network or amplify load.
Unresized original passthrough. If the transform endpoint also happily serves the untouched 6,000-pixel master when asked, you've handed out a bandwidth amplifier and, in some configurations, a way to read private assets.
Hotlinking. Less exotic, still expensive. Someone embeds your derivative endpoint directly in a high-traffic page and you fund the bandwidth.
Allowlists are a strategy, not a nicety
Sanitizing parameters — clamping numbers, stripping unknowns — is necessary but insufficient, because a clamped width from 100 to 2000 still permits 1,900 values. The stronger posture is an explicit allowlist of the variants the product actually uses. Nine widths. Two formats. Three quality tiers. Everything else returns a 400 or redirects to the nearest approved variant.
The objection is always the same: designers need flexibility. In practice, a rasterized set of breakpoints covers what the CSS is going to request anyway, and the flexibility that remains can be exposed through a signed path rather than an open query string.
Signed transforms and scoped tokens
Sign the transform parameters, not just the path. A signature over width, height, format, and quality means a fuzzer can't vary anything without a token your own application issued. Tokens can carry scope — this signature is valid for the product catalog paths and expires in an hour — and they can be issued by the same templating layer that knows which breakpoints the page needs. Signed URLs do interact badly with long-lived surfaces like marketing emails, so reserve the mechanism for high-traffic pages and keep permanent assets on plain, allowlisted public IDs.
Rate limits, bot rules, and the alarming part
Layered defenses do most of the work here:
- Per-IP and per-token limits on transform requests specifically, separate from overall request limits.
- A rule that caps unique variant creation per source object per hour. Sane pipelines create a handful; attackers create hundreds.
- Bot management on the image host, not just the main site — attackers frequently hit the CDN hostname directly.
- Referrer policy on derivatives, or signed short-lived query strings for anything you suspect is being hotlinked.
- Cost alarms tied to transform volume and cache-miss rate, not just total spend. Spend alerts fire too late; a miss-rate spike fires in minutes.
What to actually watch
Four metrics catch nearly everything: the ratio of cache misses to total image requests, the number of distinct variants per source object, the top requesting IPs and tokens by transform volume, and the share of image requests that arrive with a query string absent from your sitemap or page templates. A sudden drop in hit ratio with flat traffic is the signature of variant pumping.
A short hardening checklist
Enumerate every parameter your image endpoint accepts and delete the ones nobody uses. Put width, height, format, and quality on an allowlist. Confirm the cache key contains exactly the inputs that change the output and nothing else. Audit Vary and make sure no header influences a response without being keyed. Disable remote fetch unless a signed source allowlist backs it. Cap variants per object. Point a cost alarm at transform volume.
None of this requires rethinking your architecture. It requires deciding, deliberately, which transformations you're willing to pay for — and refusing the rest.