GraphQL Subscription Security

Subscriptions run over a separate, long-lived transport (WebSocket via graphql-ws, or HTTP SSE/multipart), so authentication, authorization and token expiry are frequently implemented — or forgotten — independently of the query/mutation path.

How it works

A subscription authenticates once, usually via the connectionParams of the ConnectionInit message, then receives a stream of events resolved and filtered server-side. That creates distinct places to get it wrong:

  • Identity at connect time — trusting client-supplied claims in connectionParams rather than verifying a token.
  • Identity reuse — gateways/executors that pool upstream connections and leak one caller’s connectionParams into another’s.
  • Transport parity — controls enforced on the WebSocket gateway but not on HTTP streaming (SSE, multipart) for the same operation.
  • Per-event authorization — filtering applied to some events but not to every event published, especially when notifications are batched.
  • Session lifetime — no teardown when the token expires mid-stream.
  • Transport resource limits — per-route WebSocket upgrade builders that skip the server’s configured frame/message/buffer limits (see SurrealDB below).

Notable cases

CaseFailure
@neo4j/graphql < 7.5.6A pre-decoded connectionParams.jwt object was accepted without verification: any WebSocket client could forge sub / roles and satisfy @authentication and @subscriptionsAuthorization (CWE-287). Requires features.subscriptions + features.authorization and a transport forwarding connectionParams into context
@graphql-tools/executor-graphql-ws 3.2.0 (GHSA-364q-4p2h-gcf3)A closure accumulator merged every request’s extensions.connectionParams into never-reset state, and ConnectionInit was assembled inside the shared options object. In GraphQL Mesh’s documented config, the first subscriber’s token overwrote the template, so later subscribers — anonymous ones included — were authenticated upstream as that user and got that user’s events. Same defects were fixed earlier in executor-legacy-ws (CVE-2026-118665)
graphql-orm-router (audit RTR-2)Hive-native HTTP subscriptions (Accept: text/event-stream or multipart) bypassed the WebSocket gateway: no mandatory bearer, no teardown at token expiry, no attempt limiter. Only Upgrade: websocket requests were routed through the gateway
AshGraphql 1.10.1 Subscription.Batchershould_send?/1 dropped forbidden/not-found results only for the first notification in a batch; the rest were published unfiltered. Two qualifying notifications inside the default 1 s subscription_batch_interval were enough to leak unauthorized records
SurrealDB GHSA-p3c2-wh5f-jwqmThe GraphQL WebSocket upgrade did not apply the operator’s SURREAL_WEBSOCKET_* limits that the /rpc and /sql handlers did; auth middleware produced an anonymous session and schema generation skipped check_anon, so an unauthenticated client could pin 64 MiB per connection and exhaust process memory. Fixed in 4.0.0

Testing

  • Find subscription fields in the schema (subscriptionType in the introspection result) and every transport the server negotiates: WebSocket subprotocols, SSE, multipart.
  • Connect with no token, an expired token, a token for another tenant, and hand-built claims in connectionParams; compare events received.
  • Open two concurrent subscribers through any gateway/mesh with different identities and check for cross-session bleed.
  • Trigger several events in quick succession to exercise batched notification paths.
  • Hold a stream past token expiry and after logout/role change.

Defenses

  • Verify signed tokens at ConnectionInit; never accept decoded claims from the client.
  • Enforce the same principal, scope and expiry checks on every transport, or reject subscriptions off the trusted path.
  • Authorize per event at publish time, including every element of a batch.
  • Keep per-connection state per connection; treat shared executor options as immutable.
  • Bind frame, message and buffer limits on every WebSocket upgrade path, not only the primary RPC route.

Sources