-
-
Notifications
You must be signed in to change notification settings - Fork 553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add utilities for preventing malicious queries #960
Comments
Because graphql-core is a direct port of graphql-js I think https://github.com/stems/graphql-depth-limit can be directly ported to Python. |
@MeRuslan points out a another useful library to implement cost analysis: https://github.com/pa-bru/graphql-cost-analysis (ref: #902 (comment)). We could probably port that library to python as well. Note that graphql-js has decided not to support adding directives through code definitions: graphql/graphql-js#1343 |
Another simple thing would be to add an extension that prevents introspection queries. That way you can add/enable it on production only to prevent people from introspecting your schema. |
Maybe this is also a thing to note: Obviousy only useful for closed API's - it makes a gql scheme more "static" with the precalculated hashes As far i know you can limit the server to only respond to known hashes |
Persisted queries is the ultimate way to protect against malicious queries because it means you can’t execute a query that isn’t trusted. It’s very powerful but requires some effort with tooling to make it work well. We should provide an extension that lets you implement persisted queries like envelop has: https://www.envelop.dev/plugins/use-persisted-operations |
For reference from strawberry discord on cost calculation (will refine later) Roadmap could be the following M1: basic cost calc
M2 advanced cost calc
M3 full integration
Example from stellate for reference: query {
# Total: 18
todos(limit: 2) {
# (Nested: 2 + 1 + 1 + 1 + (author: 2 + 1 + 1)) * limit: 2 = 18
id # Scalar: 1
text # Scalar: 1
completed # Scalar: 1
author {
## Nested: 4 (2 + 1 + 1)
id ## Scalar: 1
name ## Scalar: 1
}
}
} |
Some ideas here: https://www.apollographql.com/blog/graphql/security/securing-your-graphql-api-from-malicious-queries/
We can definitely implement some of those :)
Upvote & Fund
The text was updated successfully, but these errors were encountered: