# libp2p: ASN.1 DER decoder drives an unbounded synchronous loop on attacker-controlled length fields, stalling the Node event loop pre-auth

Crafted 15-byte Identify publicKey with oversized DER length field makes js-libp2p's synchronous DER decoder loop past buffer end, stalling the event loop ~4-5s pre-auth.

- Payout: Research
- Severity: high
- Program: js-libp2p
- Found by: X1AOxiang
- Disclosed: 2026-11-17
- CVE: CVE-2026-110789
- Write-up quality: 8/10
- Original: https://github.com/advisories/GHSA-rvfr-cqwq-rc4j
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-rvfr-cqwq-rc4j
- Tags: area:oss domain:network domain:oss impact:dos kind:research platform:ghsa sev:high tech:nodejs technique:chained technique:source-review vuln:dos

**Target:** libp2p Identify protocol / @libp2p/crypto ASN.1 DER decoder
**Root cause:** readLength() parses DER long-form lengths without comparing to buf.byteLength, and readInteger() loops to context.offset+length pushing undefined past the buffer end; the blob is parsed in Identify before the remotePeer.equals check, and the MAX_RSA_JWK_SIZE guard only bounds total blob size, not the inner length field.
**Steps:**
1. Build js-libp2p monorepo at affected version (`npm install --ignore-scripts && npm run build`)
2. Extract PoC package as sibling of `packages/`, run `cd libp2p-crypto-der-eventloop-dos-poc && node attack.mjs`
3. Attacker sends ~15-byte crafted `publicKey` in an Identify message on `connection:open`
4. Victim's `publicKeyFromProtobuf` calls DER `readLength`/`readInteger`, which loops over attacker-claimed length (up to 2^64) past buf.byteLength
5. Observe victim event-loop stall ~4-5s and ~1980 MB peak RSS per connection; repeat by reconnecting
**How found:** Code review of the DER decoder: noticed readLength returns attacker-controlled length with no byteLength comparison, and readInteger loops to offset+length; traced the call path to Identify's pre-auth publicKeyFromProtobuf before the peer-id equality check, and confirmed MAX_RSA_JWK_SIZE only caps total blob size.
**Exploitation:** Any peer opening a connection to a node running default Identify sends a malformed publicKey; Identify parses it pre-auth in a single synchronous tick, blocking all timers/heartbeats/timeouts for ~4-5s and transiently allocating ~2 GB. The DER RangeError is swallowed by Identify's `.catch(() => {})`, so the node survives and each new connection re-stalls it; under a container memory limit the spike OOM-kills the process.
**Escalation:** Reconnecting repeatedly adds multi-second stalls; memory-constrained deployments get OOM-killed by the ~2 GB transient allocation.
**Insight:** In pre-auth parsers, check whether size guards bound the outer blob or the inner length fields — a tiny blob with a huge claimed inner length defeats total-size caps; also check whether the parse runs synchronously so timeouts/AbortSignals cannot interrupt it.

## Proof of concept (copied exactly from the original report)

**Vulnerable readInteger loop over attacker length**

```
function readInteger (buf, context) {
  const length = readLength(buf, context)   // attacker-controlled, claims up to 2^64
  const end = context.offset + length
  for (let i = context.offset; i < end; i++) // runs far past buf.byteLength
    vals.push(buf[i])                         // pushes `undefined` past the end
```

**PoC run command and expected output**

```
cd libp2p-crypto-der-eventloop-dos-poc && node attack.mjs`. Expected:

[*] round 1: payload sent=true, victim event-loop stall = 4s, peak RSS ~1980 MB
[*] round 2: payload sent=true, victim event-loop stall = 4-5s, peak RSS ~1980 MB
[*] round 3: payload sent=true, victim event-loop stall = 4s, peak RSS ~1980 MB
[!] Vulnerability reproduced: 3/3 connections each stalled the victim's event loop for ~4-5s — one crafted ~15-byte Identify publicKey per connection, pre-auth
```

