Skip to main content
Menu
Advisories

Query Fields Without Cache-Control Settings Let One Cacheable Field Make Per-User Responses Shareable

GHSA-MRH7-C823-RG58Published Updated GitHub

Description

With cache control enabled (AddCacheControl() and UseQueryCache()), Hot Chocolate writes a Cache-Control header from the @cacheControl settings of the fields a query selects, taking the lowest lifetime. With ApplyDefaults, which is on by default, a query field without cache settings is documented to count as max-age=0.

In affected versions, some query fields without cache settings put no limit on the response:

  • A Fusion gateway never applies the defaults. A root field that a subgraph serves without cache settings, and a field that one subgraph adds to an entity of another through a lookup, add nothing to the header.
  • A Hot Chocolate server applies the defaults before it adds node and nodes (AddGlobalObjectIdentification()) and _service and _entities (AddApolloFederation()), so these fields add nothing either.

A single cacheable field elsewhere in the query, or a cacheable type it returns, then sets the lifetime of the whole response, without private. A shared cache in front of the server or gateway, such as a CDN or a reverse proxy, may store a response that holds one user's data and serve it to other users.

Fixed Versions

  • HotChocolate.Caching: 16.7.4, 15.1.21, 14.3.5, and 13.9.20
  • HotChocolate.Fusion.Caching: 16.7.4

Applications on 16.6 or earlier 16.x releases should upgrade to 16.7.4.

Impact

An application is affected only when cache control is enabled and a shared cache stores its responses. A query that selects a cacheable field together with one of the fields above, such as a per-user root field from a subgraph without cache control, an entity field that another subgraph adds, or data reached through node, nodes, or _entities, is then answered with a shareable lifetime. A user who requests the same URL within that lifetime can receive the previous user's response. GET routes for persisted operations give every user of an operation the same URL.

Under RFC 9111, a shared cache does not reuse a response to a request with an Authorization header unless the response carries public, must-revalidate, or s-maxage. Applications that authenticate with cookies or custom headers are exposed, and so are applications that use bearer tokens when a selected field sets sharedMaxAge. Caches that store subgraph responses by their Cache-Control, such as entity caches in federation routers, can also serve an _entities response to other users.

This issue is classified as CWE-524: Use of Cache Containing Sensitive Information.

Recommendation

Upgrade to a fixed version. A field without cache settings then counts as DefaultMaxAge, which is 0 unless configured: on the gateway, every root field and every field it selects directly on an entity it fetches through a lookup, and on the server, node, nodes, _service, and _entities as well. A response that relied on one of these fields being cacheable needs an explicit @cacheControl on that field. A gateway whose subgraphs set ApplyDefaults = false needs ApplyDefaults = false on the gateway too, to keep headers only for fields that opt in.

If an immediate upgrade is not possible, call SkipQueryCaching() from an HTTP request interceptor for authenticated requests, so that their responses carry no Cache-Control header. On a gateway, also use AddCacheControl() in every subgraph that serves per-user query fields, and give a per-user field that one subgraph adds to an entity of another an explicit @cacheControl(maxAge: 0) in every subgraph that defines it.

Affected versions

References

GitHub · ChilliCream/graphql-platform