CVE-2023-31146: Vyper Vyper Vulnerable To OOB DynArray Vulnerability

HIGH
Advisory Identifier: GHSA-3p37-3636-q8wv
CVSS 7.5
CWE-787
Published
Advisory Summary

CVE-2023-31146 is a HIGH (CVSS 7.5) vyper vulnerable to oob dynarray vulnerability (CWE-787: Out-of-bounds Write) affecting Vyper libraries in the PyPI ecosystem. The issue involves vyper vulnerable to oob dynarray access when array is on both lhs and rhs of an assignment. Remediation is available by upgrading affected packages to version 0.3.8.

CVE-2023-31146 at a Glance

CVE Identifier CVE-2023-31146
GHSA Identifier GHSA-3p37-3636-q8wv
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-787: Out-of-bounds Write
Affected Product Vyper
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.5

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

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

How to Fix CVE-2023-31146

To remediate this vulnerability, upgrade all affected Vyper dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

vyper fixed: 0.3.8
pip install vyper>=0.3.8
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show vyper

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2023-31146, inspect your installed packages using pip:

pip show vyper

Analyze the terminal output to locate any version of Vyper in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.3.8), your application is affected.

Note: The pip show vyper command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-787: Out-of-bounds Write, where the product writes data past the end, or before the beginning, of the intended buffer. In Vyper, 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 during codegen, the length word of a dynarray is written before the data, which can result in OOB array access in the case where the dynarray is on both the lhs and rhs of an assignment. here is a minimal example producing the issue: ```vyper a:DynArray[uint256,3] @external def test() -> DynArray[uint256,3]: self.a = [1,2,3] self.a = empty(DynArray[uint256,3]) self.a = [self.a[0],self.a[1],self.a[2]] return self.a # return [1,2,3] ``` and here is an example demonstrating the issue can cause data corruption across call frames: ```vyper @external def test() -> DynArray[uint256,3]: self.a() return self.b() # return [1,2,3] @internal def a(): a: uint256 = 0 b: uint256 = 1 c: uint256 = 2 d: uint256 = 3 @internal def b() -> DynArray[uint256,3]: a: DynArray[uint256,3] = empty(DynArray[uint256,3]) a = [a[0],a[1],a[2]] return a ``` examples involving append and pop: ```vyper @internal def foo(): c: DynArray[uint256, 1] = [] c.append(c[0]) ``` ```vyper @internal def foo(): c: DynArray[uint256, 1] = [1] c[0] = c.pop() ``` the expected behavior in all of the above cases is to revert due to oob array access. ### Patches patched in 4f8289a81206f767df1900ac48f485d90fc87edb ### Workarounds _Is there a way for users to fix or remediate the vulnerability without upgrading?_ ### References _Are there any links users can visit to find out more?_

CVE-2023-31146 Affected Vyper Versions

1 component(s)
Fixed Versions:
0.3.8
Product / Package Ecosystem Affected Versions Fixed Version
vyper
PyPI
< 0.3.8
0.3.8

References

Frequently Asked Questions

What is CVE-2023-31146?
CVE-2023-31146 is a security vulnerability in Vyper involving Vyper vulnerable to OOB DynArray access when array is on both LHS and RHS of an assignment under CWE-787: Out-of-bounds Write.
Which Vyper versions are affected?
Affected versions include releases prior to 0.3.8 across affected packages: vyper.
What version fixes CVE-2023-31146?
Upgrading to 0.3.8 (or the latest patched release for your respective branch) resolves the vulnerability.
Is vyper affected?
Yes, vyper is affected in releases prior to 0.3.8. Upgrade your dependency to 0.3.8 or later.
What is the CVSS score of CVE-2023-31146?
CVE-2023-31146 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N.
What CWE is associated with CVE-2023-31146?
CVE-2023-31146 is classified under CWE-787: Out-of-bounds Write (The product writes data past the end, or before the beginning, of the intended buffer.).
How can I check PyPI dependencies for CVE-2023-31146?
Run the dependency tree command: 'pip show vyper'. 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-3p37-3636-q8wv",
  "modified" : "2024-11-19T16:32:12Z",
  "published" : "2023-05-12T20:21:54Z",
  "aliases" : [ "CVE-2023-31146" ],
  "summary" : "Vyper vulnerable to OOB DynArray access when array is on both LHS and RHS of an assignment",
  "details" : "### Impact\nduring codegen, the length word of a dynarray is written before the data, which can result in OOB array access in the case where the dynarray is on both the lhs and rhs of an assignment. here is a minimal example producing the issue:\n```vyper\na:DynArray[uint256,3]\n@external\ndef test() -> DynArray[uint256,3]:\n    self.a = [1,2,3]\n    self.a = empty(DynArray[uint256,3])\n    self.a = [self.a[0],self.a[1],self.a[2]]\n    return self.a # return [1,2,3]\n```\n\nand here is an example demonstrating the issue can cause data corruption across call frames:\n\n```vyper\n@external\ndef test() -> DynArray[uint256,3]:\n    self.a()\n    return self.b() # return [1,2,3]\n\n@internal\ndef a():\n    a: uint256 = 0    \n    b: uint256 = 1    \n    c: uint256 = 2    \n    d: uint256 = 3\n\n@internal\ndef b() -> DynArray[uint256,3]:\n    a: DynArray[uint256,3] = empty(DynArray[uint256,3])\n    a = [a[0],a[1],a[2]]\n    return a\n```\n\nexamples involving append and pop:\n```vyper\n@internal\ndef foo():\n    c: DynArray[uint256, 1] = []\n    c.append(c[0])\n```\n\n```vyper\n@internal\ndef foo():\n    c: DynArray[uint256, 1] = [1]\n    c[0] = c.pop()\n```\n\nthe expected behavior in all of the above cases is to revert due to oob array access.\n\n### Patches\npatched in 4f8289a81206f767df1900ac48f485d90fc87edb\n\n### Workarounds\n_Is there a way for users to fix or remediate the vulnerability without upgrading?_\n\n### References\n_Are there any links users can visit to find out more?_\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "vyper"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.3.8"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/security/advisories/GHSA-3p37-3636-q8wv"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-31146"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/commit/4f8289a81206f767df1900ac48f485d90fc87edb"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/vyper/PYSEC-2023-77.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/vyperlang/vyper"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-787" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-05-12T20:21:54Z",
    "nvd_published_at" : "2023-05-11T21:15:10Z"
  }
}