# CVE-2023-34040: Java Deserialization vulnerability in Spring-Kafka When Improperly Configured

> Attackers can execute arbitrary code via malicious serialized objects in Kafka headers if specific non-default deserialization settings are enabled.

- **Severity:** Medium 5.3 (`CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Local or same network only
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 24 Aug 2023
- **Updated:** 1 Oct 2024
- **Also known as:** GHSA-crqf-q9fp-hwjw

## What is CVE-2023-34040?

CVE-2023-34040 is a medium-severity unsafe deserialization vulnerability in Spring For Apache Kafka, published on 24 Aug 2023. It can only be exploited from the same machine or local network, with no action from the victim.

### Official description

In Spring for Apache Kafka 3.0.9 and earlier and versions 2.9.10 and earlier, a possible deserialization attack vector existed, but only if unusual configuration was applied. An attacker would have to construct a malicious serialized object in one of the deserialization exception record headers.

Specifically, an application is vulnerable when all of the following are true:

  *  The user does not configure an ErrorHandlingDeserializer for the key and/or value of the record
  *  The user explicitly sets container properties checkDeserExWhenKeyNull and/or checkDeserExWhenValueNull container properties to true.
  *  The user allows untrusted sources to publish to a Kafka topic

By default, these properties are false, and the container only attempts to deserialize the headers if an ErrorHandlingDeserializer is configured. The ErrorHandlingDeserializer prevents the vulnerability by removing any such malicious headers before processing the record.

Weakness: CWE-502 (Deserialization of Untrusted Data)

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

4 open source packages ship an affected version, including org.springframework.kafka:spring-kafka. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `org.springframework.kafka:spring-kafka` | Maven | From 2.8.1 | 2.9.11 |
| `org.springframework.kafka:spring-kafka` | Maven | From 2.8.1 | 2.9.11 |
| `org.springframework.kafka:spring-kafka` | Maven | From 3.0.0 | 3.0.10 |
| `org.springframework.kafka:spring-kafka` | Maven | From 3.0.0 | 3.0.10 |

Products: Vmware Spring for Apache Kafka.

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

Upgrade org.springframework.kafka:spring-kafka to a fixed version for your release line: 2.9.11 or 3.0.10.

## Is CVE-2023-34040 being exploited?

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

Public exploit code:

- POC for Spring Kafka Deserialization Vulnerability CVE-2023-34040 (github_poc): https://github.com/Contrast-Security-OSS/Spring-Kafka-POC-CVE-2023-34040
- Spring-Kafka-Deserialization-Remote-Code-Execution (github_poc): https://github.com/pyn3rd/CVE-2023-34040
- https://github.com/huyennhat-dev/cve-2023-34040 (github_poc): https://github.com/huyennhat-dev/cve-2023-34040
- In Spring for Apache Kafka 3.0.9 and earlier and versions 2.9.10 and earlier, a possible deserialization attack vector existed, but only if unusual configuration was applied. An attacker would have to construct a malicious serialized object in one of the deserialization exception record headers. Cre: NVD (github_poc): https://github.com/buiduchoang24/CVE-2023-34040

## Other vulnerabilities in Spring For Apache Kafka

- [CVE-2026-59278](https://insights.sbomify.com/CVE-2026-59278/): Server-side request forgery in Spring for Apache Kafka (medium 6.5)
- [CVE-2026-59317](https://insights.sbomify.com/CVE-2026-59317/): Denial of service in Spring for Apache Kafka (medium 6.5)
- [CVE-2026-41726](https://insights.sbomify.com/CVE-2026-41726/): In Spring for Apache Kafka, unbounded delegate cache keyed on user-controlled, potentially malicious selector header (medium 6.5)
- [CVE-2026-41727](https://insights.sbomify.com/CVE-2026-41727/): In Spring for Apache Kafka, forged retry topic headers subvert retry routing and backoff behavior (medium 6.5)

## Fix prompt for AI coding agents

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

What it is: CVE-2023-34040 is a medium-severity unsafe deserialization vulnerability in Spring For Apache Kafka, published on 24 Aug 2023. It can only be exploited from the same machine or local network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2023-34040 in the wild and no public exploit code.

Affected packages and fixed versions:
- org.springframework.kafka:spring-kafka (Maven): affected from 2.8.1; fixed in 2.9.11
- org.springframework.kafka:spring-kafka (Maven): affected from 2.8.1; fixed in 2.9.11
- org.springframework.kafka:spring-kafka (Maven): affected from 3.0.0; fixed in 3.0.10
- org.springframework.kafka:spring-kafka (Maven): affected from 3.0.0; fixed in 3.0.10

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-34040/ (Markdown: https://insights.sbomify.com/CVE-2023-34040/index.md)
```

## Sources

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

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