Skip to main content
Menu
Advisories

Authorization Bypass via Subscription Topics Resolved from Arguments

GHSA-MVC4-CR9X-273FPublished Updated GitHub

Description

Hot Chocolate subscription fields subscribe to topics of the configured subscription provider. A field can resolve its topic from its arguments, with a [Topic] template such as [Topic("{orderId}")] or with SubscribeToTopicByArgument. A field without [Topic] subscribes to a topic named after its method. All topics of an application share one namespace, keyed by the topic name alone.

When a template consists only of argument placeholders, the client's argument value becomes the entire topic name. In affected versions, a client can therefore name the topic of another subscription field and receive that field's events through the field with the placeholder. The other field is not selected, so its authorization is not evaluated. The subscriptions documentation showed this template form.

An application is affected when a subscription field's topic template consists only of placeholders, or the field uses SubscribeToTopicByArgument, and another topic of the application carries the same message type. With a string or ID argument, the client can name the method-named topics of other fields, whose names follow from the field names in the schema. [ID] arguments are no obstacle, because a client can serialize any topic name as a node ID. Every subscription transport is affected.

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

A client that may use a subscription field with a placeholder-only topic can receive the events published to another topic of the same message type, including a topic that only a field protected with [Authorize] serves. By default a field's topic is its method name, so the field onAnyOrderChanged in the schema gives away the topic OnAnyOrderChanged.

With the Redis, NATS, Postgres, or RabbitMQ provider, the client can also receive the events of a topic with a different message type, deserialized into its own field's type wherever property names match. This requires that no other client on the same server instance subscribed to that topic first.

A client can also occupy a topic of a different message type that nobody else on the server instance subscribes to at that moment. Until the client disconnects, new subscribers to that topic fail, and with the in-memory provider every publish to it throws, so a mutation that publishes to the topic returns an error after its own changes are saved.

This issue is classified as CWE-639: Authorization Bypass Through User-Controlled Key.

Recommendation

Upgrade to one of the fixed releases. A subscription whose topic, resolved from its arguments, equals the fixed topic of another subscription field is then refused with a GraphQL error. A fixed topic is a method name, a [Topic] name without placeholders, or a name passed to SubscribeToTopic(string).

Upgrading alone does not fully protect a topic template that consists only of placeholders. Also give every topic template a literal prefix that no other topic starts with, and publish to the prefixed name:

[Subscribe]
[Topic("OrderStatusChanged_{orderId}")]
public Order OnOrderStatusChanged([ID] string orderId, [EventMessage] Order order)
    => order;
await sender.SendAsync($"OrderStatusChanged_{orderId}", order, cancellationToken);

Replace SubscribeToTopicByArgument with SubscribeToTopic and a delegate that adds the same kind of prefix:

descriptor
    .Field("onOrderStatusChanged")
    .SubscribeToTopic<Order>(ctx => $"OrderStatusChanged_{ctx.ArgumentValue<string>("orderId")}");

The argument value can then only produce topics that start with the prefix. If an immediate upgrade is not possible, this change alone closes the issue.

Affected versions

References

GitHub · ChilliCream/graphql-platform