-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The patched version still ships `maxSubscriptions: Infinity`\n\nThe vendored snapshot of `packages/gossipsub/src/message/decodeRpc.ts` at commit `704b0e6`, the release commit that tagged v15.0.23 on May 16, 2026, reads in full:\n\n```typescript\nexport interface DecodeRPCLimits {\n maxSubscriptions: number\n maxMessages: number\n maxIhaveMessageIDs: number\n maxIwantMessageIDs: number\n maxIdontwantMessageIDs: number\n maxControlMessages: number\n maxPeerInfos: number\n}\n\nexport const defaultDecodeRpcLimits: DecodeRPCLimits = {\n maxSubscriptions: Infinity,\n maxMessages: Infinity,\n maxIhaveMessageIDs: Infinity,\n maxIwantMessageIDs: Infinity,\n maxIdontwantMessageIDs: Infinity,\n maxControlMessages: Infinity,\n maxPeerInfos: Infinity\n}\n```\n\nThe file's first commit is `8fbcb4c`, October 4, 2022. The commit message is `feat: limit RPC lists on decode`. The author is Lion (`dapplion`). The interface and the export of `defaultDecodeRpcLimits` both landed in that commit. The values landed as written above.\n\n`this.decodeRpcLimits` is `defaultDecodeRpcLimits` unless the consumer's `GossipSub` constructor argument overrides each field. The inbound RPC decoder in `gossipsub.ts`, three years and seven months later, still wires those fields into every call:\n\n```typescript\nconst rpc = RPC.decode(rpcBytes, {\n limits: {\n subscriptions: this.decodeRpcLimits.maxSubscriptions,\n messages: this.decodeRpcLimits.maxMessages,\n control$: {\n ihave: this.decodeRpcLimits.maxIhaveMessageIDs,\n iwant: this.decodeRpcLimits.maxIwantMessageIDs,\n ...\n }\n }\n})\n```\n\nA consumer who reads the libp2p documentation, accepts the defaults, and ships to production is running `RPC.decode(rpcBytes, { limits: { subscriptions: Infinity, messages: Infinity, ... } })` against every inbound frame.\n\n## What v15.0.23 actually patched\n\nPR #3405 by `Lodekeeper`, merged on May 16, 2026 as commit `2514c01`. Title: `fix(gossipsub): prune empty topic entries from topics map, reset topic map on stop`. Twenty source lines changed across three callsites in `gossipsub.ts`.\n\n`removePeer`, the disconnect cleanup path, lines 779 through 786:\n\n```diff\n // remove peer from topics map\n- for (const peers of this.topics.values()) {\n+ for (const [topic, peers] of this.topics) {\n peers.delete(id)\n+ if (peers.size === 0) {\n+ this.topics.delete(topic)\n+ }\n }\n```\n\n`handleReceivedSubscription`, the subscription-update path, lines 1007 through 1024:\n\n```diff\n let topicSet = this.topics.get(topic)\n- if (topicSet == null) {\n- topicSet = new Set()\n- this.topics.set(topic, topicSet)\n- }\n\n if (subscribe) {\n+ if (topicSet == null) {\n+ topicSet = new Set()\n+ this.topics.set(topic, topicSet)\n+ }\n+\n // subscribe peer to new topic\n topicSet.add(from.toString())\n- } else {\n+ } else if (topicSet != null) {\n // unsubscribe from existing topic\n topicSet.delete(from.toString())\n+ if (topicSet.size === 0) {\n+ this.topics.delete(topic)\n+ }\n }\n```\n\n`stop`, the lifecycle reset, line 577:\n\n```diff\n this.peers.clear()\n this.subscriptions.clear()\n+ this.topics.clear()\n```\n\nThree surgical fixes to the leak. Pre-patch, `removePeer` left an empty `Set` in `this.topics` for every topic the disconnecting peer had ever appeared in. Post-patch, the `Set` is deleted when its last member is. Pre-patch, an `UNSUBSCRIBE` message for a topic the sender was never subscribed to allocated a fresh `Set` because the `topicSet == null` check ran before the `subscribe` branch. Post-patch, `UNSUBSCRIBE` skips the allocation when the topic has no entry. Pre-patch, `stop()` did not clear `this.topics`. Post-patch, it does.\n\nAll three are necessary. None of them caps the number of unique topics a connected peer can pour into `this.topics` in a single decode pass.\n\n## The PoC targets the branch v15.0.23 did not touch\n\nThe advisory ships three test cases. The one labeled `FLOOD` directly injects 349,000 unique topic strings via `handleReceivedSubscription` and observes `this.topics.size` after the call. The one labeled `ENCODE` binary-searches the exact maximum subscription count that fits in a 4MB length-prefixed frame and returns 349,525. The one labeled `PERSIST` confirms empty `Set`s remain in `this.topics` after `removePeer`.\n\n`PERSIST` is the test the v15.0.23 patch makes pass. `FLOOD` and `ENCODE` test the same code path. That path, in v15.0.23's `gossipsub.ts`, post-patch, reads:\n\n```typescript\n/**\n * Handles a subscription change from a peer\n */\nprivate handleReceivedSubscription (from: PeerId, topic: TopicStr, subscribe: boolean): void {\n this.log('subscription update from %p topic %s', from, topic)\n\n let topicSet = this.topics.get(topic)\n\n if (subscribe) {\n if (topicSet == null) {\n topicSet = new Set()\n this.topics.set(topic, topicSet)\n }\n\n // subscribe peer to new topic\n topicSet.add(from.toString())\n } else if (topicSet != null) {\n // unsubscribe from existing topic\n topicSet.delete(from.toString())\n if (topicSet.size === 0) {\n this.topics.delete(topic)\n }\n }\n\n // TODO: rust-libp2p has A LOT more logic here\n}\n```\n\nThe `SUBSCRIBE` branch, the branch the `FLOOD` test exercises, allocates a new `Set` and stores it in `this.topics` for every unique topic string the connected peer presents. The shape is identical to the pre-patch version. The patch's reorganization moved the allocation inside the `subscribe` arm, but the arm itself still allocates unconditionally on every fresh topic.\n\nThe `Set` is small and empty. The `Map.set` writes a string key whose length is whatever the attacker chose to encode. V8's `Map` node, the `Set` header, the eventual single `PeerIdStr` member, and the JavaScript runtime's per-allocation overhead are what the advisory's eighty-nine megabyte per-frame heap-growth figure is summing across 349,525 entries.\n\nA v15.0.23 node will accept the 4MB frame, decode every `SUBSCRIBE` entry, and call this function 349,525 times. It will hit the Node.js default 1.5GB heap ceiling after roughly seventeen frames. After the attacker disconnects, the patched `removePeer` will iterate every entry and delete the empty `Set`s. The crash arrives before the cleanup runs.\n\nThe last line of the patched function is a comment. It has been there since commit `baf84f8`, April 5, 2022, four years and two months before CVE-2026-46679 was filed. It says, in full, that `rust-libp2p` has a lot more logic here. The author who wrote it understood that the JavaScript implementation was a thin port of a richer reference implementation, and that the gap was load-bearing enough to mark. The comment outlived the `topicSet.add` line above it through four years of refactors. The patch's diff preserves it. This is the [todo-that-shipped](/patterns/todo-that-shipped) pattern in its longer-clock form: the comment does not name the missing control by name, it names the reference implementation whose richer logic the JavaScript port never imported. The follow-up did not happen. The CVE that follows is the gap above the comment.\n\nA second TODO sits eight lines above the `RPC.decode` call in the inbound stream loop: `// TODO: Check max gossip message size, before decodeRpc()`. The check the comment names does not exist in the file. The v16.0.0 patch caps the decoder's inner-list growth and leaves the outer message-size check the comment requested for another release.\n\n## The cap is the next major\n\nPR #3520 by `tabcat`, merged on May 26, 2026 as commit `773dd80`. Title: `fix(gossipsub)!: apply decodeRpcLimits to control messages`. The exclamation mark is the conventional-commits marker for a breaking change. The full diff against `defaultDecodeRpcLimits`:\n\n```diff\n export const defaultDecodeRpcLimits: DecodeRPCLimits = {\n- maxSubscriptions: Infinity,\n- maxMessages: Infinity,\n- maxIhaveMessageIDs: Infinity,\n- maxIwantMessageIDs: Infinity,\n- maxIdontwantMessageIDs: Infinity,\n- maxControlMessages: Infinity,\n- maxPeerInfos: Infinity\n+ // 5000 = GossipsubMaxIHaveLength, used as a generous upper bound for these\n+ maxSubscriptions: 5000,\n+ maxMessages: 5000,\n+ maxIhaveMessageIDs: 5000,\n+ maxIwantMessageIDs: 5000,\n+ maxControlMessages: 5000,\n+ maxIdontwantMessageIDs: 512, // GossipsubIdontwantMaxMessages\n+ maxPeerInfos: 16 // GossipsubPrunePeers\n }\n```\n\nThe release commit `745cd9d` published this as v16.0.0 on May 27, 2026, eleven days after v15.0.23. The CHANGELOG entry reads:\n\n> ⚠ BREAKING CHANGES\n> * **gossipsub:** apply decodeRpcLimits to control messages (#3520)\n\nThe breaking-change marker is what gates whether consumers receive the cap by upgrading. A consumer who reads the GHSA advisory, sees \"patched in version 15.0.23,\" runs `npm install @libp2p/gossipsub@^15.0.0`, and lets their lockfile resolve to 15.0.23 has the leak fix. The lockfile resolver will not cross the 15 to 16 boundary on a `^15.0.0` spec. The consumer who wants the cap has to make a separate decision: read the v16 changelog, evaluate the breaking-changes scope, schedule the migration, and ship a major-version bump for a CVE the advisory said was already closed.\n\nThis is the [default-is-the-mitigation](/patterns/default-is-the-mitigation) pattern at its cleanest. The audit-readable scope of the v16.0.0 fix is one number per field. The unsafe primitive (RPC decoding without an inner-list cap) is preserved verbatim. The dangerous behavior is preserved behind a flag the caller controls through the same `decodeRpcLimits` constructor argument the consumer can choose to override. A consumer who instantiates `GossipSub` with `{ decodeRpcLimits: { maxSubscriptions: Infinity } }`, perhaps copy-pasted from an older configuration, reverts to the v15.0.22 attack surface against a v16.0.3 binary.\n\n## The 2022 feature was named `limit RPC lists on decode`\n\nThe phrase \"limit RPC lists on decode\" is the commit message for `8fbcb4c`. The phrase is also, three and a half years later, the title of PR #3520. The same feature, named the same way, shipped twice. The first shipping installed the interface and the export and set every interface field to `Infinity`. The second shipping changed the values.\n\nIn the interval, `@libp2p/gossipsub` and its predecessor `@chainsafe/libp2p-gossipsub` shipped twenty-three minor and patch releases against a `DecodeRPCLimits` object whose every field said the limit was infinite. The interface was the shape of the fix. The values were the bug.\n\nThe codebase wrote the feature's name in October 2022. The CVE that follows is what it takes to write the values in.\n\n## What the advisory says\n\nThe CVE record reads: \"This issue has been patched in version 15.0.23.\" The phrasing is the maintainer's, copied verbatim into the NVD description. By the maintainer's own narrative, three cooperating omissions cause heap exhaustion; v15.0.23 closes them; the issue is resolved.\n\nThe codebase's testimony is the other reading. Two of the three omissions are closed in v15.0.23. The third is closed in v16.0.0. The third is the one the advisory's PoC exercises end to end against a single peer. A reader who upgrades from 15.0.22 to 15.0.23 has installed a node whose `defaultDecodeRpcLimits.maxSubscriptions` is the literal value `Infinity`, and whose `handleReceivedSubscription` allocates exactly the same way the pre-patch version did during the attacker's active connection.\n\nThe patch closes this CVE. The patched version contains the unpatched primitive.\n\nPoC: [GHSA-4f8r-922h-2vgv](https://github.com/libp2p/js-libp2p/security/advisories/GHSA-4f8r-922h-2vgv)\n","closing_line":"v15.0.23 closed the leak. The default for `maxSubscriptions` stayed `Infinity`.","hook_md":"The GHSA advisory for CVE-2026-46679 names three cooperating omissions in `@libp2p/gossipsub` and says all three are patched in version 15.0.23. The May 16 commit that v15.0.23 ships fixes two of them. It prunes empty `Set`s from `this.topics` after a peer disconnects, and it stops `handleReceivedSubscription` from allocating a new `Set` for an `UNSUBSCRIBE` the sender was never subscribed to. The third omission, `defaultDecodeRpcLimits.maxSubscriptions: Infinity`, is unchanged. A single 4MB RPC against a v15.0.23 node still decodes 349,525 unique `SUBSCRIBE` entries, and the node's subscription handler still allocates a fresh `Set()` per unique topic against the connected attacker. The per-RPC cap arrives in v16.0.0, eleven days later, in a release whose changelog opens with `⚠ BREAKING CHANGES`.","post_id":658,"slug":"libp2p-gossipsub-cve-2026-46679-cap-was-the-next-major","title":"CVE-2026-46679: libp2p Gossipsub's v15.0.23 Closed The Leak. The Default For maxSubscriptions Stayed Infinity.","type":"initial","unreadable_sentence":"A feature whose entire purpose was to limit RPC decode lists shipped with every limit set to Infinity for three years and seven months, and the version the advisory says patches CVE-2026-46679 is still inside that window."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaxTDggAKCRDeZjl4jgkQ Jj6oAP0SYMuNjieA89DXGtU/Kyg0uPh5tONWVVaIaBMVLvVCwQD/fIOXFxB07acB bstmw70OjtzBO4bnqS6S7hqMrOXzZgs= =7A+O -----END PGP SIGNATURE-----