Skip to content

Resource exhaustion exploit when parsing queries #3955

@tadhglewis

Description

@tadhglewis

Re-posting here as advised in apollographql/apollo-server#7688. Without digging into source code I'm not exactly sure which part of graphql-js is causing this.

Issue Description

We've identified a potential resource exhaustion vector which has a significant impact on our CPU and response times. We're currently experiencing this on AS 3 however we're able to reproduce on AS 4.

We have a custom query complexity calc plugin which is intended to handle this scenario and others however it seems before we get to didResolveOperation event/stage, there is some processing that takes a long time.

I'm assuming this is an underlying dependancy in Apollo however I'm not 100% sure so any ideas or suggestions on how we can mitigate this would be great.

Link to Reproduction

https://github.com/tadhglewis/apollo-koa-minimal

Reproduction Steps

  1. pnpm install && pnpm start
  2. Run
curl \
--data "{\"query\":\"{ $(python3 -c "print('%s' % ('__typename ' * 1000))")}\"}" \
--header 'Content-Type: application/json' \
--include \
--request POST \
https://example.com/graphql

This will take ~2.5s and increase to ~21s if you change the number of __typename to 3000

Screenshot 2023-08-16 at 10 33 30 pm

Notes

  • On subsequent requests there seems to be some caching and response time goes to ~10ms however if you change the number of __typename by one it will bypass this
  • This isn't limited to __typename, it can also be hit when using hello and I imagine introspection as well

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions