CVE-2024-24563: Vyper Vyper Negative Array Index Bounds Vulnerability

CRITICAL
Advisory Identifier: GHSA-52xq-j7v9-v4v2
CVSS 9.8
CWE-129
Published
Advisory Summary

CVE-2024-24563 is a CRITICAL (CVSS 9.8) vyper negative array index bounds vulnerability (CWE-129: Improper Validation of Array Index) affecting Vyper libraries in the PyPI ecosystem. The issue involves vyper negative array index bounds checks. Remediation is available by upgrading affected packages to version 0.4.0.

CVE-2024-24563 at a Glance

CVE Identifier CVE-2024-24563
GHSA Identifier GHSA-52xq-j7v9-v4v2
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-129: Improper Validation of Array Index
Affected Product Vyper
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 9.8

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

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

How to Fix CVE-2024-24563

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.4.0
pip install vyper>=0.4.0
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-2024-24563, 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.4.0), 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-129: Improper Validation of Array Index, where the product uses untrusted input when calculating or using an array index, but the product does not validate or incorrectly validates the index to ensure the index references a valid position within the array. 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

### Summary Arrays can be keyed by a signed integer, while they are defined for unsigned integers only. The typechecker doesn't throw when spotting the usage of an `int` as an index for an array. Typically, negative integers are filtered out at runtime by the bounds checker, but small enough (i.e. large in magnitude, ex. `-2**255 + 5`) quantities combined with large enough arrays (at least `2**255` in length) can pass the bounds checker, resulting in unexpected behavior. A contract search was performed, and no production contracts were found to be impacted. ### Details The typechecker allows the usage of signed integers to be used as indexes to arrays. The vulnerability is present in different forms in all versions. Here is an example from `0.3.10`: https://github.com/vyperlang/vyper/blob/c150fc49ee9375a930d177044559b83cb95f7963/vyper/semantics/types/subscriptable.py#L127-L137 As can be seen, the validation is performed against `IntegerT.any()`. ### PoC If the array is sufficiently large, it can be indexed with a negative value: ```python arr: public(uint256[MAX_UINT256]) @external def set(idx: int256, num: uint256): self.arr[idx] = num ``` For signed integers, the 2's complement representation is used. Because the array was declared very large, the bounds checking will pass (negative values will simply be represented as very large numbers): https://github.com/vyperlang/vyper/blob/a1fd228cb9936c3e4bbca6f3ee3fb4426ef45490/vyper/codegen/core.py#L534-L541 ### Patches Patched in https://github.com/vyperlang/vyper/pull/3817. ### Impact There are two potential vulnerability classes: unpredictable behavior and accessing inaccessible elements. 1. If it is possible to index an array with a negative integer without reverting, this is most likely not anticipated by the developer and such accesses can cause unpredictable behavior for the contract. 2. If a contract has an invariant in the form `assert index < x` where both `index` and `x` are signed integers, the developer might suppose that no elements on indexes `y | y >= x` are accessible. However, by using negative indexes this can be bypassed. The contract search found no production contracts impacted by these two classes of issues.

CVE-2024-24563 Affected Vyper Versions

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

References

Frequently Asked Questions

What is CVE-2024-24563?
CVE-2024-24563 is a security vulnerability in Vyper involving Vyper negative array index bounds checks under CWE-129: Improper Validation of Array Index.
Which Vyper versions are affected?
Affected versions include releases prior to 0.4.0 across affected packages: vyper.
What version fixes CVE-2024-24563?
Upgrading to 0.4.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is vyper affected?
Yes, vyper is affected in releases prior to 0.4.0. Upgrade your dependency to 0.4.0 or later.
What is the CVSS score of CVE-2024-24563?
CVE-2024-24563 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2024-24563?
CVE-2024-24563 is classified under CWE-129: Improper Validation of Array Index (The product uses untrusted input when calculating or using an array index, but the product does not validate or incorrectly validates the index to ensure the index references a valid position within the array.).
How can I check PyPI dependencies for CVE-2024-24563?
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-52xq-j7v9-v4v2",
  "modified" : "2024-11-22T20:46:17Z",
  "published" : "2024-02-07T17:27:58Z",
  "aliases" : [ "CVE-2024-24563" ],
  "summary" : "Vyper negative array index bounds checks",
  "details" : "### Summary\nArrays can be keyed by a signed integer, while they are defined for unsigned integers only. The typechecker doesn't throw when spotting the usage of an `int` as an index for an array. Typically, negative integers are filtered out at runtime by the bounds checker, but small enough (i.e. large in magnitude, ex. `-2**255 + 5`) quantities combined with large enough arrays (at least `2**255` in length) can pass the bounds checker, resulting in unexpected behavior.\n\nA contract search was performed, and no production contracts were found to be impacted.\n\n### Details\nThe typechecker allows the usage of signed integers to be used as indexes to arrays. The vulnerability is present in different forms in all versions. Here is an example from `0.3.10`:\nhttps://github.com/vyperlang/vyper/blob/c150fc49ee9375a930d177044559b83cb95f7963/vyper/semantics/types/subscriptable.py#L127-L137\n\nAs can be seen, the validation is performed against `IntegerT.any()`.\n\n### PoC\nIf the array is sufficiently large, it can be indexed with a negative value:\n```python\narr: public(uint256[MAX_UINT256])\n\n@external\ndef set(idx: int256, num: uint256):\n    self.arr[idx] = num\n```\nFor signed integers, the 2's complement representation is used. Because the array was declared very large, the bounds checking will pass (negative values will simply be represented as very large numbers):\nhttps://github.com/vyperlang/vyper/blob/a1fd228cb9936c3e4bbca6f3ee3fb4426ef45490/vyper/codegen/core.py#L534-L541\n\n### Patches\nPatched in https://github.com/vyperlang/vyper/pull/3817.\n\n### Impact\nThere are two potential vulnerability classes: unpredictable behavior and accessing inaccessible elements.\n\n1. If it is possible to index an array with a negative integer without reverting, this is most likely not anticipated by the developer and such accesses can cause unpredictable behavior for the contract.\n\n2. If a contract has an invariant in the form `assert index < x` where both `index` and `x` are signed integers, the developer might suppose that no elements on indexes `y | y >= x` are accessible. However, by using negative indexes this can be bypassed.\n\nThe contract search found no production contracts impacted by these two classes of issues.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "vyper"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.4.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/security/advisories/GHSA-52xq-j7v9-v4v2"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-24563"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/vyper/PYSEC-2024-150.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/vyperlang/vyper"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/blob/a1fd228cb9936c3e4bbca6f3ee3fb4426ef45490/vyper/codegen/core.py#L534-L541"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/blob/c150fc49ee9375a930d177044559b83cb95f7963/vyper/semantics/types/subscriptable.py#L127-L137"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-129" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-02-07T17:27:58Z",
    "nvd_published_at" : "2024-02-07T17:15:10Z"
  }
}