Advisory

GHSA-c4qx-w738-7hr3

Details, part 2 of 2. The advisory

Details

Vulnerable code

packages/utils/src/mergeIncrementalResult.ts, lines 12-64 at 134d67ae36a559651f43ec7fe4a9da76f4a00c2b (extract; the ... markers are elisions of intervening lines, not source text):

const path = ['data', ...(incrementalResult.path ?? [])];
...
const key = keyPath[i];
if (key === '__proto__' || key === 'constructor' || key === 'prototype') return;
if (current[key] == null) current[key] = ...;
current = current[key];
...
current[finalKey] = existingValue != null ? mergeDeep([existingValue, value]) : value;
  • The guard line (key === '__proto__' || ..., lines 50-52) is the intended defense; it is safe only for primitive string segments.
  • current = current[key] (lines 53-57) is where a non-primitive segment is coerced into a forbidden key — this is the traversal that escapes the response object.
  • current[finalKey] = ... (lines 59-64) is the sink: the write that lands on Object.prototype.
  • The final-segment check at lines 60-62 repeats the same strict-equality pattern and has the same weakness.

Reproduction

Verified — reproduced dynamically, not only by inspection. Three independent reproductions were run:

  1. Source level. packages/utils/src/{mergeIncrementalResult,mergeDeep,helpers}.ts were copied from master unchanged except for retargeting relative .js import specifiers to .ts, then run under node --experimental-strip-types --test. 5/5 tests pass, including a control proving that the plain-string "__proto__" segment is blocked, while the payload {"path":[["__proto__"],"polluted"],"data":{"pwned":true}} sets Object.prototype.polluted = {pwned: true} and leaves the executionResult as {"data":{}}. The data, items (@stream) and recursive incremental[] branches are all affected.
  2. Published artifacts. The same attacks were run against the real npm dist builds: 10.10.0 = 0/5 attacks succeed (still uses dset, which blocks it); 10.10.1, 11.0.0, 12.0.0 and 12.0.1 = 5/5 attacks succeed. This differential confirms the affected range and that fbb58b51c4993ba9680ce6c2ef7203ab3a142713 introduced the issue; that commit is still the last one touching the file on master, so HEAD (ccca0ff0dc8ea20726fd116b2f19a38709c30e62) is unfixed.
  3. Real call site over the network. A local HTTP server returned a spec-shaped multipart/mixed @defer response whose deferred patches carry path: [["__proto__"],"isAdmin"]. The client only JSON.parse()d the chunks and called the public mergeIncrementalResult(). Afterwards Object.getOwnPropertyNames(Object.prototype) contains isAdmin and ownerEmail, ({}).isAdmin === true, and a consumer-style check opts.isAdmin === true on a fresh {} returns true.

Minimal standalone reproduction:

import { mergeIncrementalResult } from '@graphql-tools/utils';

const executionResult = { data: {} };
const incrementalResult = JSON.parse('{"path":[["__proto__"],"polluted"],"data":"yes"}');
mergeIncrementalResult({ incrementalResult, executionResult });
console.log(({} as any).polluted); // expected vulnerable output: yes
delete (Object.prototype as any).polluted;

Steps: run the above under Node against the built @graphql-tools/utils package, then inspect a freshly created object after the merge.

  • Expected: the helper rejects the malformed path; ({} as any).polluted remains undefined and no property is added to Object.prototype.
  • Actual: the write lands on Object.prototype; ({} as any).polluted is "yes" on a fresh object, while executionResult is left as {"data":{}}.

Suggested remediation

Validate the type of every path segment before it is used for property access, so that only primitive string/number keys ever reach bracket access — and compare against the forbidden names only after that validation.

function isSafeKey(key: unknown): key is string | number {
  if (typeof key !== 'string' && typeof key !== 'number') return false;
  return key !== '__proto__' && key !== 'constructor' && key !== 'prototype';
}

// walking segment
const key = keyPath[i];
if (!isSafeKey(key)) return;
if (!Object.prototype.hasOwnProperty.call(current, key) || current[key] == null) {
  current[key] = ...;
}
current = current[key];

// final segment
if (!isSafeKey(finalKey)) return;
current[finalKey] = existingValue != null ? mergeDeep([existingValue, value]) : value;

A stronger variant, if it fits the project's style: build intermediate containers with Object.create(null) and use own-property access (Object.prototype.hasOwnProperty.call) throughout the walk, so an inherited property can never be resolved or written even if a future guard is missed.

Notes:

  • The final-segment check (lines 60-62) needs the same treatment as the walking check (lines 50-52); patching only one leaves the other reachable.
  • All three branches that reach this sink — data, items (@stream) and the recursive incremental[] handling — are affected by the same helper and are fixed together by validating in setObjectKeyPath.
  • Nothing outside this helper appears to need changing: 10.10.0 and earlier, which delegated to dset, were not exploitable by any of the tested payloads, so the regression is confined to the hand-rolled traversal added in fbb58b51c4993ba9680ce6c2ef7203ab3a142713.
  • Whether a released fix or backport policy is wanted for the 10.x and 11.x lines is the maintainers' call; no fix, advisory, or upstream issue currently exists for this.

Suggested regression test alongside the existing tests for mergeIncrementalResult (exact spec file path: unknown — not identified in this review): assert that merging {"path":[["__proto__"],"polluted"],"data":"yes"} leaves ({} as any).polluted undefined and Object.getOwnPropertyNames(Object.prototype) unchanged, with a paired control asserting the plain-string "__proto__" segment is still rejected, and equivalents for an object-valued segment (e.g. {"toString":() => "__proto__"}-style coercion) and for the items/incremental[] branches.

Resolution

Fixed in @graphql-tools/[email protected], which is published on npm. setObjectKeyPath rejects a path unless every segment is a primitive string or number, and still blocks __proto__, constructor, and prototype. Upgrade to >=12.0.2.

Sources & licences