Skip to content

bug: deal amount is never validated — unvalidated float string passed directly to Stellar payment operation #19

Description

@benfoster-dev

Summary

The amount in POST /api/deals comes directly from the request body and is stored in Supabase without validation. It is later passed as-is to the Stellar SDK payment operation in lockFunds and releaseFunds:

// deals.js — no validation
const { buyerSecret, seller, amount, description } = req.body;
await supabase.from('deals').insert({ buyer, seller, amount, ... });

// escrow.js — amount used directly
StellarSdk.Operation.payment({
  destination: escrowPublic,
  asset: StellarSdk.Asset.native(),
  amount: String(amount),   // ← unvalidated user input
})

Issues:

  • Negative or zero amounts: amount: -100 will cause lockFunds to throw, but the deal record has already been inserted with a bad amount
  • Precision overflow: Stellar supports at most 7 decimal places. amount: "1.000000001" causes a Stellar SDK error after the deal is written to the DB
  • String injection: amount: "100 XLM" or amount: true bypasses the falsy check and reaches the SDK

Fix

Validate amount before inserting the deal:

const parsed = parseFloat(amount);
if (!Number.isFinite(parsed) || parsed <= 0)
  return res.status(400).json({ error: 'amount must be a positive number' });
// Round to Stellar's 7 decimal places
const safeAmount = parsed.toFixed(7);

Affected files

src/routes/deals.jsPOST /
src/services/escrow.jslockFunds, releaseFunds, refund

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third CampaignbugSomething isn't workinghelp wantedExtra attention is needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions