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 Sets 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.
CVE-2026-46679: libp2p Gossipsub's v15.0.23 Closed The Leak. The Default For maxSubscriptions Stayed Infinity.
vendor
patterns
cve
proof of concept
The patched version still ships maxSubscriptions: Infinity
The 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:
export interface DecodeRPCLimits {
maxSubscriptions: number
maxMessages: number
maxIhaveMessageIDs: number
maxIwantMessageIDs: number
maxIdontwantMessageIDs: number
maxControlMessages: number
maxPeerInfos: number
}
export const defaultDecodeRpcLimits: DecodeRPCLimits = {
maxSubscriptions: Infinity,
maxMessages: Infinity,
maxIhaveMessageIDs: Infinity,
maxIwantMessageIDs: Infinity,
maxIdontwantMessageIDs: Infinity,
maxControlMessages: Infinity,
maxPeerInfos: Infinity
}The 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.
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:
const rpc = RPC.decode(rpcBytes, {
limits: {
subscriptions: this.decodeRpcLimits.maxSubscriptions,
messages: this.decodeRpcLimits.maxMessages,
control$: {
ihave: this.decodeRpcLimits.maxIhaveMessageIDs,
iwant: this.decodeRpcLimits.maxIwantMessageIDs,
...
}
}
})A 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.
What v15.0.23 actually patched
PR #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.
removePeer, the disconnect cleanup path, lines 779 through 786:
// remove peer from topics map
- for (const peers of this.topics.values()) {
+ for (const [topic, peers] of this.topics) {
peers.delete(id)
+ if (peers.size === 0) {
+ this.topics.delete(topic)
+ }
}handleReceivedSubscription, the subscription-update path, lines 1007 through 1024:
let topicSet = this.topics.get(topic)
- if (topicSet == null) {
- topicSet = new Set()
- this.topics.set(topic, topicSet)
- }
if (subscribe) {
+ if (topicSet == null) {
+ topicSet = new Set()
+ this.topics.set(topic, topicSet)
+ }
+
// subscribe peer to new topic
topicSet.add(from.toString())
- } else {
+ } else if (topicSet != null) {
// unsubscribe from existing topic
topicSet.delete(from.toString())
+ if (topicSet.size === 0) {
+ this.topics.delete(topic)
+ }
}stop, the lifecycle reset, line 577:
this.peers.clear()
this.subscriptions.clear()
+ this.topics.clear()Three 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.
All 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.
The PoC targets the branch v15.0.23 did not touch
The 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 Sets remain in this.topics after removePeer.
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:
/**
* Handles a subscription change from a peer
*/
private handleReceivedSubscription (from: PeerId, topic: TopicStr, subscribe: boolean): void {
this.log('subscription update from %p topic %s', from, topic)
let topicSet = this.topics.get(topic)
if (subscribe) {
if (topicSet == null) {
topicSet = new Set()
this.topics.set(topic, topicSet)
}
// subscribe peer to new topic
topicSet.add(from.toString())
} else if (topicSet != null) {
// unsubscribe from existing topic
topicSet.delete(from.toString())
if (topicSet.size === 0) {
this.topics.delete(topic)
}
}
// TODO: rust-libp2p has A LOT more logic here
}The 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.
The 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.
A 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 Sets. The crash arrives before the cleanup runs.
The 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 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.
A 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.
The cap is the next major
PR #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:
export const defaultDecodeRpcLimits: DecodeRPCLimits = {
- maxSubscriptions: Infinity,
- maxMessages: Infinity,
- maxIhaveMessageIDs: Infinity,
- maxIwantMessageIDs: Infinity,
- maxIdontwantMessageIDs: Infinity,
- maxControlMessages: Infinity,
- maxPeerInfos: Infinity
+ // 5000 = GossipsubMaxIHaveLength, used as a generous upper bound for these
+ maxSubscriptions: 5000,
+ maxMessages: 5000,
+ maxIhaveMessageIDs: 5000,
+ maxIwantMessageIDs: 5000,
+ maxControlMessages: 5000,
+ maxIdontwantMessageIDs: 512, // GossipsubIdontwantMaxMessages
+ maxPeerInfos: 16 // GossipsubPrunePeers
}The release commit 745cd9d published this as v16.0.0 on May 27, 2026, eleven days after v15.0.23. The CHANGELOG entry reads:
⚠ BREAKING CHANGES
- gossipsub: apply decodeRpcLimits to control messages (#3520)
The 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.
This is the 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.
The 2022 feature was named limit RPC lists on decode
The 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.
In 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.
The codebase wrote the feature's name in October 2022. The CVE that follows is what it takes to write the values in.
What the advisory says
The 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.
The 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.
The patch closes this CVE. The patched version contains the unpatched primitive.
PoC: GHSA-4f8r-922h-2vgv
v15.0.23 closed the leak. The default for maxSubscriptions stayed Infinity.