Repeated Apollo Federation SDL Selections Allow Resource Exhaustion and Expose Authorization Directives
Description
AddApolloFederation() adds the _service { sdl } field, which returns the subgraph's schema to composition tools and federation routers.
In affected versions, the field prints the whole schema each time it is resolved, and a request receives a separate copy of the schema for every selection of the field. In 14.x and later, cost analysis, which AddGraphQLServer() enables by default, charges sdl nothing, so a single request can select it through more than 2,000 aliases within the default cost limits. In 13.x, the complexity analyzer is off by default, and where an application enables it, its default limit admits 999 aliases.
In 16.x, the printed schema also contains internal directives, such as @authorize with its policy and role names, and @allowAnonymous, which the schema download and introspection leave out by default. In 15.x and earlier, the schema download contains these directives as well.
An application is affected when clients can send requests to the subgraph directly, rather than only through the router.
Fixed Versions
- 16.7.4
- 15.1.21
- 14.3.5
- 13.9.20
Applications on 16.6 or earlier 16.x releases should upgrade to 16.7.4.
Impact
An unauthenticated client that can reach the subgraph can send a single small request that occupies the server for seconds and allocates memory in proportion to the size of the schema times the number of selections. In our tests, a 21 KB request with 2,000 aliases took 7.8 seconds of CPU time and produced a 160 MB response for a 73 KB schema. For a 564 KB schema, the same request allocated 13.9 GB and ran for 37 to 43 seconds, past the 30-second execution timeout. Repeated or concurrent requests can exhaust the server's CPU and memory and degrade or stop the service.
In 16.x, the field also discloses the subgraph's authorization configuration: which types and fields require authorization, the names of the policies and roles they require, and where anonymous access is allowed. The protected types and fields remain protected.
This issue is classified as CWE-400: Uncontrolled Resource Consumption.
Recommendation
Upgrade to a fixed version. The schema is then printed once, and a request resolves sdl once: a further selection of it in the same request returns an error. In 16.x, sdl also leaves out internal directives, as the schema download does. An application that sets DisableInternalDirectives gets them in both places.
If an immediate upgrade is not possible, make the subgraph reachable only from the router and the composition tooling.