00:00

#1004

Refund Exceeds Total

Easy+50 XPA04:2021 Insecure DesignCWE-840
Business LogicRefund Validation

Scenario

Your platform's refund service allows customers to request partial or full refunds on orders via processRefund(orderId, refundAmount, orderTotal).

The function currently performs no validation — an attacker can request a refund larger than the original order total, causing the platform to overpay, or a negative or zero refund amount.

This type of business logic flaw can be exploited to extract funds beyond what was paid, making it a serious financial risk.

Refund manipulation is a well-known payment fraud technique. Without server-side validation of refund bounds, attackers can drain platform balances through repeated over-refund requests.

Your Tasks

  1. Throw 'Invalid refund amount' if refundAmount is less than or equal to zero.
  2. Throw 'Refund exceeds order total' if refundAmount is greater than orderTotal.
  3. Return { refunded: refundAmount, remaining: orderTotal - refundAmount } for valid inputs.

Examples

Example 1Refund larger than order (bug)

processRefund('ord-1', 200, 100)
// returns { refunded: 200, remaining: -100 } — overpaid!

Example 2Blocked (fix)

processRefund('ord-1', 200, 100)
// throws Error('Refund exceeds order total')

Constraints

  • Validate zero/negative before checking against the order total.
  • A refund equal to the full order total is valid (full refund).
  • Do not modify the function signature.

Hint

References

solution.js
Ln 1, Col 1UTF-8JavaScript
Sandbox ready
0/0/0not run