Skip to content

Port MaxIntrospectionDepthRule from graphql-js#904

Merged
SimonSapin merged 2 commits intomainfrom
ROUTER-685
Sep 3, 2024
Merged

Port MaxIntrospectionDepthRule from graphql-js#904
SimonSapin merged 2 commits intomainfrom
ROUTER-685

Conversation

@SimonSapin
Copy link
Copy Markdown
Contributor

Without this rule, a malicious client could cause huge introspection responses that grow exponentially with the list nesting level in the query.

Instead of a validation rule, this check is performed as part of SchemaIntrospectionSplit::split. graphql-js allows users to disable or enable specific validation rules, with max introspection depth being part of "recommended" rules. apollo-compiler does not have this mechanism, so document.validate() always performs validation as per the GraphQL spec.

The depth limit is hard-coded to 3, and applied to specific intropsection fields that matches graphql-js. graphql-js code has a comment about counting all list fields. When I tried that, a "normal" introspection query was rejected because __schema.types[list].field[list].args[list] reaches depth 3.

* https://github.com/graphql/graphql-js/blob/v17.0.0-alpha.7/src/validation/rules/MaxIntrospectionDepthRule.ts
* https://github.com/graphql/graphql-js/blob/v17.0.0-alpha.7/src/validation/__tests__/MaxIntrospectionDepthRule-test.ts

Without this rule, a malicious client could cause huge introspection responses
that grow exponentially with the list nesting level in the query.

Instead of a validation rule, this check is performed as part of
`SchemaIntrospectionSplit::split`.
graphql-js allows users to disable or enable specific validation rules,
with max introspection depth being part of "recommended" rules.
apollo-compiler does not have this mechanism, so `document.validate()`
always performs validation as per the GraphQL spec.

The depth limit is hard-coded to 3, and applied to specific intropsection fields
that matches graphql-js.
graphql-js code has a comment about counting all list fields.
When I tried that, a "normal" introspection query was rejected
because `__schema.types[list].field[list].args[list]` reaches depth 3.
@SimonSapin SimonSapin merged commit b9f39e8 into main Sep 3, 2024
@SimonSapin SimonSapin deleted the ROUTER-685 branch September 3, 2024 08:33
SimonSapin added a commit to apollographql/router that referenced this pull request Sep 9, 2024
This protection against introspection queries generating huge responses
was added recently in graphql-js graphql/graphql-js#4118
and ported to rust apollographql/apollo-rs#904,
but is not yet present in the graphql-js version used by router-bridge.

This disables it for now from Rust introspection, in order to match
the current state of JS introspection.

Adding this rule (in both implementations) can be revisited separately.
In particular: the depth limit is hard-coded to 3. Is that the right number?
Should it be configurable? Is the rule checking the right set of fields?
SimonSapin added a commit to apollographql/router that referenced this pull request Sep 10, 2024
This protection against introspection queries generating huge responses
was added recently in graphql-js graphql/graphql-js#4118
and ported to rust apollographql/apollo-rs#904,
but is not yet present in the graphql-js version used by router-bridge.

This disables it for now from Rust introspection, in order to match
the current state of JS introspection.

Adding this rule (in both implementations) can be revisited separately.
In particular: the depth limit is hard-coded to 3. Is that the right number?
Should it be configurable? Is the rule checking the right set of fields?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants