🛡️ CVE-2024-41945 — account

🟢 CVSS 3.1 — Low ✅ No Known Exploit CWE-20 NVD
3.1
CVSS Score
0 Low4 Medium7 High9 Critical10

Description

The fuels-ts typescript SDK has no awareness of to-be-spent transactions

# Brief/Intro

The typescript SDK has no awareness of to-be-spent transactions causing some transactions to fail or silently get pruned as they are funded with already used UTXOs.

The Typescript SDK provides the fund function which retrieves UTXOs, which belong to the owner and can be used to fund the request in question, from fuel's graphql api. These then get added to the request making it possible to send it to the network as it now has inputs which can be spent by its outputs. Now this works when a user only wants to fund one transaction per block as in the next block, the spent UTXO will not exist anymore. However if a user wants to fund multiple transactions within one block, the following can happen:

It is important to note, that the graphql API will return a random UTXO which has enough value to fund the transaction in question.

  • user has 2 spendable UTXOs in their wallet which can cover all expenses
  • user funds transaction tA with an input gotten from the API iA
  • user submits tA to fuel
  • iA is still in possession of the user as no new block has been produced
  • user funds a transaction tB and gets the same input iA from the API
  • user tries to submit transaction tB to fuel but now one of the following can happen:
  • if the recipient and all other parameters are the same as in tA, submission will fail as tB will have the same txHash as tA
  • if the parameters are different, there will be a collision in the txpool and tA will be removed from the txpool

# Vulnerability Details

The problem occurs, because the fund function in fuels-ts/packages/account/src/account.ts gets the needed ressources statelessly with the function getResourcesToSpend without taking into consideration already used UTXOs:

```ts

async fund<T extends TransactionRequest>(request: T, params: EstimatedTxParams): Promise<T> {

// [...]

let missingQuantities: CoinQuantity[] = [];

Object.entries(quantitiesDict).forEach(([assetId, { owned, required }]) => {

if (owned.lt(required)) {

missingQuantities.push({

assetId,

amount: required.sub(owned),

});

}

});

let needsToBeFunded = missingQuantities.length > 0;

let fundingAttempts = 0;

while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {

const resources = await this.getResourcesToSpend(

missingQuantities,

cacheRequestInputsResourcesFromOwner(request.inputs, this.address)

); // @audit-issue here we do not exclude ids we already got and used for another transaction in the current block

request.addResources(resources);

// [...]

}

// [...]

return request;

}

```

# Impact Details

This issue will lead to unexpected SDK behaviour. Looking at the scenario in Brief/Intro, it could have the following impacts for users:

1. A transaction does not get included in the txpool / in a block

1. A previous transaction silently gets removed from the txpool and replaced with a new one

# Recommendation

I would recommend adding a buffer to the Account class, in which retrieved resources are saved. These can then be provided to getResourcesToSpend to be excluded from future queries but need to be removed from the buffer if their respective transaction fails to be included, in order to be able to use those resources again in such cases.

# Proof of Concept

The following PoC transfers 100 coins from wallet2 to wallet after which wallet2 has two UTXOs one with value 100 and one with a very high value (this is printed to the console). Afterwards, wallet will attempt transfering 80 coins back to wallet2 twice in one block, each in a separate transaction. This should work perfectly fine as wallet has two UTXOs where each can cover the cost of each respective transaction. Now when running this one of the following will happen:

1. both transfers from wallet to wallet2 get a different UTXO. This is the case if execution is successful and wallet2 has 80 coins more than wallet in the end.

1. both transfers get the same UTXO. In this case the script will fail and throw an error as then both transactions will have the same hash

In order to execute this PoC, please deploy a local node with a blocktime of 5secs as I wrote my PoC for that blocktime. Note that with a small change it will also work with other blocktimes. Then add the PoC to a file poc_resources.ts and compile it with tsc poc_resources.ts. Finally execute it with node poc_resources.js.

Since the choice which UTXO is taken as input is random, it might take a few tries to trigger the bug!

```ts

import { JsonAbi, Script, Provider, WalletUnlocked, Account, Predicate, Wallet, CoinQuantityLike, coinQuantityfy, EstimatedTxParams, BN, Coin, AbstractAddress, Address, Contract, ScriptTransactionRequest } from 'fuels';

const abi: JsonAbi =

How this vulnerability can be exploited

This issue can be reached over the network, attack complexity is high, an attacker needs low-level privileges on the target. No user interaction is required. The scope is unchanged, so the impact stays within the vulnerable component. Rated impact: confidentiality none, integrity low, availability none.

Weakness class

CVE-2024-41945 is classified as CWE-20: Improper Input Validation. The application accepts input without checking that it has the expected form, so malformed values reach code that assumes they are well formed.

Affected software

CVE-2024-41945 is recorded against 2 packages.

  • @fuel-ts/account
  • unknown

Timeline and source

Published on 30 July 2024. No public exploit is currently recorded for this entry. Record sourced from NVD.

References

github.com (Web)
nvd.nist.gov (Advisory)
github.com (Web)
github.com (Package)

Details

Severity LOW
CVSS Score 3.1
CVSS Vector CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:N
CWE CWE-20
Public Exploit ✅ No
Source NVD
Published 2024-07-30
Updated 2026-08-12
Modified 2024-07-30
Fix URL N/A

Affected Packages

Software From version Fixed in
@fuel-ts/account
unknown

Free Vulnerability Check

Is your site affected by CVE-2024-41945?

BotEraser helps you identify potentially vulnerable plugins and themes by checking your installation against CVE-2024-41945 and other known CVE records.

Scan My Site Free →

No credit card required  ·  Results in minutes

ⓘ Data Notice: The information presented above has been compiled from publicly available internet sources. Boteraser aggregates this data solely for informational purposes and does not independently classify, evaluate, or endorse any findings about the vulnerabilities listed. The accuracy and completeness of this information is the sole responsibility of the original publishers. Boteraser and its operators accept no liability for any decisions made based on this data.