-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The function returned silently\n\n`packages/kad-dht/src/record/validators.ts`, pre-patch:\n\n```ts\n/**\n * Checks a record and ensures it is still valid.\n * It runs the needed validators.\n * If verification fails the returned Promise will reject with the error.\n */\nexport async function verifyRecord (validators: Validators, record: Libp2pRecord, options?: AbortOptions): Promise {\n const key = record.key\n const keyString = uint8ArrayToString(key)\n const parts = keyString.split('/')\n\n if (parts.length < 3) {\n // No validator available\n return\n }\n\n const validator = validators[parts[1].toString()]\n\n if (validator == null) {\n throw new InvalidParametersError(`No validator available for key type \"${parts[1]}\"`)\n }\n\n await validator(key, record.value, options)\n}\n```\n\nTwo 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.\n\nThe function is named `verifyRecord`. Its declared return type is `Promise`. 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.\n\nThe CVE-2026-45783 reporter, [@tahaafarooq](https://github.com/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.\n\n## The catch path was waiting on the verdict\n\n`packages/kad-dht/src/rpc/handlers/put-value.ts`:\n\n```ts\nasync handle (peerId: PeerId, msg: Message): Promise {\n const key = msg.key\n this.log('%p asked us to store value for key %b', peerId, key)\n\n if (msg.record == null) {\n this.log.error('empty record from %p', peerId)\n throw new InvalidMessageError(`Empty record from: ${peerId}`)\n }\n\n try {\n const deserializedRecord = Libp2pRecord.deserialize(msg.record)\n\n await verifyRecord(this.validators, deserializedRecord)\n\n deserializedRecord.timeReceived = new Date()\n const recordKey = bufferToRecordKey(this.datastorePrefix, deserializedRecord.key)\n await this.components.datastore.put(recordKey, deserializedRecord.serialize().subarray())\n\n this.log('accepted put for key %b under %k', key, recordKey)\n\n return msg\n } catch (err: any) {\n this.log('failed to accept put for key %b - %e', key, err)\n throw err\n }\n}\n```\n\nThe 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.\n\nThe commit message that closes CVE-2026-45783 is the patch author's reading of this fact:\n\n> 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.\n\n\"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:\n\n```diff\n if (parts.length < 3) {\n- // No validator available\n- return\n+ throw new InvalidParametersError('Record key is missing a namespace')\n }\n```\n\nThe 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.\n\n## The test suite asserted the bug as a feature\n\n`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:\n\n```ts\nit('put - get using key with no prefix (no selector available)', async function () {\n this.timeout(10 * 1000)\n\n const key = uint8ArrayFromString('hello')\n const value = uint8ArrayFromString('world')\n\n const [dhtA, dhtB] = await Promise.all([\n testDHT.spawn(),\n testDHT.spawn()\n ])\n\n await testDHT.connect(dhtA, dhtB)\n\n await drain(dhtA.dht.put(key, value))\n\n const res = await last(dhtB.dht.get(key))\n expect(res).to.have.property('value').that.equalBytes(value)\n})\n```\n\nRead 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.\n\nThe 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`:\n\n```diff\n it('stores the record in the datastore', async () => {\n+ const recordKey = uint8ArrayFromString('/val/hello')\n const msg: Message = {\n type: T,\n- key: uint8ArrayFromString('/val/hello'),\n+ key: recordKey,\n closer: [],\n providers: []\n }\n const record = new Libp2pRecord(\n- uint8ArrayFromString('hello'),\n+ recordKey,\n uint8ArrayFromString('world'),\n new Date()\n )\n```\n\nThe 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.\n\nThe 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.\n\nThe 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.\n\n## The unbounded loop stays\n\nThe 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.\n\n`packages/kad-dht/src/rpc/index.ts`, `onIncomingStream`, unchanged by the patch:\n\n```ts\nwhile (true) {\n // the remote will not send any more data\n if (stream.readStatus !== 'readable') {\n await stream.close({ signal })\n break\n }\n\n const message = await messages.read({ signal })\n\n // ... handleMessage(connection.remotePeer, message) ...\n\n // we have received a message so reset the timeout controller to\n // allow the remote to send another\n signal.removeEventListener('abort', abortListener)\n signal = AbortSignal.timeout(this.incomingMessageTimeout)\n signal.addEventListener('abort', abortListener)\n}\n```\n\n`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.\n\nThe `pk` validator that ships with `@libp2p/kad-dht` is satisfied by any record whose key is `/pk/` 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.\n\nThe 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.\n\n## What this is an instance of\n\nThe 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.\n\nSixteen prior posts in our catalog name this exact pattern. The Tomcat exhibit ([CVE-2026-34486: EncryptInterceptor Only Encrypts Messages That Survive Decryption](/posts/tomcat-encryptinterceptor-fails-open)) catches `GeneralSecurityException` and calls `super.messageReceived(msg)` outside the try. The Xerte exhibit ([CVE-2026-34413](/posts/xerte-cve-2026-34413-redirect-without-exit)) 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.\n\nPoC: [advisories/GHSA-32mq-hpph-xfvr](https://github.com/advisories/GHSA-32mq-hpph-xfvr)\n","closing_line":"The patch is a one-line code change. The three test changes around it are the record of how the bug got in.","hook_md":"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.","post_id":657,"slug":"libp2p-cve-2026-45783-verifyrecord-returned-without-verifying","title":"CVE-2026-45783: libp2p's verifyRecord Returned Without Verifying. The Test Suite Had A Case For It.","type":"initial","unreadable_sentence":"Before this bug was a CVE, the test suite had a case asserting it as the expected behavior."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaxRSygAKCRDeZjl4jgkQ JjQ0AQDZHfJSsXab/W3PGiw0TjEJ/0Te5Zuh7vxUdqzOgChdBgEAs849wyMALpgd hLY5uIiJSjwZauer8I+RfaVn+jt4WAQ= =IDWI -----END PGP SIGNATURE-----