Skip to content

Commit 3944479

Browse files
authored
Merge pull request #2860 from DFXswiss/fix/unassigned-transaction-refund-ownership-check (#2863)
fix: correct ownership check for unassigned transaction refunds Co-authored-by: TaprootFreak <142087526+TaprootFreak@users.noreply.github.com>
2 parents 1b598c0 + 827de50 commit 3944479

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/subdomains/core/history/controllers/transaction.controller.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,15 @@ export class TransactionController {
323323
if (transaction.refundTargetEntity instanceof BankTx) {
324324
// Unassigned transaction
325325
if (!BankTxTypeUnassigned(transaction.bankTx.type)) throw new NotFoundException('Transaction not found');
326-
const txOwner = await this.bankTxService.getUserDataForBankTx(transaction.bankTx, jwt.account);
327-
if (jwt.account !== transaction.userData?.id || txOwner.id !== jwt.account)
326+
327+
// Check ownership (consistent with requestRefund logic)
328+
if (transaction.userData && jwt.account !== transaction.userData.id)
328329
throw new ForbiddenException('You can only refund your own transaction');
330+
if (!transaction.userData) {
331+
const txOwner = await this.bankTxService.getUserDataForBankTx(transaction.bankTx, jwt.account);
332+
if (txOwner?.id !== jwt.account) throw new ForbiddenException('You can only refund your own transaction');
333+
}
334+
329335
if (transaction.refundTargetEntity.bankTxReturn)
330336
throw new BadRequestException('You can only refund a transaction once');
331337

@@ -421,7 +427,7 @@ export class TransactionController {
421427
throw new ForbiddenException('You can only refund your own transaction');
422428
if (!transaction.targetEntity && !transaction.userData) {
423429
const txOwner = await this.bankTxService.getUserDataForBankTx(transaction.bankTx, jwt.account);
424-
if (txOwner.id !== jwt.account) throw new ForbiddenException('You can only refund your own transaction');
430+
if (txOwner?.id !== jwt.account) throw new ForbiddenException('You can only refund your own transaction');
425431
}
426432

427433
const refundData = this.refundList.get(transaction.id);

0 commit comments

Comments
 (0)