//nefariousplan

CVE-2026-45783: libp2p's verifyRecord Returned Without Verifying. The Test Suite Had A Case For It.

vendor

pattern

cve

proof of concept

libp2p's @libp2p/kad-dht ships a function named verifyRecord. Given a record whose key did not split into at least three slash-delimited parts, the pre-16.2.6 implementation returned. No error. No verdict. The comment above the return reads // No validator available. The handler that called it took the silence as success and wrote the record to the datastore. The patch that closes CVE-2026-45783 changes the return to a throw, because the handler's catch block had been wired to drop unverified records the whole time. Before this bug was a CVE, the test suite had a case asserting it as the expected behavior.

The function returned silently

packages/kad-dht/src/record/validators.ts, pre-patch:

/**
 * Checks a record and ensures it is still valid.
 * It runs the needed validators.
 * If verification fails the returned Promise will reject with the error.
 */
export async function verifyRecord (validators: Validators, record: Libp2pRecord, options?: AbortOptions): Promise<void> {
  const key = record.key
  const keyString = uint8ArrayToString(key)
  const parts = keyString.split('/')

  if (parts.length < 3) {
    // No validator available
    return
  }

  const validator = validators[parts[1].toString()]

  if (validator == null) {
    throw new InvalidParametersError(`No validator available for key type "${parts[1]}"`)
  }

  await validator(key, record.value, options)
}

Two branches report No validator available. They report it in two different code-path languages. The branch for keys with three or more namespace components throws InvalidParametersError. The branch for keys with fewer than three namespace components returns. The author named the same condition in both comments and chose to handle one of them as a failure and the other as a success.

The function is named verifyRecord. Its declared return type is Promise<void>. The JSDoc above the function reads, in full, "If verification fails the returned Promise will reject with the error." There is no third option in the contract. A verifyRecord that returns without rejecting has, by the function's own type signature, declared the record valid.

The CVE-2026-45783 reporter, @tahaafarooq, constructed the trivial bypass case in the PoC: a record whose key is the three raw bytes [0x01, 0x02, 0x03]. Decoded as UTF-8 it produces a string of length one when split on /. One part. Less than three. The silent-return branch fires. The record is stored. The advisory documents that the same shape extends to any short key the attacker chooses: a 64 KB payload under one short key per PUT_VALUE message, replayed until the disk fills.

The catch path was waiting on the verdict

packages/kad-dht/src/rpc/handlers/put-value.ts:

async handle (peerId: PeerId, msg: Message): Promise<Message> {
  const key = msg.key
  this.log('%p asked us to store value for key %b', peerId, key)

  if (msg.record == null) {
    this.log.error('empty record from %p', peerId)
    throw new InvalidMessageError(`Empty record from: ${peerId}`)
  }

  try {
    const deserializedRecord = Libp2pRecord.deserialize(msg.record)

    await verifyRecord(this.validators, deserializedRecord)

    deserializedRecord.timeReceived = new Date()
    const recordKey = bufferToRecordKey(this.datastorePrefix, deserializedRecord.key)
    await this.components.datastore.put(recordKey, deserializedRecord.serialize().subarray())

    this.log('accepted put for key %b under %k', key, recordKey)

    return msg
  } catch (err: any) {
    this.log('failed to accept put for key %b - %e', key, err)
    throw err
  }
}

The handler is structured around a single hypothesis. verifyRecord either resolves and the record is valid, or it throws and the record is invalid. If verification throws, control falls through to the catch block, which logs and re-raises. The re-raise propagates to the RPC loop in rpc/index.ts, whose own catch calls stream.abort(err) and returns from the message loop. The entire pipeline downstream of verifyRecord is structured to refuse the record on a verdict it never received.

The commit message that closes CVE-2026-45783 is the patch author's reading of this fact:

verifyRecord previously returned silently for keys with fewer than three slash-delimited parts, causing PutValueHandler to store unvalidated records. Throw InvalidParametersError instead so the handler's catch path drops the record.

"So the handler's catch path drops the record." The patch author had read the handler. They knew the catch path was already in place. They knew what an InvalidParametersError thrown out of verifyRecord would do. The patch is one line:

   if (parts.length < 3) {
-    // No validator available
-    return
+    throw new InvalidParametersError('Record key is missing a namespace')
   }

The infrastructure to refuse the record was complete. It had been complete since PutValueHandler was first written. What it required to function was a verdict on the wire from verifyRecord. The function had chosen, in one of its two failure branches, not to send one.

The test suite asserted the bug as a feature

packages/kad-dht/test/kad-dht.spec.ts, pre-patch, contained an integration test titled 'put - get using key with no prefix (no selector available)'. The test ran a two-node DHT round-trip on a record whose key was the byte string hello. One part when split on /. No namespace. The assertion at the end of the test was that the value put to one node could be retrieved from the other:

it('put - get using key with no prefix (no selector available)', async function () {
  this.timeout(10 * 1000)

  const key = uint8ArrayFromString('hello')
  const value = uint8ArrayFromString('world')

  const [dhtA, dhtB] = await Promise.all([
    testDHT.spawn(),
    testDHT.spawn()
  ])

  await testDHT.connect(dhtA, dhtB)

  await drain(dhtA.dht.put(key, value))

  const res = await last(dhtB.dht.get(key))
  expect(res).to.have.property('value').that.equalBytes(value)
})

