/

CVE-2026-30241

Severity:

HIGH RISK

(8.2)

Missing Authorization / Policy Enforcement in Mercurius

CVE-2026-30241

Analyzed

Vulnerability type

Category:

Missing Authorization / Policy Enforcement

CWE:

CWE-863

Impact:

Denial of Service via Unbounded GraphQL Subscription Depth

Severity:

HIGH RISK

(8.2)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Mercurius, a GraphQL adapter for Fastify, fails to apply the configured queryDepth limit to subscription operations received over WebSocket connections.

As a result, a remote client can send arbitrarily deep subscription queries that bypass depth restrictions, potentially causing denial of service on schemas with recursive or highly nested types.

Affected context

This vulnerability appears in Mercurius-based GraphQL APIs that:

  • Use WebSocket-based GraphQL subscriptions
  • Rely on Mercurius' queryDepth configuration to limit query complexity
  • Expose schemas containing recursive types or deeply nestable fields

The issue is specific to subscription operations over WebSocket; HTTP queries and mutations still correctly enforce the depth limit, which can create a false sense of protection if subscriptions are assumed to be covered by the same policy.

Exploit preconditions

  • Attack surface: Public or internal GraphQL endpoints that accept subscriptions over WebSocket using Mercurius.
  • Required access: Ability to open a WebSocket connection as a client (typically unauthenticated or minimally authenticated, depending on API design).
  • Trigger point: Sending a deeply nested GraphQL subscription operation that exceeds the intended queryDepth configuration.
  • Why exploitation is possible: The subscription handling path parses and executes queries without invoking the queryDepth validation logic, effectively skipping an intended authorization/policy check on query complexity.

Why this happens

The core issue is a missing enforcement of an existing security/policy control in one execution path.

Mercurius implements a queryDepth mechanism intended to restrict how deeply nested GraphQL operations can be, limiting resource consumption and preventing abusive queries.

While this depth check is applied for HTTP-based queries and mutations, the subscription-over-WebSocket code path processes operations without calling the same validation routine.

This maps to CWE-863: Incorrect Authorization in the sense of incomplete policy enforcement: a configured authorization/guard (maximum query depth) is selectively applied, leaving a gap where certain operation types are not subject to the intended restriction.

Potential impact

  • Remote clients can submit extremely deep subscription queries that bypass configured depth limits.
  • Servers may experience excessive CPU and memory usage as recursive or deeply nested fields are resolved on each subscription event.
  • Degradation of performance for other users, including increased latency and timeouts.
  • Complete denial of service if resource exhaustion leads to process crashes or unresponsiveness.
  • Amplified impact on multi-tenant or shared infrastructure where one abusive client can affect many applications.

General mitigation guidance

Mitigation focuses on ensuring consistent application of query complexity controls across all GraphQL operation types and transport mechanisms.

Recommended patterns include:

  • Centralize query validation so that depth and complexity checks run for queries, mutations, and subscriptions, regardless of protocol (HTTP or WebSocket).
  • Apply a unified request/operation pipeline that enforces limits (depth, cost, rate) before execution begins.
  • Introduce additional complexity limits such as maximum selection count, maximum field aliases, and recursion guards, especially for schemas with recursive types.
  • Enforce strict authentication and authorization policies for subscription endpoints, reducing anonymous or low-trust access to long-lived connections.
  • Implement rate limiting and connection quotas per client, token, or IP to limit abusive subscription usage.
  • Design schemas to avoid unbounded recursion or provide server-side caps on list sizes and pagination to limit per-event workload.

How teams detect issues like this

Detecting this kind of issue typically involves both code-level and operational strategies:

  • Static/Code review:
  • Verify that query validation (depth, complexity, cost) is invoked in all operation handlers, including WebSocket subscription handlers.
  • Look for duplicated or divergent code paths for HTTP and WebSocket handling; ensure shared middleware or validation logic is factored into common utilities.
  • Check configuration handling to confirm that queryDepth or similar limits are not conditionally bypassed for subscriptions.
  • Automated analysis:
  • Use static analysis or linters with custom rules to detect GraphQL execution calls that bypass registered validation middleware.
  • Adopt security-focused code scanning that flags inconsistent enforcement of policy checks across protocol implementations.
  • Runtime monitoring:
  • Instrument GraphQL servers to log operation depth/complexity and monitor for anomalous patterns, such as extremely nested subscription operations.
  • Track resource utilization (CPU, memory, event-loop lag) correlated with subscription activity, and alert on spikes tied to a small set of clients or operations.
  • Apply WebSocket connection and message-level observability (including basic shape/size of queries) to identify abuse patterns.

Sources

SourceLink
github.comgithub.com/mercurius-js/mercurius/commit/5b56f60f4b0d60780b0ff499a479bd830bdd6986
github.comgithub.com/mercurius-js/mercurius/security/advisories/GHSA-m4h2-mjfm-mp55

Frequently asked

questions

Yes. Any remote client that can establish a WebSocket connection to the Mercurius GraphQL endpoint and send subscription operations can attempt to exploit unbounded query depth, subject to whatever network and authentication controls are in place.

An attacker typically needs only the ability to open and maintain a WebSocket connection to the GraphQL server. If subscriptions are available to anonymous users or lightly authenticated clients, the barrier to exploitation is low.

The safest pattern is to centralize and mandate query validation for all operation types and transports. Ensure that depth and complexity checks are applied consistently to queries, mutations, and subscriptions before execution, and that they cannot be accidentally bypassed in alternative code paths.

To prevent similar gaps, design the GraphQL server around a single, shared validation pipeline; avoid duplicating logic for different transports. Complement this with defense-in-depth: enforce strict schema-level limits, implement rate limiting and connection quotas, and include automated checks in CI/CD that verify new handlers or protocols reuse the existing validation mechanisms.

Find out what's already
exploitable in your codebase.