Vulnerabilities in pkg:golang/github.com/btcsuite/btcd

PACKAGE
Advisory Identifier: GHSA-27vh-h6mc-q6g8
Advisory Summary

CVE-2024-38365 is a HIGH (CVSS 7.4) btcd did not correctly re-implement vulnerability (CWE-670: Always-Incorrect Control Flow Implementation) affecting Github.com/btcsuite/btcd libraries in the Go ecosystem. The issue involves btcd did not correctly re-implement bitcoin core's "findanddelete()" functionality. Remediation is available by upgrading affected packages to version 0.24.2-beta.rc1.

3 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:golang/github.com/btcsuite/btcd

3 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:golang/github.com/btcsuite/btcd. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-27vh-h6mc-q6g8 CVE-2024-38365 HIGH btcd did not correctly re-implement Bitcoin Core's "FindAndDelete()" functionality
GHSA-3jgf-r68h-xfqm CVE-2024-34478 MODERATE btcd susceptible to consensus failures
GHSA-2chg-86hq-7w38 CVE-2022-44797 CRITICAL btcd mishandles witness size checking

CVE-2024-38365 at a Glance

CVE Identifier CVE-2024-38365
GHSA Identifier GHSA-27vh-h6mc-q6g8
Severity HIGH
CVSS v3.1 Base Score 7.4
CWE Classification CWE-670: Always-Incorrect Control Flow Implementation
Affected Product Github.com/btcsuite/btcd
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 7.4

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

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

How to Fix CVE-2024-38365

To remediate this vulnerability, upgrade all affected Github.com/btcsuite/btcd 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/btcsuite/btcd fixed: 0.24.2-beta.rc1
Upgrade github.com/btcsuite/btcd to 0.24.2-beta.rc1
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/btcsuite/btcd

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-38365, inspect your project dependencies for Github.com/btcsuite/btcd:

inspect dependencies for github.com/btcsuite/btcd

Analyze the terminal output to locate any version of Github.com/btcsuite/btcd in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.24.2-beta.rc1), 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-670: Always-Incorrect Control Flow Implementation, where the code contains a control flow path that does not reflect the algorithm that the path is intended to implement, leading to incorrect behavior any time this path is navigated. In Github.com/btcsuite/btcd, 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 The btcd Bitcoin client (versions 0.10 to 0.24) did not correctly re-implement Bitcoin Core's "FindAndDelete()" functionality. This logic is consensus-critical: the difference in behavior with the other Bitcoin clients can lead to btcd clients accepting an invalid Bitcoin block (or rejecting a valid one). This consensus failure can be leveraged to cause a chain split (accepting an invalid Bitcoin block) or be exploited to DoS the btcd nodes (rejecting a valid Bitcoin block). An attacker can create a standard transaction where FindAndDelete doesn't return a match but removeOpCodeByData does making btcd get a different sighash, leading to a chain split. Importantly, this vulnerability can be exploited remotely by any Bitcoin user and does not require any hash power. This is because the difference in behavior can be triggered by a "standard" Bitcoin transaction, that is a transaction which gets relayed through the P2P network before it gets included in a Bitcoin block. #### `FindAndDelete` vs. `removeOpcodeByData` `removeOpcodeByData(script []byte, dataToRemove []byte)` removes any data pushes from `script` that *contain* `dataToRemove`. However, `FindAndDelete` only removes *exact* matches. So for example, with `script = "<data> <data||foo>"` and `dataToRemove = "data"` btcd will remove both data pushes but Bitcoin Core's `FindAndDelete` only removes the first `<data>` push. ### Patches This has been patched in `btcd` version v0.24.2-beta. ### References `FindAndDelete`: https://github.com/btcsuite/btcd/security/advisories/GHSA-27vh-h6mc-q6g8

CVE-2024-38365 Affected Github.com/btcsuite/btcd Versions

1 component(s)
Fixed Versions:
0.24.2-beta.rc1
Product / Package Ecosystem Affected Versions Fixed Version
github.com/btcsuite/btcd
Go
< 0.24.2-beta.rc1
0.24.2-beta.rc1

