CVE-2023-40014: OpenZeppelin Contracts improper escaping in ERC2771Context

CVE-2023-40014 · Severity: low · CVSS 3.1 · Published 2023-08-11

OpenZeppelin Contracts is a widely-used library for building secure smart contracts on blockchain networks. When using the ERC2771Context module with a custom trusted forwarder, a logic flaw can cause the sender address to be incorrectly resolved as zero in certain conditions, potentially leading to authentication bypass or authorization failures in dependent applications.

Technologies: @openzeppelin/contracts (npm), @openzeppelin/contracts-upgradeable (npm), OpenZeppelin Contracts, OpenZeppelin Contracts Upgradeable. Vendors: npm, OpenZeppelin.

Quick answers

Is CVE-2023-40014 exploited in the wild?
No. Junglewise Threat Intelligence has no report of CVE-2023-40014 being exploited in the wild.
How severe is CVE-2023-40014?
Low severity, with a CVSS score of 3.1, published 11 August 2023.
Which products and versions are affected?
@openzeppelin/contracts (npm) SEMVER:introduced=4.0.0,fixed=4.9.3; @openzeppelin/contracts-upgradeable (npm) SEMVER:introduced=4.0.0,fixed=4.9.3; OpenZeppelin Contracts >=4.0.0 to <4.9.3; OpenZeppelin Contracts Upgradeable >=4.0.0 to <4.9.3.
Is there a fix for CVE-2023-40014?
Yes. @openzeppelin/contracts (npm): upgrade to 4.9.3 or later; @openzeppelin/contracts-upgradeable (npm): upgrade to 4.9.3 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is CVE-2023-40014 attacked?
It is attacked over the network, in a software library.
Am I affected by CVE-2023-40014?
Check whether you run @openzeppelin/contracts (npm), @openzeppelin/contracts-upgradeable (npm), OpenZeppelin Contracts or one of the others listed at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

How to fix

  • @openzeppelin/contracts (npm): upgrade to 4.9.3 or later
    npm install @openzeppelin/contracts@4.9.3
  • @openzeppelin/contracts-upgradeable (npm): upgrade to 4.9.3 or later
    npm install @openzeppelin/contracts-upgradeable@4.9.3

Technical details

The vulnerability exists in ERC2771Context (versions 4.0.0 through 4.9.2) and stems from improper escaping or validation of calldata when extracting the message sender from a trusted forwarder. When a custom forwarder initiates a call with calldata shorter than 20 bytes, the _msgSender() function may incorrectly return address(0) instead of the legitimate sender address. This is classified as CWE-116 (Improper Encoding or Escaping of Output). The issue requires use of a non-standard forwarder implementation; OpenZeppelin's own MinimalForwarder and known production forwarders are unaffected. The vulnerability was patched in version 4.9.3.

Affected products

  • OpenZeppelin Contracts >=4.0.0 to <4.9.3
  • OpenZeppelin Contracts Upgradeable >=4.0.0 to <4.9.3

Identifiers

  • CVE-2023-40014
  • GHSA-g4vp-m682-qqmp

Timeline

  • 2023-08-10: disclosed: Vulnerability publicly disclosed
  • 2023-08-11: patched: Patch released in version 4.9.3

References

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.