Skip to content

API security

GraphQL query limits: test depth and cost safely

Review GraphQL depth, amount and cost limits with small controlled queries and an agreed resource budget.

By BugSnaps · Updated

Add BugSnaps as a preferred source on Google(opens in a new tab)

Want more of our security guides? Select BugSnaps and confirm your choice on Google.

Direct answer

GraphQL query depth, requested amounts and batching can affect resource use. Define normal client requirements and test enforcement in a safe environment without attempting a denial of service.

Establish supported queries

Ask the owner for documented depth, amount, timeout and cost policies, and a representative ordinary query. Use synthetic data in a test environment with explicit request and concurrency limits. Agree an operational stop contact.

Reference: OWASP GraphQL Cheat Sheet.

Compare bounded cases

Run the normal query as a positive control, then an approved query just beyond the documented depth or amount limit. Check the response and server metrics. Do not create huge result sets or repeatedly increase load until the service fails.

  • Keep requests within the agreed budget.
  • Test depth and amount independently.
  • Record the applicable identity and query shape without secrets.

Review related controls

A shallow query can still be costly if it requests many items or expensive fields. Assess pagination, query cost, batching, timeouts and per-user rate controls together. Check that rejecting a query does not leak sensitive details in an error.

Retest real clients

After changing limits, repeat the allowed and rejected test queries and exercise representative client workflows. Record unavailable metrics and any approved exception for legitimate complex operations.

Assessment limits

A small threshold test does not demonstrate resilience to distributed denial of service or all query shapes. Performance tests need separate capacity planning and authorization.

Frequently asked questions

Does a depth limit control every expensive query?

No. Amount, field cost, batching and backend behavior also affect resource consumption.

Should testers increase query size until the server fails?

No. Use agreed bounded thresholds and operational monitoring to avoid disrupting the service.

Primary sources and further reading

These guides combine published security guidance with practical assessment planning. Adapt checks to the owner's policy, environment, and authorized scope.

This guide was prepared with AI assistance using the linked sources and illustrative examples. Check current vendor guidance and your environment before making changes.

Apply the guide to your own assessment.

Start with an authorized target, known test data, and a clear scope. Use the report's evidence and coverage limits to decide which checks need further review.

Open MyPentest