-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The patch is one line, and the variable was already in the file.\n\nThe v8.5.0 fix to `lib/web/websocket/receiver.js`, committed as `b4c287b3` by Matteo Collina on June 8, 2026:\n\n```diff\n #validatePayloadLength () {\n if (\n this.#maxPayloadSize > 0 &&\n !isControlFrame(this.#info.opcode) &&\n- this.#info.payloadLength > this.#maxPayloadSize\n+ this.#info.payloadLength + this.#fragmentsBytes > this.#maxPayloadSize\n ) {\n failWebsocketConnection(this.#handler, 1009, 'Payload size exceeds maximum allowed size')\n return false\n }\n return true\n }\n```\n\n`#fragmentsBytes` is not a new field. It was declared at line 27 of the same file in the same PR that introduced `maxPayloadSize`. It was incremented on every call to `writeFragments()`, which the receiver calls for every frame body it consumes:\n\n```js\nwriteFragments (fragment) {\n this.#fragmentsBytes += fragment.length\n this.#fragments.push(fragment)\n}\n```\n\nThe class wrote into `#fragmentsBytes` every time it accepted a frame body. The gate at `#validatePayloadLength()`, called from each of the three payload-length-decoding states (7-bit, 16-bit, 64-bit), compared only the current frame's `payloadLength` against `#maxPayloadSize` and stopped. The state needed to enforce the cumulative limit was in the object the whole time. The condition that reads it against the limit was not.\n\n## The compressed path read `#fragmentsBytes`. The uncompressed path did not.\n\nInside `ByteParser.run()` at the `READ_DATA` state, the receiver branches on `this.#info.compressed`. The two branches are sister branches. Both handle a single frame's body. Both call `writeFragments()`. Both check whether the FIN bit is set. Both transition the state machine back to `INFO` for the next frame. In v8.4.1, only one of them consulted `#fragmentsBytes`.\n\nThe uncompressed branch:\n\n```js\nif (!this.#info.compressed) {\n this.writeFragments(body)\n\n // If the frame is not fragmented, a message has been received.\n // If the frame is fragmented, it will terminate with a fin bit set\n // and an opcode of 0 (continuation), therefore we handle that when\n // parsing continuation frames, not here.\n if (!this.#info.fragmented && this.#info.fin) {\n websocketMessageReceived(this.#handler, this.#info.binaryType, this.consumeFragments())\n }\n\n this.#state = parserStates.INFO\n}\n```\n\nThe compressed branch, fifteen lines below it in the same function:\n\n```js\n} else {\n this.#extensions.get('permessage-deflate').decompress(\n body,\n this.#info.fin,\n (error, data) => {\n if (error) {\n const code = error instanceof MessageSizeExceededError ? 1009 : 1007\n failWebsocketConnection(this.#handler, code, error.message)\n return\n }\n\n this.writeFragments(data)\n\n // Check cumulative fragment size\n if (this.#maxPayloadSize > 0 && this.#fragmentsBytes > this.#maxPayloadSize) {\n failWebsocketConnection(this.#handler, 1009, new MessageSizeExceededError().message)\n return\n }\n\n if (!this.#info.fin) {\n this.#state = parserStates.INFO\n this.#loop = true\n this.run(callback)\n return\n }\n\n websocketMessageReceived(this.#handler, this.#info.binaryType, this.consumeFragments())\n this.#loop = true\n this.#state = parserStates.INFO\n this.run(callback)\n },\n this.#fragmentsBytes\n )\n}\n```\n\nThe compressed branch carries an explicit comment, `// Check cumulative fragment size`, naming the concern the receiver is supposed to enforce. The same concern applies to the uncompressed branch. The check is not there. This is the [parallel-implementation-gap](/patterns/parallel-implementation-gap) shape at its smallest grain: not two adapters in two files for two runtimes, but two arms of an `if/else` inside one function, sharing the same private field, with one arm consulting the field against the configured limit and the other arm not.\n\nThe CVSS vector reads `AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H`. The attacker is the WebSocket server the client opens. The class of victim is any Node.js application that calls `new WebSocket(url, ...)` against a server it does not fully control and trusts the `maxPayloadSize` knob to bound its heap: server-side fetches of third-party WebSocket APIs, webhook delivery loops, observability shippers, MCP transports, plugin-marketplace gateways. For every such application running undici 8.0.0 through 8.4.1, the knob was advisory on the uncompressed fragmented path. The application configured a hundred-byte ceiling and the receiver allowed sixty-five thousand frames of sixty bytes each.\n\n## The 6.x port of the same PR had both checks.\n\nThe April 13, 2026 commit that introduced the feature on the 8.x line, `bd91f867 feat: add configurable maxPayloadSize for WebSocket (#4955)`, has a sibling on the 6.x line: `d7a1e55f feat: add configurable maxPayloadSize for WebSocket (#4955)`. Same author. Same commit subject. Same PR reference. Committed within seconds of each other on the same Monday at 06:59 UTC. The two commits diverge in `lib/web/websocket/receiver.js`. The 6.x port's `READ_DATA` handler:\n\n```js\n} else {\n if (!this.#info.compressed) {\n this.writeFragments(body)\n\n if (this.#maxPayloadSize > 0 && this.#fragmentsBytes > this.#maxPayloadSize) {\n failWebsocketConnection(this.ws, new MessageSizeExceededError().message)\n return\n }\n\n if (!this.#info.fragmented && this.#info.fin) {\n websocketMessageReceived(this.ws, this.#info.binaryType, this.consumeFragments())\n }\n\n this.#state = parserStates.INFO\n } else {\n this.#extensions.get('permessage-deflate').decompress(\n body,\n this.#info.fin,\n (error, data) => {\n if (error) {\n failWebsocketConnection(this.ws, error.message)\n return\n }\n\n this.writeFragments(data)\n\n if (this.#maxPayloadSize > 0 && this.#fragmentsBytes > this.#maxPayloadSize) {\n failWebsocketConnection(this.ws, new MessageSizeExceededError().message)\n return\n }\n // ...\n```\n\nBoth branches in the 6.x port carry the four-line `#maxPayloadSize > 0 && #fragmentsBytes > #maxPayloadSize` check immediately after `writeFragments()`. v6.25.0 enforced cumulative payload size on uncompressed fragmented messages from the day the feature shipped. v8.1.0 did not. The two ports were committed to the repository inside the same minute.\n\nThe 7.x line is unaffected for a different reason. The `maxPayloadSize` option was never ported there. v7.x clients have no cumulative bound because they have no per-frame bound either. The CVE record names 8.0.0 through 8.4.x because that is the range where the option exists, advertises a limit, and lets the application configure a knob that does not function on fragmented uncompressed input. Six.x has the same option and the limit is enforced; seven.x has no option; eight.x had the option without the enforcement.\n\nThis is the [backport-gap](/patterns/backport-gap) shape from a different angle. The pattern's earlier exhibits, [Apache MINA's 2.0.28 / 2.1.11 / 2.2.6 release](/posts/mina-fix-shipped-on-one-branch) and [FreeBSD's `setcred(2)` fix sitting in `main` since November](/posts/freebsd-setcred-fix-in-main-since-november), describe a fix authored once and propagated to some maintenance branches and not others. CVE-2026-9675 describes the inverse direction. A feature was authored once and propagated to two branches on the same day. The safety check that came with the feature shipped intact on one port and was stripped from the other. The CVE record covers the branch that received the abridged port. The patch logic that closes it had been running in production on the 6.x branch for eight weeks before the v8.5.0 fix landed.\n\n## The PoC is the test the maintainer wrote.\n\nThe same `b4c287b3` commit that adds `+ this.#fragmentsBytes` to the gate adds a regression test the bug class did not have. The test is also the proof of concept the advisory does not include:\n\n```js\ntest('cumulative payload size', (t, done) => {\n t.plan(1)\n\n const LIMIT = 100\n const FRAGMENT_SIZE = 60\n const NUM_FRAGMENTS = 10\n\n const server = new WebSocketServer({ port: 0 })\n\n server.on('connection', (ws) => {\n const socket = ws._socket\n const payload = Buffer.alloc(FRAGMENT_SIZE, 0x41)\n\n for (let i = 0; i < NUM_FRAGMENTS; i++) {\n const fin = i === NUM_FRAGMENTS - 1 ? 0x80 : 0x00\n const opcode = i === 0 ? 0x02 : 0x00\n const header = Buffer.alloc(2)\n header[0] = fin | opcode\n header[1] = FRAGMENT_SIZE\n socket.write(header)\n socket.write(payload)\n }\n })\n\n const agent = new Agent({ webSocket: { maxPayloadSize: LIMIT } })\n const client = new WebSocket(`ws://127.0.0.1:${server.address().port}`, { dispatcher: agent })\n\n client.onmessage = t.assert.fail\n\n client.addEventListener('error', (event) => {\n t.assert.ok(event)\n done()\n })\n})\n```\n\nThe server writes ten frames by hand at the socket level. The first frame's first byte is `0x02`, a binary opcode with FIN unset. The next eight frames' first bytes are `0x00`, a continuation opcode with FIN unset. The tenth frame's first byte is `0x80`, a continuation opcode with FIN set. Every frame declares a 60-byte payload. The configured `maxPayloadSize` is 100 bytes. Each frame, on its own, passes `#validatePayloadLength()`: 60 is not greater than 100. The cumulative payload is six hundred bytes, six times the configured limit. Before the patch, `client.onmessage` would be invoked with the full assembled six-hundred-byte buffer; the test's `client.onmessage = t.assert.fail` would fire and the test would fail. After the patch, `client.addEventListener('error')` fires partway through the fragment stream and the test passes.\n\nThe numbers in the test are pedagogical. A production attacker chooses 60 and 65,000 instead of 60 and 10, sends frames at line rate, and watches the Node.js process's resident-set climb past the configured ceiling until the kernel kills it. The application's WebSocket bound was 100 bytes. The receiver buffered as many bytes as the attacker chose to send. The limit was advisory.\n\nThe advisory credits the bug to mauriceng98 and Str1ckl4nd. Neither reporter had to read code the maintainer had not already written. The cumulative-bytes counter was being maintained correctly inside `ByteParser` on every frame the v8.1.0 client ever received. The condition that compares it against the configured ceiling was sitting in `lib/web/websocket/receiver.js` on the 6.x branch the entire time, in the version of `READ_DATA` shipped by the same `feat: add configurable maxPayloadSize for WebSocket (#4955)` subject line.\n\n## The branch that shipped the bug is the one that holds the variable.\n\nv8.5.0 unifies the two former 6.x checks into the single per-frame gate at `#validatePayloadLength()`. The architectural shape is cleaner than the 6.x version: one comparison, one place, both compressed and uncompressed branches covered because they both pass through the same gate before the body is read. The 6.x branch will, in time, presumably be refactored to match. For now, two of undici's three live maintenance lines enforce `maxPayloadSize` across fragments through different mechanisms in different files in different commits, and the third never had the option at all. The PR that shipped the feature shipped two ports of the same change. One of the ports is what the CVE is about.","closing_line":"The check was in the file. It was on the wrong branch's port.","hook_md":"undici cut v8.1.0 on April 13, 2026 with a new `maxPayloadSize` option for its WebSocket client. The same author cut v6.25.0 the same day with the same option and the same commit subject line, `feat: add configurable maxPayloadSize for WebSocket (#4955)`. v6.25.0's `ByteParser.run()` consulted `this.#fragmentsBytes` against `this.#maxPayloadSize` on both the compressed path and the uncompressed path. v8.1.0's version of the same function maintained `#fragmentsBytes` on every fragment write and never read it on the uncompressed path. CVE-2026-9675 is the eight weeks during which a malicious WebSocket server could stream sixty-byte fragments at a client with a hundred-byte limit until the client's heap ran out.","post_id":653,"slug":"undici-cve-2026-9675-cumulative-check-on-wrong-branch","title":"CVE-2026-9675: undici's 6.x Port of PR #4955 Had the Cumulative Check. The 8.x Port Did Not.","type":"initial","unreadable_sentence":"The check was in the file. It was on the wrong branch's port."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCau436QAKCRDeZjl4jgkQ JrLnAQCA0PLxozFKn2XeBfCbnGMidClsk6TswKV9jIFaX2xhagD/dXf5tTo7GB/h HRJcd/2pxy1vl4YJVTJ8m83NTmXqAQA= =69Be -----END PGP SIGNATURE-----