Port MaxIntrospectionDepthRule from graphql-js#904
Merged
SimonSapin merged 2 commits intomainfrom Sep 3, 2024
Merged
Conversation
* 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.
6200e54 to
c3c32cb
Compare
lrlna
approved these changes
Sep 3, 2024
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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, sodocument.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.