# CVE-2023-34450: CometBFT PeerState JSON serialization deadlock

> A deadlock in CometBFT's JSON serialization can halt nodes or block peer communication, requiring debug logging or RPC access to trigger.

- **Severity:** Low 3.7 (`CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 3 Jul 2023
- **Updated:** 29 Oct 2024
- **Also known as:** GHSA-mvj3-qrqh-cjvr, GO-2023-1882

## What is CVE-2023-34450?

CVE-2023-34450 is a low-severity denial of service vulnerability in cometbft, published on 3 Jul 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

CometBFT is a Byzantine Fault Tolerant (BFT) middleware that takes a state transition machine and replicates it on many machines. An internal modification made in versions 0.34.28 and 0.37.1 to the way struct `PeerState` is serialized to JSON introduced a deadlock when new function MarshallJSON is called. This function can be called from two places. The first is via logs, setting the `consensus` logging module to "debug" level (should not happen in production), and setting the log output format to JSON. The second is via RPC `dump_consensus_state`.

Case 1, which should not be hit in production, will eventually hit the deadlock in most goroutines, effectively halting the node.

In case 2, only the data structures related to the first peer will be deadlocked, together with the thread(s) dealing with the RPC request(s). This means that only one of the channels of communication to the node's peers will be blocked. Eventually the peer will timeout and excluded from the list (typically after 2 minutes). The goroutines involved in the deadlock will not be garbage collected, but they will not interfere with the system after the peer is excluded.

The theoretical worst case for case 2, is a network with only two validator nodes. In this case, each of the nodes only has one `PeerState` struct. If `dump_consensus_state` is called in either node (or both), the chain will halt until the peer connections time out, after which the nodes will reconnect (with different `PeerState` structs) and the chain will progress again. Then, the same process can be repeated.

As the number of nodes in a network increases, and thus, the number of peer struct each node maintains, the possibility of reproducing the perturbation visible with two nodes decreases. Only the first `PeerState` struct will deadlock, and not the others (RPC `dump_consensus_state` accesses them in a for loop, so the deadlock at the first iteration causes the rest of the iterations of that "for" loop to never be reached).

This regression was fixed in versions 0.34.29 and 0.37.2. Some workarounds are available. For case 1 (hitting the deadlock via logs), either don't set the log output to "json", leave at "plain", or don't set the consensus logging module to "debug", leave it at "info" or higher. For case 2 (hitting the deadlock via RPC `dump_consensus_state`), do not expose `dump_consensus_state` RPC endpoint to the public internet (e.g., via rules in one's nginx setup).

Weakness: CWE-770 (Allocation of Resources Without Limits or Throttling), CWE-401 (Missing Release of Memory after Effective Lifetime)

## Which versions are affected by CVE-2023-34450?

5 open source packages ship an affected version, including github.com/cometbft/cometbft. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/cometbft/cometbft` | Go | From 0.34.28 | 0.34.29 |
| `github.com/cometbft/cometbft` | Go | From 0.34.28 | 0.34.29 |
| `github.com/cometbft/cometbft` | Go | From 0.37.1 | 0.37.2 |
| `github.com/cometbft/cometbft` | Go | From 0.37.1 | 0.37.2 |
| `github.com/cometbft/cometbft` | Go | From 0.37.1 | 0.37.2 |

Products: Cometbft Cometbft.

## How do I fix CVE-2023-34450?

Upgrade github.com/cometbft/cometbft to a fixed version for your release line: 0.34.29 or 0.37.2.

## Is CVE-2023-34450 being exploited?

There is no known exploitation of CVE-2023-34450 in the wild and no public exploit code.

## Other vulnerabilities in cometbft

- [CVE-2023-34451](https://insights.sbomify.com/CVE-2023-34451/): CometBFT may duplicate transactions in the mempool's data structures (high 8.2)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2023-34450 and fix it if it is affected.

What it is: CVE-2023-34450 is a low-severity denial of service vulnerability in cometbft, published on 3 Jul 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2023-34450 in the wild and no public exploit code.

Affected packages and fixed versions:
- github.com/cometbft/cometbft (Go): affected from 0.34.28; fixed in 0.34.29
- github.com/cometbft/cometbft (Go): affected from 0.34.28; fixed in 0.34.29
- github.com/cometbft/cometbft (Go): affected from 0.37.1; fixed in 0.37.2
- github.com/cometbft/cometbft (Go): affected from 0.37.1; fixed in 0.37.2
- github.com/cometbft/cometbft (Go): affected from 0.37.1; fixed in 0.37.2

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2023-34450/ (Markdown: https://insights.sbomify.com/CVE-2023-34450/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2023-34450
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2023-34450
- OSV: https://osv.dev/vulnerability/CVE-2023-34450

---
From sbomify Insights: https://insights.sbomify.com/CVE-2023-34450/
Summaries are generated and may contain mistakes; the official description above is the record.
