CVE-2022-39384: @openzeppelin/contracts OpenZeppelin Contracts Initializer Reentrancy May Vulnerability

MODERATE
Advisory Identifier: GHSA-9c22-pwxw-p6hx
CVSS 5.6
CWE-665
Published
Advisory Summary

CVE-2022-39384 is a MODERATE (CVSS 5.6) openzeppelin contracts initializer reentrancy may vulnerability (CWE-665: Improper Initialization) affecting @openzeppelin/contracts libraries in the npm ecosystem. The issue involves openzeppelin contracts initializer reentrancy may lead to double initialization. Remediation is available by upgrading affected packages to version 4.4.1.

CVE-2022-39384 at a Glance

CVE Identifier CVE-2022-39384
GHSA Identifier GHSA-9c22-pwxw-p6hx
Severity MODERATE
CVSS v3.1 Base Score 5.6
CWE Classification CWE-665: Improper Initialization
Affected Product @openzeppelin/contracts
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 5.6

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:L/I:L/A:L).

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 Low (C:L)
Integrity Low (I:L)
Availability Low (A:L)

How to Fix CVE-2022-39384

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.4.1
npm install @openzeppelin/contracts@4.4.1
@openzeppelin/contracts-upgradeable fixed: 4.4.1
npm install @openzeppelin/contracts-upgradeable@4.4.1
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-2022-39384, 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.4.1), 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-665: Improper Initialization, where the product does not initialize or incorrectly initializes a resource, which might leave the resource in an unexpected state when it is accessed or used. 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 Initializer functions that are invoked separate from contract creation (the most prominent example being minimal proxies) may be reentered if they make an untrusted non-view external call. Once an initializer has finished running it can never be re-executed. However, an exception put in place to support multiple inheritance made reentrancy possible in the scenario described above, breaking the expectation that there is a single execution. Note that upgradeable proxies are commonly initialized together with contract creation, where reentrancy is not feasible, so the impact of this issue is believed to be minor. ### Patches A fix is included in the version v4.4.1 of `@openzeppelin/contracts` and `@openzeppelin/contracts-upgradeable`. ### Workarounds Avoid untrusted external calls during initialization. ### References https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3006 ### Credits This issue was identified and reported by @chaitinblockchain through [our bug bounty on Immunefi](https://immunefi.com/bounty/openzeppelin/). ### For more information If you have any questions or comments about this advisory, or need assistance executing the mitigation, email us at security@openzeppelin.com.

CVE-2022-39384 Affected @openzeppelin/contracts Versions

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

References

Frequently Asked Questions

What is CVE-2022-39384?
CVE-2022-39384 is a security vulnerability in @openzeppelin/contracts involving OpenZeppelin Contracts initializer reentrancy may lead to double initialization under CWE-665: Improper Initialization.
Which @openzeppelin/contracts versions are affected?
Affected versions include releases prior to 4.4.1 across affected packages: @openzeppelin/contracts, @openzeppelin/contracts-upgradeable.
What version fixes CVE-2022-39384?
Upgrading to 4.4.1 (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.4.1. Upgrade your dependency to 4.4.1 or later.
Is @openzeppelin/contracts-upgradeable affected?
Yes, @openzeppelin/contracts-upgradeable is affected in releases prior to 4.4.1. Upgrade your dependency to 4.4.1 or later.
What is the CVSS score of CVE-2022-39384?
CVE-2022-39384 has a CVSS v3.1 base score of 5.6 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L.
What CWE is associated with CVE-2022-39384?
CVE-2022-39384 is classified under CWE-665: Improper Initialization (The product does not initialize or incorrectly initializes a resource, which might leave the resource in an unexpected state when it is accessed or used.).
How can I check npm dependencies for CVE-2022-39384?
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-9c22-pwxw-p6hx",
  "modified" : "2022-11-07T21:13:24Z",
  "published" : "2021-12-14T21:47:33Z",
  "aliases" : [ "CVE-2022-39384" ],
  "summary" : "OpenZeppelin Contracts initializer reentrancy may lead to double initialization",
  "details" : "### Impact\n\nInitializer functions that are invoked separate from contract creation (the most prominent example being minimal proxies) may be reentered if they make an untrusted non-view external call.\n\nOnce an initializer has finished running it can never be re-executed. However, an exception put in place to support multiple inheritance made reentrancy possible in the scenario described above, breaking the expectation that there is a single execution.\n\nNote that upgradeable proxies are commonly initialized together with contract creation, where reentrancy is not feasible, so the impact of this issue is believed to be minor.\n\n### Patches\n\nA fix is included in the version v4.4.1 of `@openzeppelin/contracts` and `@openzeppelin/contracts-upgradeable`.\n\n### Workarounds\n\nAvoid untrusted external calls during initialization.\n\n### References\nhttps://github.com/OpenZeppelin/openzeppelin-contracts/pull/3006\n\n### Credits\n\nThis issue was identified and reported by @chaitinblockchain through [our bug bounty on Immunefi](https://immunefi.com/bounty/openzeppelin/).\n\n### For more information\n\nIf you have any questions or comments about this advisory, or need assistance executing the mitigation, email us at security@openzeppelin.com.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@openzeppelin/contracts"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.2.0"
      }, {
        "fixed" : "4.4.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@openzeppelin/contracts-upgradeable"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.2.0"
      }, {
        "fixed" : "4.4.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts/security/advisories/GHSA-9c22-pwxw-p6hx"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-39384"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3006"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/OpenZeppelin/openzeppelin-contracts"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-665" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-12-14T19:22:45Z",
    "nvd_published_at" : "2022-11-04T22:15:00Z"
  }
}