CVE-2024-27094: @openzeppelin/contracts OpenZeppelin Contracts Base64 Encoding May Vulnerability

MODERATE
Advisory Identifier: GHSA-9vx6-7xxf-x967
CVSS 6.5
CWE-125
Published
Advisory Summary

CVE-2024-27094 is a MODERATE (CVSS 6.5) openzeppelin contracts base64 encoding may vulnerability (CWE-125: Out-of-bounds Read) affecting @openzeppelin/contracts libraries in the npm ecosystem. The issue involves openzeppelin contracts base64 encoding may read from potentially dirty memory. Remediation is available by upgrading affected packages to version 4.9.6, 5.0.2.

CVE-2024-27094 at a Glance

CVE Identifier CVE-2024-27094
GHSA Identifier GHSA-9vx6-7xxf-x967
Severity MODERATE
CVSS v3.1 Base Score 6.5
CWE Classification CWE-125: Out-of-bounds Read
Affected Product @openzeppelin/contracts
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 6.5

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

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

How to Fix CVE-2024-27094

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.6
npm install @openzeppelin/contracts@4.9.6
@openzeppelin/contracts-upgradeable fixed: 5.0.2
npm install @openzeppelin/contracts-upgradeable@5.0.2
@openzeppelin/contracts fixed: 5.0.2
npm install @openzeppelin/contracts@5.0.2
@openzeppelin/contracts-upgradeable fixed: 4.9.6
npm install @openzeppelin/contracts-upgradeable@4.9.6
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-2024-27094, 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.6), 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-125: Out-of-bounds Read, where the product reads data past the end, or before the beginning, of the intended buffer. 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 The `Base64.encode` function encodes a `bytes` input by iterating over it in chunks of 3 bytes. When this input is not a multiple of 3, the last iteration may read parts of the memory that are beyond the input buffer. Although the `encode` function pads the output for these cases, up to 4 bits of data are kept between the encoding and padding, corrupting the output if these bits were dirty (i.e. memory after the input is not 0). These conditions are more frequent in the following scenarios: - A `bytes memory` struct is allocated just after the input and the first bytes of it are non-zero. - The memory pointer is set to a non-empty memory location before allocating the input. Developers should evaluate whether the extra bits can be maliciously manipulated by an attacker. ### Patches Upgrade to 5.0.2 or 4.9.6. ### References This issue was reported by the Independent Security Researcher Riley Holterhus through Immunefi (@rileyholterhus on X)

CVE-2024-27094 Affected @openzeppelin/contracts Versions

4 component(s)
Fixed Versions:
4.9.65.0.2
Product / Package Ecosystem Affected Versions Fixed Version
@openzeppelin/contracts
npm
≥ 4.5.0
< 4.9.6
4.9.6
@openzeppelin/contracts-upgradeable
npm
≥ 5.0.0-rc.0
< 5.0.2
5.0.2
@openzeppelin/contracts
npm
≥ 5.0.0-rc.0
< 5.0.2
5.0.2
@openzeppelin/contracts-upgradeable
npm
≥ 4.5.0
< 4.9.6
4.9.6

References

Frequently Asked Questions

What is CVE-2024-27094?
CVE-2024-27094 is a security vulnerability in @openzeppelin/contracts involving OpenZeppelin Contracts base64 encoding may read from potentially dirty memory under CWE-125: Out-of-bounds Read.
Which @openzeppelin/contracts versions are affected?
Affected versions include releases prior to 4.9.6, 5.0.2 across affected packages: @openzeppelin/contracts, @openzeppelin/contracts-upgradeable.
What version fixes CVE-2024-27094?
Upgrading to 4.9.6, 5.0.2 (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.6, 5.0.2. Upgrade your dependency to 4.9.6, 5.0.2 or later.
Is @openzeppelin/contracts-upgradeable affected?
Yes, @openzeppelin/contracts-upgradeable is affected in releases prior to 5.0.2, 4.9.6. Upgrade your dependency to 5.0.2, 4.9.6 or later.
What is the CVSS score of CVE-2024-27094?
CVE-2024-27094 has a CVSS v3.1 base score of 6.5 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:H.
What CWE is associated with CVE-2024-27094?
CVE-2024-27094 is classified under CWE-125: Out-of-bounds Read (The product reads data past the end, or before the beginning, of the intended buffer.).
How can I check npm dependencies for CVE-2024-27094?
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-9vx6-7xxf-x967",
  "modified" : "2025-12-04T22:49:19Z",
  "published" : "2024-02-29T20:09:53Z",
  "aliases" : [ "CVE-2024-27094" ],
  "summary" : "OpenZeppelin Contracts base64 encoding may read from potentially dirty memory",
  "details" : "### Impact\n\nThe `Base64.encode` function encodes a `bytes` input by iterating over it in chunks of 3 bytes. When this input is not a multiple of 3, the last iteration may read parts of the memory that are beyond the input buffer.\n\nAlthough the `encode` function pads the output for these cases, up to 4 bits of data are kept between the encoding and padding, corrupting the output if these bits were dirty (i.e. memory after the input is not 0). These conditions are more frequent in the following scenarios:\n\n- A `bytes memory` struct is allocated just after the input and the first bytes of it are non-zero.\n- The memory pointer is set to a non-empty memory location before allocating the input.\n\nDevelopers should evaluate whether the extra bits can be maliciously manipulated by an attacker.\n\n### Patches\n\nUpgrade to 5.0.2 or 4.9.6.\n\n### References\n\nThis issue was reported by the Independent Security Researcher Riley Holterhus through Immunefi (@rileyholterhus on X)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@openzeppelin/contracts"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.5.0"
      }, {
        "fixed" : "4.9.6"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@openzeppelin/contracts-upgradeable"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "5.0.0-rc.0"
      }, {
        "fixed" : "5.0.2"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@openzeppelin/contracts"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "5.0.0-rc.0"
      }, {
        "fixed" : "5.0.2"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@openzeppelin/contracts-upgradeable"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.5.0"
      }, {
        "fixed" : "4.9.6"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts/security/advisories/GHSA-9vx6-7xxf-x967"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-27094"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/commit/2d081f24cac1a867f6f73d512f2022e1fa987854"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/commit/723f8cab09cdae1aca9ec9cc1cfa040c2d4b06c1"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts/commit/92224533b1263772b0774eec3134e132a3d7b2a6"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts/commit/a6286d0fded8771b3a645e5813e51993c490399c"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-125" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-02-29T20:09:53Z",
    "nvd_published_at" : "2024-03-21T02:52:18Z"
  }
}