Skip to content

fix: reject malformed amount strings in validateStringAmount#348

Open
Snowmanzx wants to merge 1 commit into
base:masterfrom
Snowmanzx:fix/strict-amount-validation
Open

fix: reject malformed amount strings in validateStringAmount#348
Snowmanzx wants to merge 1 commit into
base:masterfrom
Snowmanzx:fix/strict-amount-validation

Conversation

@Snowmanzx

Copy link
Copy Markdown

validateStringAmount used parseFloat to check the amount. parseFloat reads a leading numeric prefix and ignores the rest, so "1abc" becomes 1, "1.2.3" becomes 1.2 and "1e6" becomes 1000000. Those pass validation and only fail later in parseUnits, which expects a plain decimal string. A commenter on the issue also flagged the "1e6" scientific notation case.

Replaced the parseFloat check with a strict decimal regex. The rest of the behavior is unchanged on purpose: negative and zero amounts still throw "must be greater than 0", non string input still throws "must be a string", and the max decimal places check is untouched. All existing tests still pass.

Added a test that runs the malformed inputs through the validator and checks they are rejected.

Closes #313

validateStringAmount used parseFloat, which reads a leading numeric prefix so values like "1abc", "1.2.3" and "1e6" passed validation and only failed later in parseUnits. Replaced it with a strict decimal check. Negative and zero amounts still report must be greater than 0 as before, so existing tests keep passing.
@cb-heimdall

Copy link
Copy Markdown
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

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.

Bug: Payment amount validation accepts malformed numeric strings

2 participants