Read the title. put - get using key with no prefix (no selector available). The parenthetical names the silent-return condition by hand. The body of the test exercises it end-to-end across two nodes. The assertion is that storing and retrieving succeeds. The patch deletes the test.

The same patch modifies the unit test 'stores the record in the datastore' in put-value.spec.ts. The pre-patch version constructed a Message whose key field was /val/hello (three parts, valid namespace) and a Libp2pRecord whose key field was hello (one part, no namespace), and then asserted that the handler stored the record under the bare hello:

 it('stores the record in the datastore', async () => {
+  const recordKey = uint8ArrayFromString('/val/hello')
   const msg: Message = {
     type: T,
-    key: uint8ArrayFromString('/val/hello'),
+    key: recordKey,
     closer: [],
     providers: []
   }
   const record = new Libp2pRecord(
-    uint8ArrayFromString('hello'),
+    recordKey,
     uint8ArrayFromString('world'),
     new Date()
   )

The pre-patch test was a specimen of the bug embedded in test infrastructure. The message advertised one key. The record carried another. The handler stored the record under the record's key, not the message's, because the silent-return branch did not care that the two disagreed. The recorded "expected" behavior, asserted on every CI run, was that a PUT_VALUE message carrying one key in its envelope and a record with a different key in its payload would land in the datastore under the payload's key. The post-patch test uses the same key for both. The handler stores it. The test passes. The test is now what the function name claimed all along.

The unit tests for verifyRecord itself covered two cases prior to the patch: 'calls matching validator' (3-part key, validator registered, runs it) and 'calls not matching any validator' (3-part key, no validator registered, throws). The branch the patch closes, fewer than three parts, was not under test. The author wrote a test for the no-validator-registered case. They did not write a test for the no-namespace-at-all case, because in their model of the function those were the same case, except the function had reported them differently and they had named one of those reports as expected.

The patch deletes one integration test, modifies one unit test that the bug was hiding inside, and adds one unit test that asserts the new throw. Three test changes for a one-line code change.

The unbounded loop stays

The CVE-2026-45783 advisory describes the vulnerability as the composition of two defects: "silent validation bypass for keys with fewer than 3 slash-delimited parts, and an unbounded RPC message loop with no per-stream message limits or rate limiting." The patch closes the first defect. The second is structural.

packages/kad-dht/src/rpc/index.ts, onIncomingStream, unchanged by the patch:

while (true) {
  // the remote will not send any more data
  if (stream.readStatus !== 'readable') {
    await stream.close({ signal })
    break
  }

  const message = await messages.read({ signal })

  // ... handleMessage(connection.remotePeer, message) ...

  // we have received a message so reset the timeout controller to
  // allow the remote to send another
  signal.removeEventListener('abort', abortListener)
  signal = AbortSignal.timeout(this.incomingMessageTimeout)
  signal.addEventListener('abort', abortListener)
}

while (true). Per-stream message count, unbounded. Per-peer write budget, absent. Each successful handler dispatch resets the abort signal to a fresh ten-second timeout, so as long as the attacker sends a message every nine seconds, the stream stays open indefinitely. The post-patch code accepts any record whose key has three or more namespace components and a registered validator that accepts the contents.

The pk validator that ships with @libp2p/kad-dht is satisfied by any record whose key is /pk/<multihash> and whose value is the public key whose multihash the suffix is. An attacker who generates one Ed25519 keypair per record can produce arbitrarily many such records, each as valid as the last, and pipe them down a single stream. The cost is the keygen per record on the attacker's side. The disk usage is the record size per record on the victim's side. The structural disk-fill primitive is the design of the protocol: a public DHT in server mode that accepts writes from unauthenticated peers exists to accept writes from unauthenticated peers.

The patch closes the unauthenticated disk-fill via invalid records. The unauthenticated disk-fill via valid records is what the component does. The advisory grouped the two defects in one CVE because together they produced the same outcome under the smallest attacker effort. The patch closes the easy one.

What this is an instance of

The shape this names is the fail-open-intercept pattern. A security gate, designed to reject, given an input it cannot evaluate, forwards. The dialect changes with the language: Java's try { gate(); } catch (SecurityException) { log; } super.forward(msg);, PHP's header('Location: /login'); without exit;, Go's defer recover() over a panicked verifier that returns nil, JavaScript's if (e instanceof JWTError) { return; } next();. verifyRecord writes the dialect on one return statement. The function is declared to reject on failure. One of its two failure branches reports the failure by returning. The reporter is the listener. The listener does not hear itself.

Sixteen prior posts in our catalog name this exact pattern. The Tomcat exhibit (CVE-2026-34486: EncryptInterceptor Only Encrypts Messages That Survive Decryption) catches GeneralSecurityException and calls super.messageReceived(msg) outside the try. The Xerte exhibit (CVE-2026-34413) issues a 302 redirect without calling exit. The Burst Statistics exhibit tests is_wp_error() on a function whose null return is neither success nor WP_Error. CVE-2026-45783 is the exhibit where the gate's silence was so close to a verdict that the patch is one line: change the silence to a throw and the catch path downstream catches it.

PoC: advisories/GHSA-32mq-hpph-xfvr

The patch is a one-line code change. The three test changes around it are the record of how the bug got in.