-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
GraphQL QueryComplexityLimiter queryComplexity is set too low value and queryDepth probably too high #32427
Comments
Hi @paales. Thank you for your report.
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
For more details, please, review the Magento Contributor Assistant documentation. Please, add a comment to assign the issue:
🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions! |
This isn't stale |
Hi @engcom-Lima. Thank you for working on this issue.
|
Hi @paales , default query complexity and depth thresholds are configurable via the magento2/app/code/Magento/GraphQl/etc/di.xml file. So you are free to adjust these values as deemed fit for your environment. This is the current approach we advocate to users and will have improved in the upcoming 2.4.3 release. Thanks |
@engcom-Lima Thanks for the suggestion to modify those values! Changing the defaults would still make sense, right? Or is that what you mentioned for 2.4.3? |
This needs to be put in the core, we can have the configuration as it is. Doing an integration or consuming the GraphQL right now, makes the usage of the API totally worthless. |
@engcom-Lima Can you elaborate on the improvements for 2.4.3? I'm currently on this version, and still find myself running into the queryComplexity limit that seems to be set to 300. For our application to remain compatible with standard Magento (that is, without requiring one to change the default limits through DI customisation) this would require splitting up such queries, which only introduces more overhead and takes away one of the benefits of GraphQL |
300 is still set as the default query complexity limit. This really ought to be assessed. 2.4-develop magento2/app/code/Magento/GraphQl/etc/di.xml Line 104 in 647b34e
2.5-develop magento2/app/code/Magento/GraphQl/etc/di.xml Line 103 in 6ac4cda
It's not difficult to change in a project, but also not difficult to set a more reasonable default that reduces the chance of devs chasing their tails because of this. |
Preconditions (*)
Steps to reproduce (*)
I'm trying to fetch all product information for the product page in one go:
When I run this query I get an error:
Max query complexity should be 300 but got 388.
Expected result (*)
I'm not doing anything super special and I would expect this to succeed. Especially since the workaround is that I need to make two calls to the Magento backend which will invariably cause more load for the server.
Actual result (*)
The current complexity limit is set to 300:
magento2/app/code/Magento/GraphQl/etc/di.xml
Lines 102 to 103 in 3ad7a1d
There currently is a test set to validate that it isn't more than 300:
magento2/dev/tests/api-functional/testsuite/Magento/GraphQl/Framework/QueryComplexityLimiterTest.php
Line 398 in 3ad7a1d
It seems that the
queryDepth
here is set relatively high, but thequeryComplexity
is set relatively low.Proposed solution
Apollo
If we read this security post from Apollo https://www.apollographql.com/blog/securing-your-graphql-api-from-malicious-queries-16130a324a6b/, it seems more sensible values would be:
graphql-query-complexity library
If we follow the defaults mentioned here: https://github.com/slicknode/graphql-query-complexity/blob/95e2899dd9bc32600114dd04bef5996ceeba0f4a/README.md#usage, we get:
Hasura
Hasura doesn't even offer queryComplexity limits they only offer queryDepth limits:
https://hasura.io/docs/latest/graphql/cloud/api-limits.html#configuring-an-api-limit
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
The text was updated successfully, but these errors were encountered: