Skip to main content
Menu
Advisories

Type-Level Cache-Control Settings Are Ignored for Non-Null, List, Interface, and Union Fields, Making Per-User Responses Shareable

GHSA-RMJG-VRRQ-FXCPPublished Updated GitHub

Description

With cache control enabled (AddCacheControl() and UseQueryCache()), Hot Chocolate writes Cache-Control and Vary from the @cacheControl settings of the fields a query selects and of the types those fields return. A type can declare scope: PRIVATE, vary, or a lifetime once, for every field that returns it.

In affected versions, a type's settings are read only for a nullable field that returns the type itself. They are ignored for a field that returns the type through a non-null or list wrapper, such as Account! or [Account!]!, and the settings of an object type are ignored for a field that returns an interface or union the object type belongs to. With nullable reference types enabled, a C# property or method that returns a reference type maps to a non-null field unless its return type is annotated with ?, and a list field ignores the type's settings whether or not it is nullable. A response that selects such a field carries neither private nor the type's Vary names, and takes its lifetime from the field. A shared cache in front of the server, such as a CDN or a reverse proxy, may store a response that holds one user's data and serve it to other users.

A Fusion gateway computes its headers the same way, so its responses are affected for the same fields.

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, a shared cache stores its responses, and a type that holds per-user data declares scope: PRIVATE or vary on the type rather than on every field that returns it. A query that selects a cacheable field returning that type through a non-null, list, interface, or union field is then answered with a shareable lifetime. A user who requests the same URL within that lifetime can receive the previous user's response. A field such as me, and the 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. _entities returns a list of a union, so caches that store subgraph responses by their Cache-Control, such as entity caches in federation routers, can also serve one user's entities to other users.

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

Recommendation

Upgrade to a fixed version. A type's @cacheControl then applies to fields that return it through non-null and list wrappers, and for a field that returns an interface or union, the settings of every object type that implements it or belongs to it apply as well, whether or not the query selects fields of that object type. A lifetime declared on the field still takes precedence. A response that selects such a field can become private, gain Vary names, get a shorter lifetime, or gain a Cache-Control header it did not have.

If an immediate upgrade is not possible, repeat scope: PRIVATE and vary on every field that returns the type, the non-null, list, interface, and union fields included. Alternatively, call SkipQueryCaching() from an HTTP request interceptor for authenticated requests, so that their responses carry no Cache-Control header.

Affected versions

References

GitHub · ChilliCream/graphql-platform