Skip to main content
Menu
Advisories

Cross-Site Request Forgery via Persisted Operation Routes

GHSA-X3HJ-GXJV-GPMFPublished Updated GitHub

Description

The persisted operation routes mapped by MapGraphQLPersistedOperations() execute a POST request whatever its Content-Type. A web page on another origin can send such a POST with Content-Type: text/plain, or with no Content-Type at all. That is a CORS simple request, which a browser sends without a preflight and with the user's cookies, so the page can run a persisted operation, including a mutation, as the signed-in user. The GraphQL endpoint mapped by MapGraphQL() refuses the same request.

An application is affected when all of the following hold:

  • It maps the persisted operation routes with MapGraphQLPersistedOperations(), on a Hot Chocolate server or a Fusion gateway. In 14.x, the routes exist only in applications that target .NET 8 or later.
  • It authenticates requests with credentials that the browser attaches automatically, such as cookies. That includes cookies with any SameSite value when the attacking page is on the same site, for example on another subdomain.
  • A persisted operation changes state, such as a mutation.

Fixed Versions

The vulnerability is fixed in the following releases:

  • 16.6.9
  • 15.1.19
  • 14.3.3

Impact

A page that a signed-in user visits can execute persisted operations with that user's identity. It cannot read the responses, so the impact is the effect of the operations it runs, such as any persisted mutation. The attacker needs the ID of a persisted operation, which a web client usually carries in its code.

This issue is classified as CWE-352: Cross-Site Request Forgery (CSRF).

Recommendation

Upgrade to one of the fixed releases. A POST to a persisted operation route must then carry Content-Type: application/json, and a request without it is refused, as it is on the GraphQL endpoint.

If an immediate upgrade is not possible, refuse POST requests to the persisted operation routes that do not carry a JSON Content-Type, before they reach Hot Chocolate:

app.Use(async (context, next) =>
{
    if (HttpMethods.IsPost(context.Request.Method)
        && context.Request.Path.StartsWithSegments("/graphql/persisted")
        && !context.Request.HasJsonContentType())
    {
        context.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType;
        return;
    }

    await next(context);
});

Use the path passed to MapGraphQLPersistedOperations() if it is not the default /graphql/persisted. If the application calls app.UseEndpoints(), register the middleware before it.

Affected versions

References

GitHub · ChilliCream/graphql-platform