The vulnerability lies in the bsv-sdk and bsv-wallet gems, specifically within the BSV::Wallet::WalletClient class in lib/bsv/wallet_interface/wallet_client.rb. The core issue is a failure to verify cryptographic signatures on identity certificates, as required by the BRC-52 specification. This allows an attacker to forge certificates.
The analysis of the patch commit 4992e8a265fd914a7eeb0405c69d1ff0122a84cc reveals the exact locations of the vulnerability. The two primary vulnerable functions are acquire_via_direct and acquire_via_issuance.
-
BSV::Wallet::WalletClient.acquire_via_direct: This function handles the 'direct' acquisition protocol, where a caller provides all certificate data. The vulnerability was that it accepted the signature field from the caller without any verification and passed it on for storage. An attacker could simply provide arbitrary bytes as a signature.
-
BSV::Wallet::WalletClient.acquire_via_issuance: This function handles the 'issuance' protocol, where the client communicates with a certifier's HTTP endpoint. The vulnerability was that it trusted the signature provided in the HTTP response from the endpoint without verification. This allows a malicious endpoint (or an attacker performing a MITM attack on an HTTP connection) to forge a certificate.
The parent function, BSV::Wallet::WalletClient.acquire_certificate, orchestrates this process. It calls one of the two vulnerable helper methods based on the acquisition_protocol and then writes the resulting certificate record to the wallet's storage. Therefore, during exploitation, all three functions would likely appear in a runtime profile's stack trace.
The patch introduces a new module, BSV::Wallet::CertificateSignature, which contains the logic to correctly verify BRC-52 certificate signatures. The fix involves adding calls to CertificateSignature.verify! within both acquire_via_direct and acquire_via_issuance before they return the certificate data, thus ensuring that no unverified certificate is ever persisted.