Why Direct-to-Bank UPI Integrations Require Strict Security Invariants
Every online payment architecture—whether Visa/Mastercard, Razorpay, or direct NPCI UPI—faces attackers probing for logic flaws. In custom UPI integrations, real exploits rarely break cryptography inside banking apps; instead, they target sloppy merchant code that trusts browser parameters, skips settled amount verification, or fails to deduplicate 12-digit UTR numbers.
Attack Vectors & Exact UPIGateway.dev Defenses
| Attack Vector | How Attackers Attempt It | How UPIGateway.dev Stops It |
|---|---|---|
| DevTools Request Price Edit | Altering JSON `amount: 1` inside browser Network tab before order creation | Server-derived `product_id` pricing in PostgreSQL + merchant server-side catalog lookup rule |
| Edited Mobile Transfer (Underpaying) | Modifying UPI amount to ₹1 for a ₹999 order during checkout | Verifier compares settled rupee total vs `order.amount`; flags `FLAGGED_UNDERPAID` and returns `status: false` |
| UTR Replay / Screenshot Reuse | Submitting an old 12-digit bank reference from last week to verify a fresh order | Strict post-order timestamp guard (`alert >= create_date`) + atomic PostgreSQL `utr` uniqueness lock |
| Forged Redirect Query Parameters | Manually loading `/payment-success?status=SUCCESS&order_id=...` in browser address bar | Backend always calls `POST /api/check-order-status` directly and ignores unsigned query params |
Exact `FLAGGED_UNDERPAID` Response Contract
{
"status": false,
"message": "Payment rejected: Underpaid transaction detected",
"result": {
"txnStatus": "FAILED",
"orderId": "ORD_1732948102",
"status": "FLAGGED_UNDERPAID",
"amount": "999",
"date": "2026-11-30T08:12:00.000Z",
"utr": "433412345678",
"redirect_url": null
}
}
4-Point Developer Verification Checklist
- Verify `UPIGATEWAY_USER_TOKEN` exists strictly inside server `.env`, never in `VITE_*` or `NEXT_PUBLIC_*` browser builds.
- Inspect ALL four response fields before crediting customers: `resp.status === true`, `resp.result.status === 'SUCCESS'`, `resp.result.txnStatus === 'COMPLETED'`, and `Number(resp.result.amount) >= expectedOrderAmount`.
- Enforce `UNIQUE (utr)` and `WHERE status = 'PENDING'` conditional SQL updates inside your own orders ledger.
- Always verify `result.status !== 'FLAGGED_UNDERPAID'` and log underpaid attempts cleanly for fraud auditing.
Reference Webhook Verification Function Rejecting Underpaid Orders
export async function verifyStrictOrder(orderId, expectedAmountInr) {
const resp = await fetch("https://upigateway.dev/api/check-order-status", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
user_token: process.env.UPIGATEWAY_USER_TOKEN,
order_id: orderId,
}),
});
const body = await resp.json();
if (!body.status || body.result?.status === "FLAGGED_UNDERPAID") {
return { verified: false, reason: body.result?.status || "REJECTED" };
}
const paid = Number(body.result?.amount || 0);
const ok = body.result?.status === "SUCCESS" && body.result?.txnStatus === "COMPLETED" && paid >= expectedAmountInr && Boolean(body.result?.utr);
return { verified: ok, utr: body.result?.utr || null, paid };
}