CVE-2023-34449: Ink Ink! Vulnerable To Incorrect Decoding Vulnerability

MODERATE
Advisory Identifier: GHSA-853p-5678-hv8f
CVSS 5.3
CWE-253 CWE-754
Published
Advisory Summary

CVE-2023-34449 is a MODERATE (CVSS 5.3) ink! vulnerable to incorrect decoding vulnerability (CWE-253: Incorrect Check of Function Return Value) affecting Ink libraries in the crates.io ecosystem. The issue involves ink! vulnerable to incorrect decoding of storage value when using `delegatecall`. Remediation is available by upgrading affected packages to version 4.2.1.

CVE-2023-34449 at a Glance

CVE Identifier CVE-2023-34449
GHSA Identifier GHSA-853p-5678-hv8f
Severity MODERATE
CVSS v3.1 Base Score 5.3
CWE Classification CWE-253: Incorrect Check of Function Return Value
Affected Product Ink
Package Ecosystem crates.io
Published Date
Last Updated

Security Impact

CVSS: 5.3

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:L/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 Low (I:L)
Availability None (A:N)

How to Fix CVE-2023-34449

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

ink fixed: 4.2.1
Upgrade ink to 4.2.1
ink_env fixed: 4.2.1
Upgrade ink_env to 4.2.1
Verify Direct and Transitive Dependencies

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

inspect dependencies for ink

How to Check if You Are Affected

To determine whether your application is affected by CVE-2023-34449, inspect your project dependencies for Ink:

