CVE-2025-54070
OpenZeppelin Contracts's Bytes's lastIndexOf function with position argument performs out-of-bound memory access on empty buffers
Also known as GHSA-9rcw-c2f9-2j55
Mitigation
- Upgrade @openzeppelin/contracts to 5.4.0 or later.
- Upgrade @openzeppelin/contracts-upgradeable to 5.4.0 or later.
Who should check
- Projects that depend on npm package @openzeppelin/contracts (>= 5.2.0, < 5.4.0)
- Projects that depend on npm package @openzeppelin/contracts-upgradeable (>= 5.2.0, < 5.4.0)
- Anyone running openzeppelin-contracts >= 5.2.0, < 5.4.0
Vulnerability facts
- Affected
- @openzeppelin/contracts >= 5.2.0, < 5.4.0; @openzeppelin/contracts-upgradeable >= 5.2.0, < 5.4.0
- Fixed in
- 5.4.0
- Exploited in the wild
- Not in CISA KEV
- Public exploit / PoC
- None known
- Remote exploitation
- Remote, no login needed
- CVSS
- 6.9 (v4.0, CNA)CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:L/VA:L/SC:N/SI:N/SA:NOpen in CVSS calculator
Show all 11 CVSS metrics
- Attack vector: Network
- Attack complexity: Low
- Attack requirements: None
- Privileges required: None
- User interaction: None
- Confidentiality impact: None
- Integrity impact: Low
- Availability impact: Low
- Confidentiality impact on other systems: None
- Integrity impact on other systems: None
- Availability impact on other systems: None
- EPSS
- 0.67% chance of exploitation in 30 days (percentile 47, 2026-11-26)
- CWE
- CWE-125
- Modified
Description
OpenZeppelin Contracts is a library for secure smart contract development. Starting in version 5.2.0 and prior to version 5.4.0, the `lastIndexOf(bytes,byte,uint256)` function of the `Bytes.sol` library may access uninitialized memory when the following two conditions hold: 1) the provided buffer length is empty (i.e. `buffer.length == 0`) and position is not `2**256 - 1` (i.e. `pos != type(uint256).max`). The `pos` argument could be used to access arbitrary data outside of the buffer bounds. This could lead to the operation running out of gas, or returning an invalid index (outside of the empty buffer). Processing this invalid result for accessing the `buffer` would cause a revert under normal conditions. When triggered, the function reads memory at offset `buffer + 0x20 + pos`. If memory at that location (outside the `buffer`) matches the search pattern, the function would return an out of bound index instead of the expected `type(uint256).max`. This creates unexpected behavior where callers receive a valid-looking index pointing outside buffer bounds. Subsequent memory accesses that don't check bounds and use the returned index must carefully review the potential impact depending on their setup. Code relying on this function returning `type(uint256).max` for empty buffers or using the returned index without bounds checking could exhibit undefined behavior. Users should upgrade to version 5.4.0 to receive a patch.
Affected and fixed versions
| Package / product | Affected | Fixed | Source |
|---|---|---|---|
| npm @openzeppelin/contracts | >= 5.2.0, < 5.4.0 | 5.4.0 | osv |
| npm @openzeppelin/contracts-upgradeable | >= 5.2.0, < 5.4.0 | 5.4.0 | osv |
| openzeppelin-contracts | >= 5.2.0, < 5.4.0 | — | cvelist |
Check your systems with an agent
Paste this into Claude Code, Cursor or another coding agent. It only reads; it changes nothing.
Check whether anything I run is affected by CVE-2025-54070. Work read-only: do not install, upgrade, delete or change anything. Details: https://flawdb.com/CVE-2025-54070.md Affected: @openzeppelin/contracts >= 5.2.0, < 5.4.0; @openzeppelin/contracts-upgradeable >= 5.2.0, < 5.4.0 Fixed in: 5.4.0 Steps: 1. Search this machine and project for @openzeppelin/contracts (npm), @openzeppelin/contracts-upgradeable (npm), openzeppelin-contracts: dependency manifests and lockfiles, installed packages, container images and running services. 2. For each match, note the installed version and whether it is inside the affected range. 3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
References
Vendor advisories
FAQ
Is CVE-2025-54070 being exploited?
There is no confirmed exploitation: CVE-2025-54070 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known. EPSS estimates a 0.67% chance of exploitation in the next 30 days (as of 2026-11-26).
How serious is CVE-2025-54070?
Medium: CVSS 6.9 (v4.0, scored by CNA). Remote, no login needed.
Which versions are affected by CVE-2025-54070?
@openzeppelin/contracts >= 5.2.0, < 5.4.0; @openzeppelin/contracts-upgradeable >= 5.2.0, < 5.4.0.
Is there a fix for CVE-2025-54070?
Yes. Fixed in 5.4.0. Upgrade @openzeppelin/contracts to 5.4.0 or later. Upgrade @openzeppelin/contracts-upgradeable to 5.4.0 or later.
How do I check if I'm affected by CVE-2025-54070?
Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.