UPGRD
← Home

Cybersecurity

The Cache Key Is a Security Boundary

A cache key determines which HTTP requests are considered equivalent. Incorrect assumptions about that equivalence can become both performance and security vulnerabilities.

Home · · 5 min read · Updated November 26, 2026
  • HTTP
  • CDN
  • Varnish
  • Cloudflare
  • Caching
  • Web Security
Two HTTP requests pass through a cache key that decides whether they share a response.

Quick summary

A cache key determines which HTTP requests are considered equivalent. Incorrect assumptions about that equivalence can become both performance and security vulnerabilities.

A cache key answers a deceptively consequential question: which request may reuse this stored response? Every cache hit is an assertion that the response generated for one request is safe and correct for another. If that assertion is too narrow, a cache can serve the wrong content to a user. If it is too broad, equivalent content is fragmented into many entries and the cache loses its value.

The key is therefore both a performance control and a security boundary. Application teams sometimes treat it as a tuning knob controlled by a CDN rule. It is better treated as part of the application’s response semantics: decide which request properties can change the representation, then ensure the cache key or cache policy accounts for them.

What HTTP says—and what implementations add

RFC 9111 defines a cache key as including, at minimum, the request method and target URI. Many practical caches only store GET responses and use the URI as the key. If a response varies according to request headers, the origin can use Vary so a cache distinguishes representations based on the named request fields. HTTP permits caches to add key material beyond that minimum; user-agent caches, for example, may partition entries for privacy.

This standard-level model is not a universal CDN recipe. A product’s default key, what it caches by default, and custom-key features are implementation-specific. Cloudflare documents a default key that includes the full URL, including query string, along with selected headers such as Origin and method-override headers. Its custom-key settings can alter query, header, cookie, host, or user-feature components. Varnish has its own built-in behavior and can be changed through VCL. Do not infer a vendor’s effective key solely from the HTTP standard or from a rule name in a dashboard.

Equivalence is where the risk lives

Imagine a public product page at /item?id=42. A marketing parameter such as utm_source may not affect its representation, so including it in the key can create separate cache entries for each campaign value. That increases cardinality and reduces hits. But a query parameter that selects currency, locale, or product variant is different: if ?currency=EUR changes the price shown, stripping that parameter from the key could make requests for euros and dollars share a response incorrectly.

The same analysis applies to host, cookies, authorization, language, and headers. A response can depend on the host or forwarded host, a session cookie, a bearer credential, Accept-Language, or a custom header. Some responses are intentionally private and must never be reused by a shared cache across users. RFC 9111 places restrictions on shared caching of responses to requests with Authorization, but directives and cache configuration matter; a cookie’s mere presence does not automatically make every cache safe. A Set-Cookie response header is not, by itself, a general instruction to every cache to avoid storing the response.

Cache poisoning occurs when an attacker can influence a request property that changes the origin’s response but is omitted, normalized differently, or interpreted inconsistently in the cache key. The cache stores a response under a key that another request can reach, so an unintended response may be served to other visitors. In the other direction, overly inclusive keying can be an availability and cost problem: random tracking values produce many distinct objects, weaken hit rates, and increase origin traffic. Security and performance both depend on matching the key to actual response variance. Persistent object caches have a related but different request-path trade-off; see when Redis can slow WordPress requests.

Test the deployed path, not just the rule

Start by listing every input that can change the response: path, query parameters, host, cookies, authorization, language, content negotiation headers, and application-specific headers. For each input, determine whether two values produce distinct representations, whether the response is public, and whether the origin emits appropriate Cache-Control and Vary fields. Do not blindly vary on all cookies or all headers; that can destroy sharing. Equally, do not remove a dimension simply because it hurts the hit ratio.

In staging, test pairs of requests that should be equivalent and pairs that must remain distinct. Repeat with a clean cache and then with requests in the reverse order; order matters when checking for cross-user leakage. Compare response bodies and sensitive headers, not only status codes. Inspect Cache-Control, Age, Vary, and provider-specific cache status and key diagnostics. Confirm that a personalized request cannot warm a shared object later served to an anonymous visitor, and that an anonymous response cannot leak into an authenticated view.

For a CDN, verify the active rules and provider’s effective key rather than assuming the origin’s Vary header is the only input. With Cloudflare, its cache-key documentation describes which fields are in the default key and how cache rules can include or exclude query parameters and other fields. With Varnish, review the actual VCL and built-in behavior for the deployed version. Proxies, CDNs, and application caches can each have different key rules; a safe edge key does not prove a safe downstream cache configuration.

Make the policy explainable

Document why the selected dimensions distinguish content and why ignored values do not. Keep personalized or credential-dependent responses out of shared caching unless there is a carefully designed, verified isolation scheme. Normalize URLs consistently between cache and origin, because differing normalization rules can create mismatched interpretations. When a response’s dependency changes, update its cache policy and invalidation strategy together.

Cache efficiency is not simply the largest hit ratio. A cache that reuses the wrong representation is a defect, not an optimization. Define request equivalence from the origin’s behavior, encode it in a concrete key and cacheability policy, then test the same boundaries attackers would probe.

References

RFC 9111: HTTP Caching; Cloudflare cache keys; Varnish HTTP caching documentation.