# CVE-2021-20329: Specific cstrings input may not be properly validated in the Go Driver

> A malicious user can inject additional fields into BSON documents by exploiting improper cstring validation in the MongoDB Go Driver.

- **Severity:** Medium 6.8 (`CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 10 Jun 2021
- **Updated:** 16 Sep 2024
- **Also known as:** GHSA-f6mq-5m25-4r72, GO-2021-0112

## What is CVE-2021-20329?

CVE-2021-20329 is a medium-severity vulnerability in MongoDB Go Driver, published on 10 Jun 2021. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

Specific cstrings input may not be properly validated in the MongoDB Go Driver when marshalling Go objects into BSON. A malicious user could use a Go object with specific string to potentially inject additional fields into marshalled documents. This issue affects all MongoDB GO Drivers prior to and including 1.5.0.

Weakness: CWE-20 (Improper Input Validation), CWE-1287 (Improper Validation of Specified Type of Input)

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

3 open source packages ship an affected version, including go.mongodb.org/mongo-driver. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `go.mongodb.org/mongo-driver` | Go | All versions | 1.5.1 |
| `go.mongodb.org/mongo-driver` | Go | All versions | 1.5.1 |
| `go.mongodb.org/mongo-driver` | Go | All versions | 1.5.1 |

Products: Mongodb Go Driver.

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

Upgrade go.mongodb.org/mongo-driver to 1.5.1 or later.

## Is CVE-2021-20329 being exploited?

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

## Other vulnerabilities in MongoDB Go Driver

- [CVE-2026-107324](https://insights.sbomify.com/CVE-2026-107324/): Application denial of service via integer overflow in BSON value-length validation in MongoDB Go Driver (high 8.2)
- [CVE-2026-107325](https://insights.sbomify.com/CVE-2026-107325/): Application denial of service via missing BSON array length validation in MongoDB Go Driver (high 8.2)
- [CVE-2026-81521](https://insights.sbomify.com/CVE-2026-81521/): Cross-database write retargeting via unvalidated dotted database name in Client.BulkWrite in the MongoDB Go Driver (high 7.1)
- [CVE-2026-88031](https://insights.sbomify.com/CVE-2026-88031/): GridFS data deletion via query-operator injection in file IDs in the MongoDB Go Driver (medium 6.1)

## Fix prompt for AI coding agents

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

What it is: CVE-2021-20329 is a medium-severity vulnerability in MongoDB Go Driver, published on 10 Jun 2021. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2021-20329 in the wild and no public exploit code.

Affected packages and fixed versions:
- go.mongodb.org/mongo-driver (Go): affected all versions; fixed in 1.5.1
- go.mongodb.org/mongo-driver (Go): affected all versions; fixed in 1.5.1
- go.mongodb.org/mongo-driver (Go): affected all versions; fixed in 1.5.1

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

## Sources

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

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