CVE-2022-23495: Github.com/ipfs/go merkledag Go-merkledag's ProtoNode May Be Modified Vulnerability

HIGH
Advisory Identifier: GHSA-x39j-h85h-3f46
CVSS 7.5
CWE-755 CWE-252
Published
Advisory Summary

CVE-2022-23495 is a HIGH (CVSS 7.5) go-merkledag's protonode may be modified vulnerability (CWE-755: Improper Handling of Exceptional Conditions) affecting Github.com/ipfs/go merkledag libraries in the Go ecosystem. The issue involves go-merkledag's protonode may be modified such that common method calls may panic. Remediation is available by upgrading affected packages to version 0.8.1.

CVE-2022-23495 at a Glance

CVE Identifier CVE-2022-23495
GHSA Identifier GHSA-x39j-h85h-3f46
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-755: Improper Handling of Exceptional Conditions
Affected Product Github.com/ipfs/go merkledag
Package Ecosystem Go
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:N/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 None (C:N)
Integrity None (I:N)
Availability High (A:H)

How to Fix CVE-2022-23495

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

github.com/ipfs/go-merkledag fixed: 0.8.1
Upgrade github.com/ipfs/go-merkledag to 0.8.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 github.com/ipfs/go-merkledag

How to Check if You Are Affected

To determine whether your application is affected by CVE-2022-23495, inspect your project dependencies for Github.com/ipfs/go merkledag:

inspect dependencies for github.com/ipfs/go-merkledag

Analyze the terminal output to locate any version of Github.com/ipfs/go merkledag in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.8.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-755: Improper Handling of Exceptional Conditions, where the product does not handle or incorrectly handles an exceptional condition. In Github.com/ipfs/go merkledag, 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 A `ProtoNode` may be modified in such a way as to cause various encode errors which will trigger a panic on common method calls that don't allow for error returns. A `ProtoNode` should only be able to encode to valid DAG-PB, attempting to encode invalid DAG-PB forms will result in an error from the codec. Manipulation of an existing (newly created or decoded) `ProtoNode` using the modifier methods did not account for certain states that would place the `ProtoNode` into an unencodeable form. Due to conformance with the [`github.com/ipfs/go-block-format#Block`](https://pkg.go.dev/github.com/ipfs/go-block-format#Block) and [`github.com/ipfs/go-ipld-format#Node`](https://pkg.go.dev/github.com/ipfs/go-ipld-format#Node) interfaces, certain methods, which internally require a re-encode if state has changed, will panic due to the inability to return an error. Additionally, use of the `ProtoNode#SetCidBuilder()` method to set a non-functioning `CidBuilder` (such as one that refers to a multihash where an implementation of that hash function is not available) may cause the same methods to panic as a new CID is required but cannot be created. ### Patches Releases involving fixes for this issue are [v0.8.0](https://github.com/ipfs/go-merkledag/releases/tag/v0.8.0) and [v0.8.1](https://github.com/ipfs/go-merkledag/releases/tag/v0.8.1). The recommended minimum version is **v0.8.1**. * Additional checks are performed on `ProtoNode` state changes to avoid the possibility of creating unencodeable forms, errors are returned where this is the case. * The builder passed in to `SetCidBuilder()` is inspected to attempt to determine if it is usable to generate CIDs, otherwise an error is returned. * The panics have been removed and replaced with default values (empty byte slice for `RawData()` and a default zero-bytes DAG-PB CID for methods involving CIDs). ### Workarounds These workarounds are available when using impacted versions to avoid panic conditions, and may be generally appropriate in order to provide meaningful feedback to users and avoid generating bad, or unexpected encoded data: * Sanitise inputs when allowing user-input to set a new `CidBuilder` on a `ProtoNode`. * Sanitise `Tsize` (`Link#Size`) values such that they are a reasonable byte-size for sub-DAGs where derived from user-input. ### References * https://github.com/ipfs/kubo/issues/9297 * https://github.com/ipfs/go-merkledag/issues/90 * https://github.com/ipfs/go-merkledag/releases/tag/v0.8.0 * https://github.com/ipfs/go-merkledag/pull/91 * https://github.com/ipfs/go-merkledag/pull/92 * https://github.com/ipfs/go-merkledag/pull/93 * https://github.com/ipfs/go-merkledag/releases/tag/v0.8.1 ### Credit Thanks to [@mrd0ll4r](https://github.com/mrd0ll4r) for reporting the original error to Kubo!

CVE-2022-23495 Affected Github.com/ipfs/go merkledag Versions

1 component(s)
Fixed Versions:
0.8.1
Product / Package Ecosystem Affected Versions Fixed Version
github.com/ipfs/go-merkledag
Go
≥ 0.4.0
< 0.8.1
0.8.1

References

Frequently Asked Questions

