Skip to content

feat: implement default GraphQL query depth limiting #9789#9831

Open
envsecure wants to merge 2 commits intokeystonejs:mainfrom
envsecure:fix/graphql-query-depth-limit
Open

feat: implement default GraphQL query depth limiting #9789#9831
envsecure wants to merge 2 commits intokeystonejs:mainfrom
envsecure:fix/graphql-query-depth-limit

Conversation

@envsecure
Copy link
Copy Markdown
Contributor

Description

This PR addresses the security concern raised in #9789 by implementing a default GraphQL query depth limit.

🛡️ Why is this needed?

Without a depth limit, malicious users can send deeply nested circular queries (e.g., author -> posts -> author -> posts...) that consume exponential server resources, leading to a Denial of Service (DoS).

🛠️ Changes

  • Configuration: Added maxDepth to the graphql section of KeystoneConfig. It defaults to 20 levels, which is a sensible balance between security and flexibility.
  • Validation: Integrated the industry-standard graphql-depth-limit package as a validation rule in the Apollo Server setup.
  • Dependencies: Added graphql-depth-limit to @keystone-6/core.

Verification

  • Added the maxDepth type to the config so it's discoverable via IntelliSense.
  • Updated the server creation logic to inject the depthLimit rule before any user-defined rules.

Resolves #9789

envsecure and others added 2 commits May 2, 2026 13:06
This PR implements query depth limiting to protect the Keystone server from deeply nested circular queries that can cause resource exhaustion (DoS).

- Added 'maxDepth' option to KeystoneConfig (default: 20).
- Integrated 'graphql-depth-limit' validation rule into Apollo Server setup.
- Added 'graphql-depth-limit' as a dependency to @keystone-6/core.

Resolves keystonejs#9789
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should Keystone enforce GraphQL query depth limits by default?

1 participant