Missing Authorization on Batch Resolver Fields
Description
Hot Chocolate 16 does not enforce authorization on fields that are resolved by a batch resolver when the @authorize directive uses ApplyPolicy.BeforeResolver (the default) or ApplyPolicy.AfterResolver. This applies to directives declared with the [Authorize] attribute, the Authorize() descriptor method or in SDL, both on the batch resolver field and on an object type that the field returns. The authorization handler is not called, the field returns its data without an error, and the schema builds without a warning.
Authorization with ApplyPolicy.Validation is enforced on batch resolver fields.
An application is affected when all of the following hold:
- It uses Hot Chocolate authorization, for example
AddAuthorization()fromHotChocolate.AspNetCore.Authorization. No other server option is needed. - Its schema has a batch resolver field. A field has a batch resolver when it is declared with any of the following:
- a method marked
[BatchResolver], in a source-generated[ObjectType<T>]class, anObjectType<T>, or a type extension; ResolveBatchorResolveBatchWithon an object field descriptor;- an interface field with a batch resolver (
[BatchResolver]orResolveBatchWith), which the implementing object types inherit. - That batch resolver field is protected with
ApplyPolicy.BeforeResolverorApplyPolicy.AfterResolverin at least one of these ways: @authorizeon the batch resolver field itself;@authorizeon an object type that the field returns, directly, as a list, or as a member of a union or interface that the field returns;@authorizeon the Query, Mutation or Subscription type, when the batch resolver field is a root field of that type.
Fixed Versions
- 16.7.3
Impact
A client without the required authorization can read the values of protected batch resolver fields, and of protected object types that a batch resolver field returns. If the endpoint accepts anonymous requests, the client needs no credentials. Roles, policies and custom IAuthorizationHandler implementations are all bypassed. If a batch resolver changes state, for example as a root field of a protected Mutation type, the client can also trigger that change. The client needs to know the name of the field, which introspection or a client usually reveals.
This issue is classified as CWE-862: Missing Authorization.
Recommendation
Upgrade to 16.7.3 or later. Authorization on batch resolver fields, and on the object types they return, is then enforced as it is on other fields. A denied parent gets the same AUTH_NOT_AUTHENTICATED or AUTH_NOT_AUTHORIZED error as a regular field. The authorization handler is called once for each parent in the batch. With ApplyPolicy.BeforeResolver, a batch resolver receives only the parents the client is authorized for, and it is not called when no parent is allowed. A batch resolver that relies on receiving every parent must account for this.
If an immediate upgrade is not possible, replace the affected batch resolvers with regular resolvers that load their data through a DataLoader. Authorization is enforced on regular resolvers.