Schedule icon
Request icon
If icon
SlackIncomingWebhook icon
Fail icon
Log icon

GraphQL query depth and complexity limit enforcement gate

Verify GraphQL APIs enforce query depth and complexity limits before release, preventing nested query denial-of-service vulnerabilities.

Categories
Infrastructure

Prevent recursive query denial-of-service (DoS) vulnerabilities by validating that GraphQL APIs enforce query depth and complexity limiting middleware before code reaches production. In GraphQL, nested relationship graphs allow clients to send recursive queries (e.g. user { friends { friends { friends ... } } }) that force backend resolvers into expensive exponential database joins and CPU exhaustion. To protect servers, production APIs must implement query depth limiters that reject queries exceeding strict nesting thresholds (typically 5 to 7 levels). This gate dispatches an intentionally deep nested query against your candidate deployment, verifies that the server successfully rejects it, alerts SecOps if the query was processed without restriction, and fails deployment pipelines before vulnerable configurations go live.

How it works

  1. A Schedule trigger periodically invokes the security gate, or CI/CD pipelines trigger it before promoting staging builds.
  2. Task test_deep_nested_query uses io.kestra.plugin.graphql.Request to dispatch a 7-level nested introspection query to inputs.graphql_endpoint_url. With failOnGraphQLErrors: false and allowFailed: true, expected security rejection errors (such as "Query depth limit exceeded" or HTTP 400 Bad Request) are captured cleanly without crashing the task runner.
  3. Task evaluate_depth_protection (io.kestra.plugin.core.flow.If) inspects the response:
    • If the server returns HTTP 200 with no GraphQL errors and full data, it processed the deep query without restriction (VULNERABLE). The workflow sends an urgent Slack alert and invokes fail_deployment_gate (io.kestra.plugin.core.execution.Fail) to halt the release.
    • If the server returns GraphQL validation errors or rejects the request, task log_depth_protection_verified confirms clean PROTECTED status.
  4. Task log_audit_summary emits structured compliance metrics for audit logs.
  5. Top-level errors handler catches network unreachable or TLS handshake failures.

What you get

  • Automated pre-deployment verification that prevents shipping GraphQL endpoints vulnerable to query complexity attacks.
  • Deterministic testing of GraphQL middleware (such as graphql-depth-limit, graphql-armor, or Apollo complexity plugins).
  • Immediate Slack notifications detailing the tested endpoint, tested depth, and specific remediation guidelines.
  • Non-intrusive CI/CD gating that integrates seamlessly with GitHub Actions, GitLab CI, or Kestra webhooks.

Who it's for

  • Application Security (AppSec) and SecOps engineers enforcing API resilience standards.
  • Platform and Backend Engineers maintaining high-traffic GraphQL APIs.
  • QA and DevSecOps engineers incorporating automated security regression tests into release workflows.

Why orchestrate this with Kestra

Ad-hoc security scans or manual Postman testing are rarely integrated consistently into automated promotion gates. Kestra provides declarative, version-controlled execution with native GraphQL querying, conditional branching, secrets management, and automated failure handling. With Kestra, query depth verification functions as an observable, repeatable security contract that runs automatically across staging environments.

Prerequisites

  • Network access from the Kestra worker to the target GraphQL endpoint.
  • A valid authentication token or API key if the endpoint requires credentials.

Secrets

  • GRAPHQL_AUTH_TOKEN: Bearer token or API key used in the Authorization header to authenticate against the GraphQL endpoint.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL used to post security alerts and probe failure notifications.

Quick start

  1. Store your Slack webhook and API token in Kestra Secrets (SLACK_WEBHOOK_URL and GRAPHQL_AUTH_TOKEN).
  2. Configure graphql_endpoint_url with your staging GraphQL URL (e.g., https://staging-api.yourcompany.com/graphql).
  3. Trigger a manual execution from the Kestra UI to verify that your staging server successfully blocks the deep query.
  4. Connect the workflow to your deployment pipeline via Webhook trigger to enforce automated security gates on every release.

How to extend

  • Add multiple test queries with varying depth levels (e.g. 5, 7, and 10) to determine the exact threshold enforced by the server.
  • Test query complexity cost analysis by dispatching wide queries with aliased fields (e.g. requesting 50 distinct aliases in one call).
  • Automatically create a GitHub security advisory or issue if the gate fails during automated daily sweeps.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.