Fintech wallet
Fix the vulnerability in this mobile money transfer code
Validate account ownership, bind transfers to signed intents, and prevent client-side amount manipulation.
app.post("/transfer", async (req, res) => {
const { fromWallet, toWallet, amount } = req.body;
// Vulnerable: trusts client-supplied wallet and amount.
await ledger.debit(fromWallet, amount);
await ledger.credit(toWallet, amount);
res.json({ status: "sent" });
});Derive the source wallet from the authenticated session, enforce server-side limits, require idempotency keys, and sign the transfer intent before ledger mutation.