Validation-Level Authorization Bypass via a Cache Shared Across Schemas
Description
Hot Chocolate evaluates authorization policies applied with ApplyPolicy.Validation (apply: VALIDATION on @authorize) once per request, before execution. A validation rule collects the validation-level @authorize directives on the fields and types that an operation selects, and caches that set by the ID of the operation document. The document ID is the hash of the document text or the ID of a persisted operation, so it does not depend on the schema.
In affected versions, this cache exists once per application. Every schema in the application shares it, and it survives a rebuild of a schema. A schema can therefore authorize an operation against the directives that another schema, or an earlier version of the same schema, collected for the same document, and skip its own validation-level policies.
An application is affected when it calls AddAuthorization(), protects fields or types with ApplyPolicy.Validation, and either of the following holds:
- Two or more schemas registered with
AddGraphQLServer(...)on the same service collection use validation-level authorization. An operation document sent to several of them is checked against the policies collected by the schema that received it first. - A schema with validation-level authorization is rebuilt while the application runs, for example when a type module raises
TypesChangedor the request executor is evicted. Documents sent before the rebuild keep the policies of the previous schema version until the cache, which holds 256 documents, evicts them.
In 13.0.x, ApplyPolicy.Validation is the default for the [Authorize] attribute, the @authorize directive, and the code-first Authorize(...) methods. The code-first methods keep that default until 13.3.0. Those releases are affected without an explicit apply.
Fixed Versions
- 16.7.4
- 15.1.21
- 14.3.5
- 13.9.20
Impact
A caller can run an operation that selects fields or types protected by a validation-level policy they do not meet, as long as they meet the policies cached for that document. That is the case when the other schema, or the previous schema version, protects the same selections with weaker policies or none. Any request fills the cache, including one the attacker sends to the other schema beforehand, and a request that fails authorization there still stores its entry. When the bypassed policy only requires an authenticated user, an anonymous caller is enough.
Mutations whose fields are protected only by validation-level policies execute for that caller.
The same mix-up also refuses callers who meet the receiving schema's requirements when the cached policies are stricter.
Policies applied with ApplyPolicy.BeforeResolver or ApplyPolicy.AfterResolver are evaluated during execution and are still enforced.
This issue is classified as CWE-863: Incorrect Authorization.
Recommendation
Upgrade to one of the fixed releases. Each request executor then keeps its own cache, so schemas do not share entries and a rebuilt schema starts with an empty cache.
If an immediate upgrade is not possible, apply policies with ApplyPolicy.BeforeResolver in every schema but one, and restart the application after a runtime schema change that adds or tightens a validation-level policy. Alternatively, host each schema that uses validation-level authorization in its own application.
[Authorize("ReadOrders", ApplyPolicy.BeforeResolver)]
public IQueryable<Order> GetOrders(OrderContext context) => context.Orders;type Query {
orders: [Order!]! @authorize(policy: "ReadOrders", apply: BEFORE_RESOLVER)
}A BeforeResolver policy is checked when its field resolves, so a denied field returns an authorization error in the result instead of the whole request being refused before execution.
Affected versions
- HotChocolate.AuthorizationFrom 16.0.0 · fixed in 16.7.4
- HotChocolate.AuthorizationFrom 15.0.0 · fixed in 15.1.21
- HotChocolate.AuthorizationFrom 14.0.0 · fixed in 14.3.5
- HotChocolate.AuthorizationFrom 13.0.0 · fixed in 13.9.20
- HotChocolate.AspNetCoreFrom 16.0.0 · fixed in 16.7.4
- HotChocolate.AspNetCoreFrom 15.0.0 · fixed in 15.1.21
- HotChocolate.AspNetCoreFrom 14.0.0 · fixed in 14.3.5
- HotChocolate.AspNetCoreFrom 13.0.0 · fixed in 13.9.20