CVE-2021-20329: Go.mongodb.org/mongo driver Go.mongodb.org/mongo-driver Improperly Validates Cstrings When Vulnerability

MODERATE
Advisory Identifier: GHSA-f6mq-5m25-4r72
CVSS 6.8
CWE-1287 CWE-20
Published
Advisory Summary

CVE-2021-20329 is a MODERATE (CVSS 6.8) go.mongodb.org/mongo-driver improperly validates cstrings when vulnerability (CWE-1287: Improper Validation of Specified Type of Input) affecting Go.mongodb.org/mongo driver libraries in the Go ecosystem. The issue involves go.mongodb.org/mongo-driver improperly validates cstrings when marshalling go objects into bson. Remediation is available by upgrading affected packages to version 1.5.1.

CVE-2021-20329 at a Glance

CVE Identifier CVE-2021-20329
GHSA Identifier GHSA-f6mq-5m25-4r72
Severity MODERATE
CVSS v3.1 Base Score 6.8
CWE Classification CWE-1287: Improper Validation of Specified Type of Input
Affected Product Go.mongodb.org/mongo driver
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 6.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2021-20329

To remediate this vulnerability, upgrade all affected Go.mongodb.org/mongo driver dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

go.mongodb.org/mongo-driver fixed: 1.5.1
Upgrade go.mongodb.org/mongo-driver to 1.5.1
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for go.mongodb.org/mongo-driver

How to Check if You Are Affected

To determine whether your application is affected by CVE-2021-20329, inspect your project dependencies for Go.mongodb.org/mongo driver:

inspect dependencies for go.mongodb.org/mongo-driver

Analyze the terminal output to locate any version of Go.mongodb.org/mongo driver in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.5.1), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-1287: Improper Validation of Specified Type of Input, where the product receives input that is expected to be of a certain type, but it does not validate or incorrectly validates that the input is actually of the expected type. In Go.mongodb.org/mongo driver, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

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 up to (and including) 1.5.0.

CVE-2021-20329 Affected Go.mongodb.org/mongo driver Versions

1 component(s)
Fixed Versions:
1.5.1
Product / Package Ecosystem Affected Versions Fixed Version
go.mongodb.org/mongo-driver
Go
< 1.5.1
1.5.1

References

Frequently Asked Questions

What is CVE-2021-20329?
CVE-2021-20329 is a security vulnerability in Go.mongodb.org/mongo driver involving go.mongodb.org/mongo-driver improperly validates cstrings when marshalling Go objects into BSON under CWE-1287: Improper Validation of Specified Type of Input.
Which Go.mongodb.org/mongo driver versions are affected?
Affected versions include releases prior to 1.5.1 across affected packages: go.mongodb.org/mongo-driver.
What version fixes CVE-2021-20329?
Upgrading to 1.5.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is go.mongodb.org/mongo-driver affected?
Yes, go.mongodb.org/mongo-driver is affected in releases prior to 1.5.1. Upgrade your dependency to 1.5.1 or later.
What is the CVSS score of CVE-2021-20329?
CVE-2021-20329 has a CVSS v3.1 base score of 6.8 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:N.
What CWE is associated with CVE-2021-20329?
CVE-2021-20329 is classified under CWE-1287: Improper Validation of Specified Type of Input (The product receives input that is expected to be of a certain type, but it does not validate or incorrectly validates that the input is actually of the expected type.).
How can I check Go dependencies for CVE-2021-20329?
Run the dependency tree command: 'inspect dependencies for go.mongodb.org/mongo-driver'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-f6mq-5m25-4r72",
  "modified" : "2024-09-17T15:38:07Z",
  "published" : "2021-06-15T16:08:16Z",
  "aliases" : [ "CVE-2021-20329" ],
  "summary" : "go.mongodb.org/mongo-driver improperly validates cstrings when marshalling Go objects into BSON",
  "details" : "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 up to (and including) 1.5.0.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "go.mongodb.org/mongo-driver"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.5.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-20329"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mongodb/mongo-go-driver/pull/622"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mongodb/mongo-go-driver/commit/2aca31d5986a9e1c65a92264736de9fdc3b9b4ca"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/mongodb/mongo-go-driver"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mongodb/mongo-go-driver/releases/tag/v1.5.1"
  }, {
    "type" : "WEB",
    "url" : "https://jira.mongodb.org/browse/GODRIVER-1923"
  }, {
    "type" : "WEB",
    "url" : "https://pkg.go.dev/vuln/GO-2021-0112"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1287", "CWE-20" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-06-14T19:11:50Z",
    "nvd_published_at" : "2021-06-10T17:15:00Z"
  }
}