# CVE-2023-40014: OpenZeppelin Contracts's ERC2771Context with custom forwarder may lead to zero-valued _msgSender

> Attackers can bypass sender verification in smart contracts using custom forwarders, potentially leading to unauthorized actions.

- **Severity:** Medium 5.3 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 10 Aug 2023
- **Updated:** 3 Oct 2024
- **Also known as:** GHSA-g4vp-m682-qqmp, UBUNTU-CVE-2023-40014

## What is CVE-2023-40014?

CVE-2023-40014 is a medium-severity vulnerability in openzeppelin-contracts, published on 10 Aug 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

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. The problem has been patched in v4.9.3.

Weakness: CWE-116 (Improper Encoding or Escaping of Output)

## Which versions are affected by CVE-2023-40014?

4 open source packages ship an affected version, including @openzeppelin/contracts and @openzeppelin/contracts-upgradeable. It affects 2 products.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `@openzeppelin/contracts` | npm | From 4.0.0 | 4.9.3 |
| `@openzeppelin/contracts` | npm | From 4.0.0 | 4.9.3 |
| `@openzeppelin/contracts-upgradeable` | npm | From 4.0.0 | 4.9.3 |
| `@openzeppelin/contracts-upgradeable` | npm | From 4.0.0 | 4.9.3 |

Products: Openzeppelin Openzeppelin Contracts, Openzeppelin Openzeppelin Contracts-Upgradable.

## How do I fix CVE-2023-40014?

Upgrade @openzeppelin/contracts to 4.9.3 or later.

## Is CVE-2023-40014 being exploited?

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

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2023-40014 and fix it if it is affected.

What it is: CVE-2023-40014 is a medium-severity vulnerability in openzeppelin-contracts, published on 10 Aug 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2023-40014 in the wild and no public exploit code.

Affected packages and fixed versions:
- @openzeppelin/contracts (npm): affected from 4.0.0; fixed in 4.9.3
- @openzeppelin/contracts (npm): affected from 4.0.0; fixed in 4.9.3
- @openzeppelin/contracts-upgradeable (npm): affected from 4.0.0; fixed in 4.9.3
- @openzeppelin/contracts-upgradeable (npm): affected from 4.0.0; fixed in 4.9.3

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

## Sources

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

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