Details
- Reachability — the package directly exports
buildWSLegacyExecutor(`index.ts:27`), and the entry point is the returned disposable executor plusrequest.extensions.connectionParams.
Vulnerable code
packages/executors/legacy-ws/src/index.ts, lines 32-100 at b5d1c36ebb8ed3868260ffee5bbcbb423ad5c1f1:
let executorConnectionParams = {}; // closure state, lives as long as the executor
...
payload = Object.assign(payload, executorConnectionParams); // sink: retained keys enter connection_init
websocket!.send(JSON.stringify({ type: LEGACY_WS.CONNECTION_INIT, payload }));
...
if (request.extensions?.['connectionParams'] && typeof request.extensions?.['connectionParams'] === 'object') {
executorConnectionParams = Object.assign(executorConnectionParams, request.extensions['connectionParams']);
}
// no else branch: a request that omits connectionParams leaves the previous request's keys in place,
// and cleanupWebsocket (lines 78-88) resets only `websocket`, never `executorConnectionParams`.
Reproduction
Verified dynamically against the real package, not by static review alone. Release 1.1.33 was installed from npm and driven against a live local ws server implementing the legacy graphql-ws protocol, recording the connection_init payload of every physical connection.
Observed across the validation runs, using one shared executor instance:
- Request 1 (victim) sent
extensions.connectionParams{Authorization: "Bearer VICTIM-ALICE-SECRET-TOKEN", tenant: "alice-tenant"}. After that subscription completed, the executor sentconnection_terminateand tore the socket down. - Request 2 supplied no
connectionParams, yet the server observed a brand-new connection whoseconnection_initpayload was byte-identical to the victim's, including the victim's bearer token. - Partial overwrite: when the later caller supplied only
{tenant: "mallory-tenant"},Object.assignmerged rather than replaced, so the victim'sAuthorizationwas retained alongside the attacker's tenant. - Calling
executor[Symbol.dispose]()between requests did not clear the state. - Negative control: patching the installed
1.1.33to addexecutorConnectionParams = {}insidecleanupWebsocketmade the second connection's init payload{}, so the leak is causally attributable to the missing reset. - The same proof of concept leaks identically on
1.1.35, andmasterstill contains the unreset closure. Upstream line numbers onmasterare slightly offset from those cited above (closure declaration L38, conditionalObject.assignL100-105,cleanupWebsocketL84,onopenmerge L60-63).
Steps:
- Run a legacy GraphQL WS server that records the
connection_initpayload and authorizes notifications byAuthorizationvalue. - Use one executor for a victim request with
extensions.connectionParams.Authorization = 'Bearer victim-token'; finish/unsubscribe it so cleanup closes the socket. - Use the same executor for an anonymous request with no
extensions.connectionParams. - Observe that the second
connection_initstill containsBearer victim-tokenand that the anonymous subscription receives victim-authorized results.
import WebSocket from 'isomorphic-ws';
import { parse } from 'graphql';
import { buildWSLegacyExecutor } from '@graphql-tools/executor-legacy-ws';
const exec = buildWSLegacyExecutor('ws://localhost:8081/graphql', WebSocket);
const v = exec({
document: parse('subscription { privateEvents { id } }'),
extensions: { connectionParams: { Authorization: 'Bearer victim-token' } },
});
await v.next();
await v.return?.(); // iterator cleanup closes the first socket; executorConnectionParams is not cleared
const a = exec({ document: parse('subscription { privateEvents { id } }') });
await a.next(); // the server logs a second connection_init payload still carrying Authorization: Bearer victim-token
- Expected: the second
connection_initpayload contains only the base options and the second request's own parameters, with no key omitted by that request carried over from the victim. - Actual: the second
connection_initcarries the victim's retainedAuthorization/tenant values, and the downstream server authenticates the later caller as the victim.
Suggested remediation
Do not retain operation-level extensions.connectionParams beyond the operation and connection they belong to: build each connection_init payload from the base options plus the current request's parameters only, and clear connection-specific state during cleanup.
// 1. Clear the retained state when the connection is torn down.
function cleanupWebsocket() {
// ... existing connection_terminate / terminate / websocket = null ...
executorConnectionParams = {};
}
Alternative, and the more complete form: stop accumulating into shared closure state at all — derive the payload per request, e.g. const payload = { ...options.connectionParams, ...(request.extensions?.['connectionParams'] ?? {}) }, passed down to the onopen handler for that connection rather than read from the executor closure.
Notes:
executor[Symbol.dispose]()is bound tocleanupWebsocket, so fixing the reset there also makes the documented teardown behave as callers expect.Object.assignmerges rather than replaces, so a later request supplying *some* parameters still inherits the keys it omits; a fix that only replaces the object on the "present" branch would leave this half-open.- The
UrlLoaderpath in this repository constructs a fresh executor per request and is already safe; no change is needed there. The exposure is to direct consumers of the exportedbuildWSLegacyExecutor. - It would also help to define explicitly whether mixing distinct auth contexts on one executor is supported, and to reject it if not — today the factory returns a general
Executorwith no stated per-identity restriction.
Suggested regression test alongside the package's existing legacy-ws executor tests (the exact spec file is not verified by the available information): drive one executor against a recording server, send request 1 with extensions.connectionParams = { Authorization: 'Bearer victim-token' }, let it complete, then send request 2 with no connectionParams, and assert the second connection_init payload contains no Authorization key. Add a second case where request 2 supplies only { tenant: 'other' } and assert the payload is exactly { tenant: 'other' } plus base options.
Disclosure status
Currently undisclosed: no CVE, GHSA, advisory URL, upstream issue, or fix commit is associated with this finding, and no fixed version exists to upgrade to.
Resolution
Fixed in @graphql-tools/[email protected], which is published on npm. Each execution opens its own socket. connection_init is built from the executor's base connectionParams plus only that request's extensions.connectionParams. Upgrade to >=1.1.36.