Skip to main content
Menu
Advisories

Type-Level Authorization Bypass via Union Types

GHSA-XJ23-P564-9H29Published Updated GitHub

Description

A type-level @authorize directive, or an [Authorize] attribute on a class, makes Hot Chocolate authorize every field that returns the protected object type. Fields that return certain unions that contain the protected type got no authorization. Their resolvers ran for any caller and returned every field of the protected type.

This applies to the following unions:

  • Unions declared in a schema document, such as union SearchResult = Invoice | Customer, including members added with extend union. This also applies when the member types are defined in C#.
  • Unions built with IUnionTypeDescriptor.Type(NamedTypeNode).
  • The result unions that AddQueryConventions() creates for resolvers with [Error] attributes or a FieldResult<...> return type (14.0.0 and later).

Unions declared with descriptor.Type<TObjectType>(), descriptor.Type(objectType) or a [UnionType] marker interface are not affected. Interfaces are not affected.

An application is affected when all of the following hold:

  • An object type is protected by a type-level @authorize directive or [Authorize] attribute that uses apply: BEFORE_RESOLVER (the default) or apply: AFTER_RESOLVER. A directive with apply: VALIDATION is enforced. In 13.0.x the default was VALIDATION, so those versions are affected only when BEFORE_RESOLVER or AFTER_RESOLVER is set explicitly.
  • A field returns that object type through one of the unions listed above, as the union itself or as a list of it.
  • That field has no field-level @authorize or [Authorize] of its own that requires the same authorization.

No option beyond AddAuthorization() is needed. A schema document with such a union is affected in the default configuration.

Fixed Versions

  • 16.7.3
  • 15.1.20
  • 14.3.4
  • 13.9.19

Impact

A caller that does not meet the protected type's requirements can read every field of that type through a field that returns an affected union. With a plain @authorize, an anonymous caller is enough. With roles or a policy, an authenticated caller without them is enough. The attacker needs to know the union-typed field, which introspection or a client usually reveals.

The resolver of the union-typed field also runs for that caller, so a mutation that returns an affected union executes.

Field-level authorization and type-level directives with apply: VALIDATION are still enforced. Fields of the protected type that return other protected types still apply those types' authorization.

This issue is classified as CWE-863: Incorrect Authorization.

Recommendation

Upgrade to one of the fixed releases. A field that returns a union is then authorized with the requirements of every protected member type before its resolver runs, however the union refers to its members. This is how unions declared with descriptor.Type<TObjectType>() already behave. As a result, such a field is refused for a caller that does not meet those requirements even when it would return an unprotected member, for example the error member of a query conventions result union. When several members are protected, the caller must meet the requirements of all of them.

If an immediate upgrade is not possible, add authorization with the same requirements to every field that returns an affected union. In a schema document:

type Query {
  search(term: String!): SearchResult @authorize(policy: "Invoices")
}

On a resolver that uses query conventions:

[Authorize(Policy = "Invoices")]
[Error(typeof(InvoiceNotFoundException))]
public Invoice GetInvoice(int id) => ...;

Alternatively, declare the union in C# with descriptor.Type<TObjectType>() for each member.

Affected versions

References

GitHub · ChilliCream/graphql-platform