inspect dependencies for ink

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

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-253: Incorrect Check of Function Return Value, where the product incorrectly checks a return value from a function, which prevents it from detecting errors or exceptional conditions. In Ink, 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 The return value when using delegate call mechanics, either through [`CallBuilder::delegate`](https://docs.rs/ink_env/4.2.0/ink_env/call/struct.CallBuilder.html#method.delegate) or [`ink_env::invoke_contract_delegate`](https://docs.rs/ink_env/4.2.0/ink_env/fn.invoke_contract_delegate.html), is being decoded incorrectly. ### Description Consider this minimal example: ```rust // First contract, this will be performing a delegate call to the `Callee`. #[ink(storage)] pub struct Caller { value: u128, } #[ink(message)] pub fn get_value(&self, callee_code_hash: Hash) -> u128 { let result = build_call::<DefaultEnvironment>() .delegate(callee_code_hash) .exec_input(ExecutionInput::new(Selector::new(ink::selector_bytes!( "get_value" )))) .returns::<u128>() .invoke(); result } // Different contract, using this code hash for the delegate call. #[ink(storage)] pub struct Callee { value: u128, } #[ink(message)] pub fn get_value(&self) -> u128 { self.value } ``` In this example we are executing the `Callee` code in the context of the `Caller` contract. This means we'll be using the storage values of the `Caller` contract. Running this code we expect the delegate call to return `value` as it was stored in the `Caller` contract. However, due to the reported bug a different value is returned (for the case of `uint`s it is `256` times the expected value). ### Impact After conducting an analysis of the on-chain deployments of ink! contracts on Astar, Shiden, Aleph Zero, Amplitude and Pendulum, we have found that no contracts on those chains have been affected by the issue. This bug was related to the mechanics around decoding a call's return buffer, which was changed as part of https://github.com/paritytech/ink/pull/1450. Since this feature was only released in ink! 4.0.0 no previous versions are affected. ### Mitigations If you have an ink! 4.x series contract, please update it to the [4.2.1](https://github.com/paritytech/ink/releases/tag/v4.2.1) patch release that we just published. ### Credits Thank you Facundo Lerena from [CoinFabrik](https://www.coinfabrik.com) for reporting this problem in a well-structured and responsible way.

CVE-2023-34449 Affected Ink Versions

2 component(s)
Fixed Versions:
4.2.1
Product / Package Ecosystem Affected Versions Fixed Version
ink
crates.io
≥ 4.0.0
< 4.2.1
4.2.1
ink_env
crates.io
≥ 4.0.0
< 4.2.1
4.2.1

References

Frequently Asked Questions

What is CVE-2023-34449?
CVE-2023-34449 is a security vulnerability in Ink involving ink! vulnerable to incorrect decoding of storage value when using `DelegateCall` under CWE-253: Incorrect Check of Function Return Value.
Which Ink versions are affected?
Affected versions include releases prior to 4.2.1 across affected packages: ink, ink_env.
What version fixes CVE-2023-34449?
Upgrading to 4.2.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is ink affected?
Yes, ink is affected in releases prior to 4.2.1. Upgrade your dependency to 4.2.1 or later.
Is ink_env affected?
Yes, ink_env is affected in releases prior to 4.2.1. Upgrade your dependency to 4.2.1 or later.
What is the CVSS score of CVE-2023-34449?
CVE-2023-34449 has a CVSS v3.1 base score of 5.3 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N.
What CWE is associated with CVE-2023-34449?
CVE-2023-34449 is classified under CWE-253: Incorrect Check of Function Return Value (The product incorrectly checks a return value from a function, which prevents it from detecting errors or exceptional conditions.).
How can I check crates.io dependencies for CVE-2023-34449?
Run the dependency tree command: 'inspect dependencies for ink'. 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-853p-5678-hv8f",
  "modified" : "2023-06-16T17:57:43Z",
  "published" : "2023-06-14T20:11:38Z",
  "aliases" : [ "CVE-2023-34449" ],
  "summary" : "ink! vulnerable to incorrect decoding of storage value when using `DelegateCall`",
  "details" : "### Summary\nThe return value when using delegate call mechanics, either through [`CallBuilder::delegate`](https://docs.rs/ink_env/4.2.0/ink_env/call/struct.CallBuilder.html#method.delegate) or [`ink_env::invoke_contract_delegate`](https://docs.rs/ink_env/4.2.0/ink_env/fn.invoke_contract_delegate.html), is being decoded incorrectly.\n\n### Description\nConsider this minimal example:\n\n```rust\n// First contract, this will be performing a delegate call to the `Callee`.\n#[ink(storage)]\npub struct Caller {\n    value: u128,\n}\n\n#[ink(message)]\npub fn get_value(&self, callee_code_hash: Hash) -> u128 {\n    let result = build_call::<DefaultEnvironment>()\n        .delegate(callee_code_hash)\n        .exec_input(ExecutionInput::new(Selector::new(ink::selector_bytes!(\n            \"get_value\"\n        ))))\n        .returns::<u128>()\n        .invoke();\n\n    result\n}\n\n// Different contract, using this code hash for the delegate call.\n#[ink(storage)]\npub struct Callee {\n    value: u128,\n}\n\n#[ink(message)]\npub fn get_value(&self) -> u128 {\n    self.value\n}\n```\n\nIn this example we are executing the `Callee` code in the context of the `Caller` contract. This means we'll be using the storage values of the `Caller` contract.\n\nRunning this code we expect the delegate call to return `value` as it was stored in the `Caller` contract. However, due to the reported bug a different value is returned (for the case of `uint`s it is `256` times the expected value).\n\n### Impact\nAfter conducting an analysis of the on-chain deployments of ink! contracts on Astar, Shiden, Aleph Zero, Amplitude and Pendulum, we have found that no contracts on those chains have been affected by the issue.\n\nThis bug was related to the mechanics around decoding a call's return buffer, which was changed as part of https://github.com/paritytech/ink/pull/1450. Since this feature was only released in ink! 4.0.0 no previous versions are affected.\n\n### Mitigations\nIf you have an ink! 4.x series contract, please update it to the [4.2.1](https://github.com/paritytech/ink/releases/tag/v4.2.1) patch release that we just published. \n\n### Credits\nThank you Facundo Lerena from [CoinFabrik](https://www.coinfabrik.com) for reporting this problem in a well-structured and responsible way.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "ink"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.0.0"
      }, {
        "fixed" : "4.2.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "ink_env"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.0.0"
      }, {
        "fixed" : "4.2.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/paritytech/ink/security/advisories/GHSA-853p-5678-hv8f"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-34449"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/paritytech/ink/pull/1450"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/paritytech/ink/commit/f1407ee9f87e5f64d467a22d26ee88f61db7f3db"
  }, {
    "type" : "WEB",
    "url" : "https://docs.rs/ink_env/4.2.0/ink_env/call/struct.CallBuilder.html#method.delegate"
  }, {
    "type" : "WEB",
    "url" : "https://docs.rs/ink_env/4.2.0/ink_env/fn.invoke_contract_delegate.html"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/paritytech/ink"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-253", "CWE-754" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-06-14T20:11:38Z",
    "nvd_published_at" : "2023-06-14T21:15:09Z"
  }
}