java-topology/whitepaper/outreach/go-libp2p-0002.md
russell@unturf.com 652608142a feat: close outreach doc gap — 276 docs (batches 11-16)
All projects with patches now have outreach docs. 276 new docs covering
CWE-407, CWE-312, CWE-362 across C, C++, Java, Python, Go, Rust, C#,
PHP, Ruby, JavaScript, Dart, Erlang, R, and more.

Outreach gap: 276 -> 0.
2026-04-15 13:57:42 -04:00

2.2 KiB
Raw Blame History

go-libp2p — CWE-407 Disclosure Brief (go-libp2p-0002)

2026-04-13 · Patch available — awaiting upstream merge

Finding

One O(n²) defect in go-libp2p's noise transport muxer negotiation. The matchMuxers() function in p2p/security/noise/transport.go uses slices.Contains() to find the first common muxer between initiator and responder lists.

The Defect

go-libp2p-0002 (PATCHED — LOW): p2p/security/noise/transport.go in matchMuxers()

func matchMuxers(initiatorMuxers, responderMuxers []protocol.ID) protocol.ID {
    for _, initMuxer := range initiatorMuxers {
        if slices.Contains(responderMuxers, initMuxer) {  // O(R) per iteration
            return initMuxer
        }
    }
    return ""
}

For I initiator muxers and R responder muxers, the worst-case cost (no match found) is O(I*R).

Complexity Proof

At I=10, R=10 muxers:

  • Defective: 10 × 10 = 100 comparisons (worst case)
  • Fixed: 10 map build + 10 lookups = 20 operations
  • ~5× op reduction. Fires on every noise handshake.

Impact

go-libp2p's noise transport handles encrypted connections for IPFS, Filecoin, and many other P2P networks. Muxer negotiation fires on every connection establishment. While muxer lists are currently small, the fix eliminates unnecessary quadratic scaling.

The Fix

Build a map[protocol.ID]struct{} from responder muxers, then iterate initiator muxers with O(1) lookup:

// After
respSet := make(map[protocol.ID]struct{}, len(responderMuxers))
for _, m := range responderMuxers { respSet[m] = struct{}{} }
for _, initMuxer := range initiatorMuxers {
    if _, ok := respSet[initMuxer]; ok { return initMuxer }
}

Patch

Fix available: defects/go-libp2p-0002/patch/go-libp2p-0002.patch

Single-file patch in p2p/security/noise/transport.go. ~5× speedup at 10 muxers.

What We Ask

A patch is ready for review.

  1. Confirm receipt and assign a GitHub issue reference (libp2p/go-libp2p).
  2. Assess severity — fires on every noise handshake.
  3. Coordinate a disclosure date — we are targeting 90 days from first contact.
  4. We will credit the libp2p team in the public disclosure. Preferred acknowledgment format welcome.

Contact: see cover email. This brief is confidential until coordinated disclosure.