CVE-2023-40014: @openzeppelin/contracts OpenZeppelin Contracts Vulnerable To Improper Vulnerability

MODERATE
Advisory Identifier: GHSA-g4vp-m682-qqmp
CVSS 5.3
CWE-116
Published
Advisory Summary

CVE-2023-40014 is a MODERATE (CVSS 5.3) openzeppelin contracts vulnerable to improper vulnerability (CWE-116: Improper Encoding or Escaping of Output) affecting @openzeppelin/contracts libraries in the npm ecosystem. The issue involves openzeppelin contracts vulnerable to improper escaping of output. Remediation is available by upgrading affected packages to version 4.9.3.

CVE-2023-40014 at a Glance

CVE Identifier CVE-2023-40014
GHSA Identifier GHSA-g4vp-m682-qqmp
Severity MODERATE
CVSS v3.1 Base Score 5.3
CWE Classification CWE-116: Improper Encoding or Escaping of Output
Affected Product @openzeppelin/contracts
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 5.3

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

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

How to Fix CVE-2023-40014

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

@openzeppelin/contracts fixed: 4.9.3
npm install @openzeppelin/contracts@4.9.3
@openzeppelin/contracts-upgradeable fixed: 4.9.3
npm install @openzeppelin/contracts-upgradeable@4.9.3
Verify Direct and Transitive Dependencies

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

npm ls @openzeppelin/contracts

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2023-40014, inspect your project dependencies using npm:

npm ls @openzeppelin/contracts

Analyze the terminal output to locate any version of @openzeppelin/contracts in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.9.3), your application is affected.

Note: The npm ls @openzeppelin/contracts command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-116: Improper Encoding or Escaping of Output, where the product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. as a result, the intended structure of the message is not preserved. In @openzeppelin/contracts, 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

### Impact OpenZeppelin Contracts is a library for secure smart contract development. Starting in version 4.0.0 and prior to version 4.9.3, contracts using `ERC2771Context` along with a custom trusted forwarder may see `_msgSender` return `address(0)` in calls that originate from the forwarder with calldata shorter than 20 bytes. This combination of circumstances does not appear to be common, in particular it is not the case for `MinimalForwarder` from OpenZeppelin Contracts, or any deployed forwarder the team is aware of, given that the signer address is appended to all calls that originate from these forwarders. ### Patches The problem has been patched in v4.9.3.

CVE-2023-40014 Affected @openzeppelin/contracts Versions

2 component(s)
Fixed Versions:
4.9.3
Product / Package Ecosystem Affected Versions Fixed Version
@openzeppelin/contracts
npm
≥ 4.0.0
< 4.9.3
4.9.3
@openzeppelin/contracts-upgradeable
npm
≥ 4.0.0
< 4.9.3
4.9.3

References

Frequently Asked Questions

What is CVE-2023-40014?
CVE-2023-40014 is a security vulnerability in @openzeppelin/contracts involving OpenZeppelin Contracts vulnerable to Improper Escaping of Output under CWE-116: Improper Encoding or Escaping of Output.
Which @openzeppelin/contracts versions are affected?
Affected versions include releases prior to 4.9.3 across affected packages: @openzeppelin/contracts, @openzeppelin/contracts-upgradeable.
What version fixes CVE-2023-40014?
Upgrading to 4.9.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @openzeppelin/contracts affected?
Yes, @openzeppelin/contracts is affected in releases prior to 4.9.3. Upgrade your dependency to 4.9.3 or later.
Is @openzeppelin/contracts-upgradeable affected?
Yes, @openzeppelin/contracts-upgradeable is affected in releases prior to 4.9.3. Upgrade your dependency to 4.9.3 or later.
What is the CVSS score of CVE-2023-40014?
CVE-2023-40014 has a CVSS v3.1 base score of 5.3 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N.
What CWE is associated with CVE-2023-40014?
CVE-2023-40014 is classified under CWE-116: Improper Encoding or Escaping of Output (The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved.).
How can I check npm dependencies for CVE-2023-40014?
Run the dependency tree command: 'npm ls @openzeppelin/contracts'. 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-g4vp-m682-qqmp",
  "modified" : "2023-08-11T19:00:48Z",
  "published" : "2023-08-11T19:00:48Z",
  "aliases" : [ "CVE-2023-40014" ],
  "summary" : "OpenZeppelin Contracts vulnerable to Improper Escaping of Output",
  "details" : "### Impact\n\nOpenZeppelin Contracts is a library for secure smart contract development. Starting in version 4.0.0 and prior to version 4.9.3, contracts using `ERC2771Context` along with a custom trusted forwarder may see `_msgSender` return `address(0)` in calls that originate from the forwarder with calldata shorter than 20 bytes. This combination of circumstances does not appear to be common, in particular it is not the case for `MinimalForwarder` from OpenZeppelin Contracts, or any deployed forwarder the team is aware of, given that the signer address is appended to all calls that originate from these forwarders.\n\n### Patches\n\nThe problem has been patched in v4.9.3.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@openzeppelin/contracts"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.0.0"
      }, {
        "fixed" : "4.9.3"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@openzeppelin/contracts-upgradeable"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.0.0"
      }, {
        "fixed" : "4.9.3"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts/security/advisories/GHSA-g4vp-m682-qqmp"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-40014"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts/pull/4481"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts/pull/4484"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts/commit/9445f96223041abf2bf08daa56f8da50b674cbcd"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts/commit/e4435eed757d4309436b1e06608e97b6d6e2fdb5"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.3/CHANGELOG.md"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts/releases/tag/v4.9.3"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-116" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-08-11T19:00:48Z",
    "nvd_published_at" : "2023-08-10T20:15:10Z"
  }
}