fix(account): tighten payment input validation#322
Open
Kubudak90 wants to merge 1 commit into
Open
Conversation
validateStringAmount now requires a strict decimal literal (`^\d+(\.\d+)?$`) so malformed inputs like '1abc' or '1.2.3' can't slip past parseFloat — which previously read only the numeric prefix and silently truncated the rest. Closes base#313. subscribe() now validates periodInDays and overridePeriodInSecondsForTestnet as positive safe integers within the uint48 range used by spend-permission typed data, called at the same point as the existing input validation. Zero, negative, fractional, NaN, Infinity, and out-of-range values now fail fast with a clear error instead of reaching wallet_sign. Closes base#314. Also exports a reusable validatePositiveSafeInteger helper and the UINT48_MAX constant. Tests: - 12 new assertions in validation.test.ts covering the strict format and the positive-safe-integer helper. - 11 new assertions in subscribe.test.ts covering both period parameters, including the uint48 upper bound. - Existing '-10' assertion message updated (still rejects; the new message is more accurate).
Collaborator
🟡 Heimdall Review Status
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two bugs in
@base-org/accountpayment validation, fixed together because they sharevalidation.ts:validateStringAmountusedparseFloat, which silently accepts inputs like"1abc"or"1.2.3"by reading only the numeric prefix. The function now requires a strict decimal literal^\d+(\.\d+)?$, so malformed amounts fail immediately with a clear error rather than reaching downstream payment encoding with a truncated value.subscribe()did not boundperiodInDaysoroverridePeriodInSecondsForTestnet, so0, negative, fractional,NaN,Infinity, or values aboveuint48could reachwallet_sign. A newvalidatePositiveSafeInteger(value, fieldName, max?)helper enforces a positive safe integer (optionally bounded byUINT48_MAX = 281474976710655), called at the same point as the existing input validation insubscribe().pay()benefits from the strictervalidateStringAmountautomatically, since it calls the same validator.Changes
validation.tsSTRICT_DECIMAL_RErejects malformed/scientific/whitespace;validatePositiveSafeIntegerhelper;UINT48_MAXconstant exportedsubscribe.tsvalidation.test.tsvalidatePositiveSafeInteger(positive/zero/negative/non-integer/non-number/max-bound/unsafe-integer)subscribe.test.tsit.eachover both period parameters for zero/negative/non-integer/NaN/Infinity; uint48 upper-bound rejectionBehavior changes worth noting
validateStringAmount("-10", 6)previously threw"Invalid amount: must be greater than 0"; now throws"Invalid amount: must be a valid number". Still rejects negatives — the message is just more accurate (negative-sign also fails the strict-decimal format check first). Existing test updated.validatePositiveSafeInteger,UINT48_MAX) are additive.Test Plan
yarn vitest run src/interface/payment/utils/validation.test.ts src/interface/payment/subscribe.test.ts→ 42 / 42 passing.master; two test files (pay.test.ts,base.test.ts) fail at the Vite transform stage withFailed to resolve import "./Dialog-css.js"— verified to fail identically on the unmodifiedmasterbaseline (pre-existing).biome check --writeapplied to the four touched files; no new diagnostics from my diff.Closes #313
Closes #314