Skip to content

Conversation

grandchildrice
Copy link
Contributor

Summary

This PR addresses a DoS vulnerability in the GraphQL service by implementing a maximum query depth limit. While #26026 introduced timeout handling, it didn't fully mitigate the attack vector where deeply nested queries can still consume excessive CPU and memory resources before the timeout is reached.

Changes

  • Added maxQueryDepth constant (set to 20) to limit the maximum nesting depth of GraphQL queries
  • Applied the depth limit using graphql.MaxDepth() option when parsing the schema
  • Added test case TestGraphQLMaxDepth to verify that queries exceeding the depth limit are properly rejected

Security Impact

Without query depth limits, malicious actors could craft deeply nested queries that:

  • Consume excessive CPU cycles during query parsing and execution
  • Allocate large amounts of memory for nested result structures
  • Potentially cause service degradation or outages even with timeout protection

This fix complements the existing timeout mechanism by preventing resource-intensive queries from being executed in the first place.

Testing

Added TestGraphQLMaxDepth which verifies that queries with nesting depth > 20 are rejected with a MaxDepthExceeded error.

References

@fjl
Copy link
Contributor

fjl commented Aug 7, 2025

We'll have to see if this limit is too tight for real world uses, but it's good to add.

@rjl493456442 rjl493456442 added this to the 1.16.3 milestone Aug 19, 2025
@rjl493456442 rjl493456442 merged commit 1c74f23 into ethereum:master Aug 19, 2025
3 of 5 checks passed
gballet pushed a commit to gballet/go-ethereum that referenced this pull request Sep 11, 2025
## Summary

This PR addresses a DoS vulnerability in the GraphQL service by
implementing a maximum query depth limit. While ethereum#26026 introduced
timeout handling, it didn't fully mitigate the attack vector where
deeply nested queries can still consume excessive CPU and memory
resources before the timeout is reached.

## Changes
- Added `maxQueryDepth` constant (set to 20) to limit the maximum
nesting depth of GraphQL queries
- Applied the depth limit using `graphql.MaxDepth()` option when parsing
the schema
- Added test case `TestGraphQLMaxDepth` to verify that queries exceeding
the depth limit are properly rejected

## Security Impact

Without query depth limits, malicious actors could craft deeply nested
queries that:
  - Consume excessive CPU cycles during query parsing and execution
  - Allocate large amounts of memory for nested result structures
- Potentially cause service degradation or outages even with timeout
protection

This fix complements the existing timeout mechanism by preventing
resource-intensive queries from being executed in the first place.

## Testing

Added `TestGraphQLMaxDepth` which verifies that queries with nesting
depth > 20 are rejected with a `MaxDepthExceeded` error.

## References
  - Original issue: ethereum#26026
- Related security best practices:
https://www.howtographql.com/advanced/4-security/

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
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.

4 participants