-
-
Notifications
You must be signed in to change notification settings - Fork 564
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
Protection against malicious queries #26
Comments
Yeah, Sangria provides some insights. I think we can implement similar concept, but I suspect that they do several executor passes on the query. That may affect performance, because PHP is not a perfect tool for such tasks. Ideally we'd want this with some sort of PHP module for parser / executor. Or at least have some profiling tool to make sure that new features do not affect performance significantly. |
As a workaround for now (just an idea) - you can set up complexity tracking by wrapping all field "resolve" methods with some closure and using ResolveInfo to collect complexity data. Then throw if it reaches threshold. But since you won't be able to get children complexity in parent resolve, you will have to set complexity multiplier in parent and apply it to all children scores when descending deeper during execution. |
I'd say, absolutely yes, to adding some sort of protection. It is a necessity. However, I'd also be worried about bogging down the system with the checks. It's a difficult split to make. Scott |
The idea with wrapping all resolve methods could work, but seems a little bit hacky and repetitive. I think the best place for that would be the executor. I think most projects that expose the server to the public need such an implementation anyways. |
@ivome I think it makes sense to perform several passes on query - one for analysis (optional), another one for execution. I am also monitoring graphql-js activity on optimizations subject (graphql/graphql-js#304). Will likely move forward when there is some clear vision on this subject in graphql-js, as this project tries to match reference implementation when possible. |
@ivome Another idea is that you could probably write custom validation Rule that will test query fields against schema to check for complexity. It might be the way to go with this feature. See Obviously you will have to avoid using |
@vladar I confirm that using |
@mcg-web That would be awesome! I would definately use such rules in my projects. |
Nice, I will soon contribute it. |
Closing this as now we have validator rules for query depth and complexity, thanks to @mcg-web! |
With GraphQL it is quite easy to create a query that crashes the server. Especially with graphs that have some kind of recursive structure.
How do you guys protect against that?
I like how they did it in the Scala project:
http://sangria-graphql.org/learn/#protection-against-malicious-queries
The text was updated successfully, but these errors were encountered: