Skip to main content
Menu
Advisories

floodsub StrictSign verifies the signature against the untrusted message.key with no binding to message.from, allowing peer impersonation

GHSA-PXV8-J7H7-M2PJPublished Updated GitHub

Description

A floodsub peer can publish messages impersonating any Ed25519 PeerId (including peers it is not connected to) even when StrictSign is enabled, because the signature is validated against the untrusted message.key rather than the key bound to message.from.

Details

packages/floodsub/src/sign.ts messagePublicKey() (line 73) returns the peer-supplied message.key (lines 83–84) with no binding to message.from:

export function messagePublicKey (message) {
  ...
  if (message.key != null) {
    return message.key            // untrusted; never compared to message.from
  }
  if (message.from.publicKey != null) {
    return message.from.publicKey
  }
}

and verifySignature() validates the signature with that key (pubKey.verify(bytes, message.signature)). utils.ts isSigned() returns true for any inline-key (Ed25519) PeerId without checking message.key agreement, and the signed bytes deliberately exclude key/signature. gossipsub closes this exact hole at buildRawMessage.ts:143 (if (fromPeerId.publicKey !== undefined && !publicKey.equals(fromPeerId.publicKey)) return invalid); floodsub lacks the equivalent, yet index.ts advertises StrictSign as spoof-prevention. The attacker picks any victim PeerId X (it need not be online), signs the message bytes with its own private key, and attaches its own public key as message.key; the victim verifies against the attacker's key (passes), accepts the message, dispatches it with msg.from = X, then re-broadcasts it to its other subscribers. Verified on js-libp2p commit a04f5e0, where @libp2p/floodsub reads 11.0.25.

PoC

Full PoC attached (floodsub-strictsign-impersonation-poc.tar.gz). Build the js-libp2p monorepo at the affected version (npm install --ignore-scripts && npm run build), extract the package inside the monorepo root (sibling of packages/), then cd floodsub-strictsign-impersonation-poc && node attack.mjs. It sends three messages that isolate the defect — NEG (wrong sig, rejected), BYPASS (from=X, key=A, signed with A), POS (self-signed). Expected:

[*] victim dispatched messages: 2
[*]   from=12D3KooW...(X) topic=pwn data="FORGED-BY-A-as-X"
[*]   from=12D3KooW...(A) topic=pwn data="POS-self-signed"
[!] Vulnerability reproduced: StrictSign accepted a message whose declared 'from' is X — a peer the victim is NOT connected to — while the signature was made with the ATTACKER's key A
[!] evidence: NEG(wrong sig)=rejected (0 messages), BYPASS(from=X,key=A)=ACCEPTED as from=X, POS(self-signed)=accepted

A is the attacker's connection identity; X is a PeerId the victim is not connected to. The wrongly-signed NEG message is correctly rejected, proving the verify path works and the defect is specifically the missing key-to-from binding.

Impact

CWE-347/CWE-345. A floodsub peer can forge messages as any Ed25519 PeerId and have them propagated across hops (every relay re-runs the same broken verify). @libp2p/floodsub is documented "not for production / deprecated", which bounds real-world exposure, but the bypass is a concrete spec violation that index.ts still advertises as protection. Suggested fix: mirror gossipsub — in messagePublicKey/toMessage, when from has an inline public key and message.key is supplied, require publicKeyFromProtobuf(message.key).equals(from.publicKey) and reject on mismatch; or require message.key to be absent for hashed PeerIds.

floodsub-strictsign-impersonation-poc.tar.gz

Affected versions

References

GitHub · libp2p/js-libp2p