diff --git a/backend/src/api/bitcoin/bitcoin.routes.ts b/backend/src/api/bitcoin/bitcoin.routes.ts index e6075ffa2..42ab9f935 100644 --- a/backend/src/api/bitcoin/bitcoin.routes.ts +++ b/backend/src/api/bitcoin/bitcoin.routes.ts @@ -143,17 +143,14 @@ class BitcoinRoutes { } private getTransactionTimes(req: Request, res: Response) { - if (!Array.isArray(req.query.txId)) { - handleError(req, res, 500, 'Not an array'); + if (!req.query.txId || typeof req.query.txId !== 'object') { + handleError(req, res, 500, 'invalid txId format'); return; } const txIds: string[] = []; - for (const _txId in req.query.txId) { - if (typeof req.query.txId[_txId] === 'string') { - const txid = req.query.txId[_txId].toString(); - if (TXID_REGEX.test(txid)) { - txIds.push(txid); - } + for (const txid of Object.values(req.query.txId)) { + if (typeof txid === 'string' && TXID_REGEX.test(txid)) { + txIds.push(txid); } } diff --git a/backend/src/api/explorer/channels.routes.ts b/backend/src/api/explorer/channels.routes.ts index 031aeea17..71bc77280 100644 --- a/backend/src/api/explorer/channels.routes.ts +++ b/backend/src/api/explorer/channels.routes.ts @@ -78,17 +78,14 @@ class ChannelsRoutes { private async $getChannelsByTransactionIds(req: Request, res: Response): Promise { try { - if (!Array.isArray(req.query.txId)) { - handleError(req, res, 400, 'Not an array'); + if (!req.query.txId || typeof req.query.txId !== 'object') { + handleError(req, res, 400, 'invalid txId format'); return; } const txIds: string[] = []; - for (const _txId in req.query.txId) { - if (typeof req.query.txId[_txId] === 'string') { - const txid = req.query.txId[_txId].toString(); - if (TXID_REGEX.test(txid)) { - txIds.push(txid); - } + for (const txid of Object.values(req.query.txId)) { + if (typeof txid === 'string' && TXID_REGEX.test(txid)) { + txIds.push(txid); } } const channels = await channelsApi.$getChannelsByTransactionId(txIds);