Skip to content
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

Open
5 tasks
paales opened this issue Mar 10, 2021 · 9 comments
Assignees
Labels
feature request Issue: needs update Additional information is require, waiting for response Progress: dev in progress Project: GraphQL Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it Type: Feature/Improvement

Comments

@paales
Copy link
Contributor

paales commented Mar 10, 2021

Preconditions (*)

  1. Magento 2.4.2

Steps to reproduce (*)

I'm trying to fetch all product information for the product page in one go:

  • All product information and relevant attributes
  • All upsells/related products with specific fields for each product type
  • Etc.

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:

<argument name="queryDepth" xsi:type="number">20</argument>
<argument name="queryComplexity" xsi:type="number">300</argument>

There currently is a test set to validate that it isn't more than 300:

self::expectExceptionMessageMatches('/Max query complexity should be 300 but got 302/');

It seems that the queryDepth here is set relatively high, but the queryComplexity 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:

  • queryComplexity: 750
  • queryDepth: 10

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:

  • queryComplexity: 1000

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.

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
@m2-assistant
Copy link

m2-assistant bot commented Mar 10, 2021

Hi @paales. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

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:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 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

@m2-community-project m2-community-project bot added this to Ready for Confirmation in Issue Confirmation and Triage Board Mar 10, 2021
@paales paales changed the title GraphQL QueryComplexity validation is set to a relatively low value and queryDepth probably too high GraphQL QueryComplexityLimiter queryComplexity is set to a relatively low value and queryDepth probably too high Mar 10, 2021
@paales paales changed the title GraphQL QueryComplexityLimiter queryComplexity is set to a relatively low value and queryDepth probably too high GraphQL QueryComplexityLimiter queryComplexity is set too low value and queryDepth probably too high Mar 10, 2021
@stale
Copy link

stale bot commented May 27, 2021

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!

@stale stale bot added the stale issue label May 27, 2021
@paales
Copy link
Contributor Author

paales commented May 30, 2021

This isn't stale

@stale stale bot removed the stale issue label May 30, 2021
@engcom-Lima engcom-Lima self-assigned this May 31, 2021
@m2-assistant
Copy link

m2-assistant bot commented May 31, 2021

Hi @engcom-Lima. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Lima
Copy link
Contributor

Hi @paales ,

default query complexity and depth thresholds are configurable via the magento2/app/code/Magento/GraphQl/etc/di.xml file.
20
300

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 engcom-Lima added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Jun 14, 2021
@m2-community-project m2-community-project bot moved this from In Progress to Ready for Grooming in Feature Requests Backlog Jun 14, 2021
@m2-community-project m2-community-project bot moved this from Ready for Grooming to In Progress in Feature Requests Backlog Jun 14, 2021
@paales
Copy link
Contributor Author

paales commented Jun 14, 2021

@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?

@bloodf
Copy link

bloodf commented Sep 14, 2021

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.

@hnsr
Copy link

hnsr commented Dec 23, 2021

@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

@joshdavenport
Copy link

joshdavenport commented Feb 28, 2023

300 is still set as the default query complexity limit. This really ought to be assessed.

2.4-develop

<argument name="queryComplexity" xsi:type="number">300</argument>

2.5-develop

<argument name="queryComplexity" xsi:type="number">300</argument>

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issue: needs update Additional information is require, waiting for response Progress: dev in progress Project: GraphQL Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it Type: Feature/Improvement
Projects
Development

No branches or pull requests

6 participants