Node ID and Cursor Errors Repeat the Rejected Value for Every Field, Allowing Response Amplification
Description
When Hot Chocolate cannot parse a node ID, the field's error reports the ID in its originalValue extension, and on 14.x and later, when it cannot parse an index cursor in after or before, the HC0078 error reports the cursor in its cursor extension. In affected versions, these errors report the whole value, however long it is, and every field that receives the value reports its own error. A request that passes one long ID in a variable to many aliased node fields or [ID] arguments, or, on 14.x and later, one long cursor to many aliased connection fields, gets one copy of the value back per field, so the response grows with the value's length times the number of fields, within the default request size, field, and cost limits.
The same applies to:
- The ID filter of
HotChocolate.Data, which puts the ID into its error message when the node ID serializer fails, and forinandninevery ID of the list. This happens with the legacy node ID serializer, which is the default on 13.x, where it is namedIdSerializer, and is selected withAddLegacyNodeIdSerializer()on later versions. - The
[ID]argument messages on 13.x, which also contain the ID, and for a list every ID of the list. - The type name read from a node ID, in the errors for an unknown type and for a type name that does not match the expected one, where the node ID serializer does not limit the ID's length.
- The
nodefield of the Fusion gateway, on 16.x, which reports an ID it cannot read in the same way.
The legacy node ID serializer also has no length limit, so every field that receives a long ID decodes the whole ID before it fails.
Servers and gateways that accept only persisted operations are not affected.
The fixed versions report at most 128 characters of a node ID, or of the type name read from it, and, on 14.x and later, at most 32 characters of a cursor, each followed by .... The ID filter reports a node ID it cannot parse in the same way as an [ID] argument does. On 14.x and later, index cursors longer than 16 characters, the longest that Hot Chocolate issues, are refused before they are decoded. The legacy node ID serializer refuses IDs longer than 1,024 characters, the same default as the other node ID serializers. On 13.x, IdSerializer has the same 1,024-character default.
Fixed Versions
- 16.7.8
- 15.1.22
- 14.3.6
- 13.9.21
Applications on earlier 16.x releases should upgrade to 16.7.8.
Impact
An unauthenticated client can make a server or gateway build a response hundreds of times the size of the request. In our tests on 16.7.7, with no option changed:
- A 5 MB request that passed a 5,000,000-character ID to 100
nodefields returned 500 MB and held 1.65 GB of managed memory while the response was written. A Fusion gateway returned the same 500 MB. - A 305 KB request that passed a 250,000-character ID to 2,000
[ID]arguments returned 500 MB. - A 553 KB request that passed a 500,000-character cursor to 1,000 connection fields returned 500 MB.
The memory a request holds is about three times its response, and a request near the default size limit holds several gigabytes. With the legacy node ID serializer, 1,000 node fields over one 5 MB ID also took 3.5 seconds of CPU on 13.9.20 in its default configuration. Repeated requests can exhaust the server's memory and CPU and degrade or stop the service.
No data is disclosed or changed.
This issue is classified as CWE-405: Asymmetric Resource Consumption (Amplification).
Recommendation
Upgrade to a fixed version.
If an application uses the legacy node ID serializer with IDs longer than 1,024 characters, raise its limit:
builder.Services
.AddGraphQLServer()
.AddLegacyNodeIdSerializer(maxIdLength: 2_048)
.AddGlobalObjectIdentification();On 14.x, AddLegacyNodeIdSerializer already takes maxIdLength, but versions before 14.3.6 ignore it. From 14.3.6 on, the limit applies and must be at least 128, so check any value an application already passes.
On 13.x, the node ID serializer is IdSerializer, which refuses IDs longer than 1,024 characters from 13.9.21 on. Raise its limit with AddIdSerializer(maxIdLength: …), or with new IdSerializer(maxIdLength: …) where an application creates the serializer itself. The limit must be at least 128. A 13.x Fusion gateway decodes the node IDs its subgraphs return with its own serializer, so a gateway in front of subgraphs with longer IDs needs the same setting.
builder.Services
.AddGraphQLServer()
.AddIdSerializer(maxIdLength: 2_048)
.AddGlobalObjectIdentification();If an immediate upgrade is not possible:
- Accept only persisted operations, which limits the documents a client can send to the application's own.
- Lower the server's maximum request size, which narrows the response, since it grows with the length of the value.
Affected versions
- HotChocolate.AspNetCoreFrom 16.0.0 · fixed in 16.7.8
- HotChocolate.Execution.AbstractionsFrom 16.0.0 · fixed in 16.7.8
- HotChocolate.TypesFrom 16.0.0 · fixed in 16.7.8
- HotChocolate.Types.CursorPaginationFrom 16.0.0 · fixed in 16.7.8
- HotChocolate.DataFrom 16.0.0 · fixed in 16.7.8
- HotChocolate.Fusion.AspNetCoreFrom 16.0.0 · fixed in 16.7.8
- HotChocolate.Fusion.ExecutionFrom 16.0.0 · fixed in 16.7.8
- HotChocolate.AspNetCoreFrom 15.0.0 · fixed in 15.1.22
- HotChocolate.TypesFrom 15.0.0 · fixed in 15.1.22
- HotChocolate.Types.CursorPaginationFrom 15.0.0 · fixed in 15.1.22
- HotChocolate.DataFrom 15.0.0 · fixed in 15.1.22
- HotChocolate.AspNetCoreFrom 14.0.0 · fixed in 14.3.6
- HotChocolate.TypesFrom 14.0.0 · fixed in 14.3.6
- HotChocolate.Types.CursorPaginationFrom 14.0.0 · fixed in 14.3.6
- HotChocolate.DataFrom 14.0.0 · fixed in 14.3.6
- HotChocolate.AspNetCoreFrom 13.0.0 · fixed in 13.9.21
- HotChocolate.TypesFrom 13.0.0 · fixed in 13.9.21
- HotChocolate.DataFrom 13.0.0 · fixed in 13.9.21