References

Frequently Asked Questions

What is CVE-2024-38365?
CVE-2024-38365 is a security vulnerability in Github.com/btcsuite/btcd involving btcd did not correctly re-implement Bitcoin Core's "FindAndDelete()" functionality under CWE-670: Always-Incorrect Control Flow Implementation.
Which Github.com/btcsuite/btcd versions are affected?
Affected versions include releases prior to 0.24.2-beta.rc1 across affected packages: github.com/btcsuite/btcd.
What version fixes CVE-2024-38365?
Upgrading to 0.24.2-beta.rc1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/btcsuite/btcd affected?
Yes, github.com/btcsuite/btcd is affected in releases prior to 0.24.2-beta.rc1. Upgrade your dependency to 0.24.2-beta.rc1 or later.
What is the CVSS score of CVE-2024-38365?
CVE-2024-38365 has a CVSS v3.1 base score of 7.4 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:H/A:H.
What CWE is associated with CVE-2024-38365?
CVE-2024-38365 is classified under CWE-670: Always-Incorrect Control Flow Implementation (The code contains a control flow path that does not reflect the algorithm that the path is intended to implement, leading to incorrect behavior any time this path is navigated.).
How can I check Go dependencies for CVE-2024-38365?
Run the dependency tree command: 'inspect dependencies for github.com/btcsuite/btcd'. 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-27vh-h6mc-q6g8",
  "modified" : "2025-08-21T04:05:13Z",
  "published" : "2024-10-10T16:43:17Z",
  "aliases" : [ "CVE-2024-38365" ],
  "summary" : "btcd did not correctly re-implement Bitcoin Core's \"FindAndDelete()\" functionality",
  "details" : "### Impact\n\nThe btcd Bitcoin client (versions 0.10 to 0.24) did not correctly re-implement Bitcoin Core's \"FindAndDelete()\" functionality. This\nlogic is consensus-critical: the difference in behavior with the other Bitcoin clients can lead to btcd clients accepting an invalid Bitcoin block (or rejecting a valid one). \n\nThis consensus failure can be leveraged to cause a chain split (accepting an invalid Bitcoin block) or be exploited to DoS the btcd nodes (rejecting a valid Bitcoin block). An attacker can create a standard transaction where FindAndDelete doesn't return a match but removeOpCodeByData does making btcd get a different sighash, leading to a chain split. Importantly, this vulnerability can be exploited remotely by any Bitcoin user and does not require any hash power. This is because the difference in behavior can be triggered by a \"standard\" Bitcoin\ntransaction, that is a transaction which gets relayed through the P2P network before it gets included in a Bitcoin block.\n\n#### `FindAndDelete` vs. `removeOpcodeByData`\n\n`removeOpcodeByData(script []byte, dataToRemove []byte)` removes any data pushes from `script` that *contain* `dataToRemove`. However, `FindAndDelete` only removes *exact* matches. So for example, with `script = \"<data> <data||foo>\"` and `dataToRemove = \"data\"` btcd will remove both data pushes but Bitcoin Core's `FindAndDelete` only removes the first `<data>` push.\n\n\n### Patches\n\nThis has been patched in `btcd` version v0.24.2-beta. \n\n### References\n\n`FindAndDelete`: https://github.com/btcsuite/btcd/security/advisories/GHSA-27vh-h6mc-q6g8",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:H/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/btcsuite/btcd"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.24.2-beta.rc1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/btcsuite/btcd/security/advisories/GHSA-27vh-h6mc-q6g8"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-38365"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/btcsuite/btcd/commit/04469e600e7d4a58881e2e5447d19024e49800f5"
  }, {
    "type" : "WEB",
    "url" : "https://delvingbitcoin.org/t/cve-2024-38365-public-disclosure-btcd-findanddelete-bug/1184"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/btcsuite/btcd"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/btcsuite/btcd/releases/tag/v0.24.2"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-670" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-10-10T16:43:17Z",
    "nvd_published_at" : "2024-10-11T20:15:04Z"
  }
}