SyncStateDataGlobals will not work, effectively DoS'ing nodes
The archiver's account lookup builds a SQL IN clause with a single placeholder, so a request containing more than one account ID fails. A restoring node that asks for several accounts at once therefore cannot sync, which can deny service to that node.
Originally disclosed on Immunefi
- Disclosed after under an hour
#39109 [W&A-Insight] syncStateDataGlobals will not work, effectively DoS'ing nodes
Submitted on Jan 22nd 2025 at 12:40:06 UTC by @br0nz3p1ck4x3 for Audit Comp | Shardeum: Ancillaries III
- Report ID: #39109
- Report Type: Websites and Applications
- Report severity: Insight
- Target: https://github.com/shardeum/archive-server/tree/itn4
- Impacts:
- DOS
Description
Description
Inside src/state-manager/ArchiverSyncTracker::syncStateDataGlobals(), we find the following function that is being executed:
const getAccountDataByListFromArchiver = async (payload) => {
const dataSourceArchiver = this.archiverDataSourceHelper.dataSourceArchiver
const accountDataByListArchiverUrl = `http://${dataSourceArchiver.ip}:${dataSourceArchiver.port}/get_account_data_by_list_archiver`
try {
const result = await http.post(accountDataByListArchiverUrl, payload, false, 10000)
console.log('getAccountDataByListFromArchiver result', result)
return result
} catch (error) {
console.error('getAccountDataByListFromArchiver error', error)
return null
}
}
const result = await getAccountDataByListFromArchiver(signedMessage)
A POST call is made to the archiver. The payload of this call will be an array of accountIds.
The problem is, if the length of this array is more than 1, this call will return an error.
Root Cause Analysis
The root cause is the following line in the archiver repo:AccountDataProvider.ts#L269
const sql = `SELECT * FROM accounts WHERE accountId IN (?)`;
When using (?), SQLite expects a single value, not an array. To properly handle an array of values with an IN clause, you need to create the correct number of parameter placeholders based on the array length.
Impact
When the node is restoring and trying to sync, it will not be able to sync when fetching more than one accountIds, leading to an effective Denial of Service of the restoring node.
Recommendation
Change the query such that it accommodates for multiple values inside the array. If you don't want to use multiple values, consider not using an array but a normal, constant value.
Link to Proof of Concept
https://gist.github.com/bronzepickaxe/fdbf068728a5262e8611624619370df1
Proof of Concept
Proof of Concept
Check the gist here:
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The SQL query uses a single placeholder for an IN clause, but the code passes an array of account IDs, which SQLite does not expand into multiple placeholders.
Impact
A restoring node that requests more than one account ID cannot sync, effectively denying service to that node.
What the attacker needed
Node is restoring and syncing; request contains more than one account ID
The fix
The query should be changed to create the correct number of placeholders for the array length, or to use a single constant value instead of an array.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A node that is catching up asks an archiver for details about several accounts in one request. The archiver's database query was written to accept only one account at a time, so the request fails. The node cannot finish syncing and stays out of service.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.