# CVE-2021-20328: MongoDB Java driver client-side field level encryption not verifying KMS host name

> Attackers with privileged network position can intercept traffic and bypass field-level encryption in MongoDB Java drivers due to missing KMS host name verification.

- **Severity:** Medium 6.4 (`CVSS:3.1/AV:A/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Local or same network only
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 25 Feb 2021
- **Updated:** 16 Sep 2024
- **Also known as:** GHSA-rghw-6px2-fgwc, UBUNTU-CVE-2021-20328

## What is CVE-2021-20328?

CVE-2021-20328 is a medium-severity vulnerability in MongoDB Inc. mongo-java-driver, published on 25 Feb 2021. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.

### Official description

Specific versions of the Java driver that support client-side field level encryption (CSFLE) fail to perform correct host name verification on the KMS server’s certificate. This vulnerability in combination with a privileged network position active MITM attack could result in interception of traffic between the Java driver and the KMS service rendering Field Level Encryption ineffective. This issue was discovered during internal testing and affects all versions of the Java driver that support CSFLE. The Java async, Scala, and reactive streams drivers are not impacted. This vulnerability does not impact driver traffic payloads with CSFLE-supported key services originating from applications residing inside the AWS, GCP, and Azure network fabrics due to compensating controls in these environments. This issue does not impact driver workloads that don’t use Field Level Encryption.

Weakness: CWE-295 (Improper Certificate Validation)

## Which versions are affected by CVE-2021-20328?

28 open source packages ship an affected version, including org.mongodb:mongo-java-driver, org.mongodb:mongodb-driver and org.mongodb:mongodb-driver-legacy. It affects 2 products.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `org.mongodb:mongo-java-driver` | Maven | From 3.11.0 | 3.11.3 |
| `org.mongodb:mongo-java-driver` | Maven | From 3.11.0 | 3.11.3 |
| `org.mongodb:mongo-java-driver` | Maven | From 3.12.0 | 3.12.8 |
| `org.mongodb:mongo-java-driver` | Maven | From 3.12.0 | 3.12.8 |
| `org.mongodb:mongodb-driver` | Maven | From 3.11.0 | 3.11.3 |
| `org.mongodb:mongodb-driver` | Maven | From 3.11.0 | 3.11.3 |
| `org.mongodb:mongodb-driver` | Maven | From 3.12.0 | 3.12.8 |
| `org.mongodb:mongodb-driver` | Maven | From 3.12.0 | 3.12.8 |
| `org.mongodb:mongodb-driver-legacy` | Maven | From 3.11.0 | 3.11.3 |
| `org.mongodb:mongodb-driver-legacy` | Maven | From 3.11.0 | 3.11.3 |
| `org.mongodb:mongodb-driver-legacy` | Maven | From 3.12.0 | 3.12.8 |
| `org.mongodb:mongodb-driver-legacy` | Maven | From 3.12.0 | 3.12.8 |
| `org.mongodb:mongodb-driver-legacy` | Maven | From 4.0.0 | 4.0.6 |
| `org.mongodb:mongodb-driver-legacy` | Maven | From 4.0.0 | 4.0.6 |
| `org.mongodb:mongodb-driver-legacy` | Maven | From 4.1.0 | 4.1.2 |
| `org.mongodb:mongodb-driver-legacy` | Maven | From 4.1.0 | 4.1.2 |
| `org.mongodb:mongodb-driver-legacy` | Maven | From 4.2.0 | 4.2.1 |
| `org.mongodb:mongodb-driver-legacy` | Maven | From 4.2.0 | 4.2.1 |
| `org.mongodb:mongodb-driver-sync` | Maven | From 3.11.0 | 3.11.3 |
| `org.mongodb:mongodb-driver-sync` | Maven | From 3.11.0 | 3.11.3 |
| `org.mongodb:mongodb-driver-sync` | Maven | From 3.12.0 | 3.12.8 |
| `org.mongodb:mongodb-driver-sync` | Maven | From 3.12.0 | 3.12.8 |
| `org.mongodb:mongodb-driver-sync` | Maven | From 4.0.0 | 4.0.6 |
| `org.mongodb:mongodb-driver-sync` | Maven | From 4.0.0 | 4.0.6 |
| `org.mongodb:mongodb-driver-sync` | Maven | From 4.1.0 | 4.1.2 |
| `org.mongodb:mongodb-driver-sync` | Maven | From 4.1.0 | 4.1.2 |
| `org.mongodb:mongodb-driver-sync` | Maven | From 4.2.0 | 4.2.1 |
| `org.mongodb:mongodb-driver-sync` | Maven | From 4.2.0 | 4.2.1 |

Products: Mongodb Java Driver, Quarkus Quarkus.

## How do I fix CVE-2021-20328?

Upgrade org.mongodb:mongo-java-driver to a fixed version for your release line: 3.11.3 or 3.12.8.

## Is CVE-2021-20328 being exploited?

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

## Other vulnerabilities in MongoDB Inc. mongo-java-driver

- [CVE-2026-88032](https://insights.sbomify.com/CVE-2026-88032/): Application denial of service via cancellation race in reactive client-side encryption in MongoDB Java Driver (high 8.2)
- [CVE-2026-18710](https://insights.sbomify.com/CVE-2026-18710/): Cleartext Storage of Sensitive Information in MongoDB Driver Logging During Client Initialization (high 8.2)
- [CVE-2026-88033](https://insights.sbomify.com/CVE-2026-88033/): GridFS data disclosure and deletion via query-operator injection in file IDs in the MongoDB Java Driver (medium 6.1)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2021-20328 and fix it if it is affected.

What it is: CVE-2021-20328 is a medium-severity vulnerability in MongoDB Inc. mongo-java-driver, published on 25 Feb 2021. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of CVE-2021-20328 in the wild and no public exploit code.

Affected packages and fixed versions:
- org.mongodb:mongo-java-driver (Maven): affected from 3.11.0; fixed in 3.11.3
- org.mongodb:mongo-java-driver (Maven): affected from 3.11.0; fixed in 3.11.3
- org.mongodb:mongo-java-driver (Maven): affected from 3.12.0; fixed in 3.12.8
- org.mongodb:mongo-java-driver (Maven): affected from 3.12.0; fixed in 3.12.8
- org.mongodb:mongodb-driver (Maven): affected from 3.11.0; fixed in 3.11.3
- org.mongodb:mongodb-driver (Maven): affected from 3.11.0; fixed in 3.11.3
- org.mongodb:mongodb-driver (Maven): affected from 3.12.0; fixed in 3.12.8
- org.mongodb:mongodb-driver (Maven): affected from 3.12.0; fixed in 3.12.8
- org.mongodb:mongodb-driver-legacy (Maven): affected from 3.11.0; fixed in 3.11.3
- org.mongodb:mongodb-driver-legacy (Maven): affected from 3.11.0; fixed in 3.11.3
- org.mongodb:mongodb-driver-legacy (Maven): affected from 3.12.0; fixed in 3.12.8
- org.mongodb:mongodb-driver-legacy (Maven): affected from 3.12.0; fixed in 3.12.8

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

## Sources

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

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