What is CVE-2022-23495?
CVE-2022-23495 is a security vulnerability in Github.com/ipfs/go merkledag involving go-merkledag's ProtoNode may be modified such that common method calls may panic under CWE-755: Improper Handling of Exceptional Conditions.
Which Github.com/ipfs/go merkledag versions are affected?
Affected versions include releases prior to 0.8.1 across affected packages: github.com/ipfs/go-merkledag.
What version fixes CVE-2022-23495?
Upgrading to 0.8.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/ipfs/go-merkledag affected?
Yes, github.com/ipfs/go-merkledag is affected in releases prior to 0.8.1. Upgrade your dependency to 0.8.1 or later.
What is the CVSS score of CVE-2022-23495?
CVE-2022-23495 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:N/A:H.
What CWE is associated with CVE-2022-23495?
CVE-2022-23495 is classified under CWE-755: Improper Handling of Exceptional Conditions (The product does not handle or incorrectly handles an exceptional condition.).
How can I check Go dependencies for CVE-2022-23495?
Run the dependency tree command: 'inspect dependencies for github.com/ipfs/go-merkledag'. 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-x39j-h85h-3f46",
  "modified" : "2022-12-09T15:21:18Z",
  "published" : "2022-12-08T16:12:26Z",
  "aliases" : [ "CVE-2022-23495" ],
  "summary" : "go-merkledag's ProtoNode may be modified such that common method calls may panic",
  "details" : "### Impact\n\nA `ProtoNode` may be modified in such a way as to cause various encode errors which will trigger a panic on common method calls that don't allow for error returns.\n\nA `ProtoNode` should only be able to encode to valid DAG-PB, attempting to encode invalid DAG-PB forms will result in an error from the codec. Manipulation of an existing (newly created or decoded) `ProtoNode` using the modifier methods did not account for certain states that would place the `ProtoNode` into an unencodeable form.\n\nDue to conformance with the [`github.com/ipfs/go-block-format#Block`](https://pkg.go.dev/github.com/ipfs/go-block-format#Block) and [`github.com/ipfs/go-ipld-format#Node`](https://pkg.go.dev/github.com/ipfs/go-ipld-format#Node) interfaces, certain methods, which internally require a re-encode if state has changed, will panic due to the inability to return an error.\n\nAdditionally, use of the `ProtoNode#SetCidBuilder()` method to set a non-functioning `CidBuilder` (such as one that refers to a multihash where an implementation of that hash function is not available) may cause the same methods to panic as a new CID is required but cannot be created.\n\n### Patches\n\nReleases involving fixes for this issue are [v0.8.0](https://github.com/ipfs/go-merkledag/releases/tag/v0.8.0) and [v0.8.1](https://github.com/ipfs/go-merkledag/releases/tag/v0.8.1). The recommended minimum version is **v0.8.1**.\n\n* Additional checks are performed on `ProtoNode` state changes to avoid the possibility of creating unencodeable forms, errors are returned where this is the case.\n* The builder passed in to `SetCidBuilder()` is inspected to attempt to determine if it is usable to generate CIDs, otherwise an error is returned.\n* The panics have been removed and replaced with default values (empty byte slice for `RawData()` and a default zero-bytes DAG-PB CID for methods involving CIDs).\n\n### Workarounds\n\nThese workarounds are available when using impacted versions to avoid panic conditions, and may be generally appropriate in order to provide meaningful feedback to users and avoid generating bad, or unexpected encoded data:\n\n* Sanitise inputs when allowing user-input to set a new `CidBuilder` on a `ProtoNode`.\n* Sanitise `Tsize` (`Link#Size`) values such that they are a reasonable byte-size for sub-DAGs where derived from user-input.\n\n### References\n\n* https://github.com/ipfs/kubo/issues/9297\n* https://github.com/ipfs/go-merkledag/issues/90\n* https://github.com/ipfs/go-merkledag/releases/tag/v0.8.0\n* https://github.com/ipfs/go-merkledag/pull/91\n* https://github.com/ipfs/go-merkledag/pull/92\n* https://github.com/ipfs/go-merkledag/pull/93\n* https://github.com/ipfs/go-merkledag/releases/tag/v0.8.1\n\n\n### Credit\n\nThanks to [@mrd0ll4r](https://github.com/mrd0ll4r) for reporting the original error to Kubo!",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/ipfs/go-merkledag"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.4.0"
      }, {
        "fixed" : "0.8.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/ipfs/go-merkledag/security/advisories/GHSA-x39j-h85h-3f46"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-23495"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ipfs/go-merkledag/issues/90"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ipfs/kubo/issues/9297"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ipfs/go-merkledag/pull/91"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ipfs/go-merkledag/pull/92"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ipfs/go-merkledag/pull/93"
  }, {
    "type" : "WEB",
    "url" : "https://en.wikipedia.org/wiki/Directed_acyclic_graph"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/ipfs/go-merkledag"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ipfs/go-merkledag/releases/tag/v0.8.0"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ipfs/go-merkledag/releases/tag/v0.8.1"
  }, {
    "type" : "WEB",
    "url" : "https://pkg.go.dev/vuln/GO-2022-1155"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-252", "CWE-755" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-12-08T16:12:26Z",
    "nvd_published_at" : "2022-12-08T22:15:00Z"
  }
}