Skip to content

fix: reject unquoted numeric JSON amounts to prevent silent rounding - #727

Merged
jahrulezfrancis merged 1 commit into
Batch-Pay:mainfrom
alade-dev:fix/prevent-silent-numeric-rounding
Jul 31, 2026
Merged

fix: reject unquoted numeric JSON amounts to prevent silent rounding#727
jahrulezfrancis merged 1 commit into
Batch-Pay:mainfrom
alade-dev:fix/prevent-silent-numeric-rounding

Conversation

@alade-dev

@alade-dev alade-dev commented Jul 30, 2026

Copy link
Copy Markdown

When users submit JSON payment instructions with unquoted numeric amounts (e.g., 99999999999.9999999 instead of "99999999999.9999999"), JSON.parse() applies IEEE-754 floating-point rounding before validation occurs. This silently alters critical payment values — for example, 99999999999.9999999 becomes 100000000000 and 0.0000001 can become 1e-7. This can lead to incorrect payment amounts being processed without any error.
Issue: #714

Solution

The parseJSON() function now explicitly checks the type of each amount field after parsing. If item.amount is a number (unquoted), the parser throws a descriptive row-level error instructing the user to quote the amount as a string, e.g.:
Row 1: amount must be a quoted string, not a number (received 99999999999.9999999)
This prevents silent data corruption by failing fast at the input validation stage.

Changes

  • lib/stellar/parser.ts: Added type check to reject numeric amount values with a clear error message.
  • tests/parser.test.ts: Added 4 new test cases covering:
    • Rejection of large unquoted decimals
    • Rejection of tiny unquoted decimals (scientific notation case)
    • Rejection of unquoted integers
    • Acceptance of quoted string amounts for large and tiny values

Backward Compatibility

This is a breaking change for malformed inputs only — any JSON that previously worked with unquoted numeric amounts will now fail with an explicit error. All correctly-formatted JSON (amounts as quoted strings) is unaffected.

Closes #714

JSON.parse() applies IEEE-754 rounding before validation, silently altering
payment values like 99999999999.9999999 → 100000000000. The parseJSON()
function now explicitly rejects numeric amount values with a row-level
error directing users to quote amounts as strings.

Fixes Batch-Pay#714
@vercel

vercel Bot commented Jul 30, 2026

Copy link
Copy Markdown

@wseng is attempting to deploy a commit to the indexhtml's projects Team on Vercel.

A member of the Team first needs to authorize it.

@jahrulezfrancis

Copy link
Copy Markdown
Collaborator

@alade-dev Provide a more detailed description for your PR, it helps with backlogs.

@alade-dev

Copy link
Copy Markdown
Author

Done

@jahrulezfrancis
jahrulezfrancis self-requested a review July 31, 2026 11:21

@jahrulezfrancis jahrulezfrancis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alade-dev Looks good to me. Thanks for your contributions

@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stellar-batch-pay Ready Ready Preview Jul 31, 2026 11:24am

@jahrulezfrancis
jahrulezfrancis merged commit 29b323b into Batch-Pay:main Jul 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent silent rounding of numeric amounts in JSON payment uploads

2 participants