You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Number.parseInt and Number.parseFloat accept numeric prefixes while silently ignoring trailing input. As a result, malformed CLI option values such as 10foo, 1.9 (for integers), 0.5oops, and 0.01% were accepted. Non-finite values such as Infinity could also pass float parsing.
Solution
Validate the entire input before conversion and require the result to be finite:
integers accept only signed decimal integer strings, rejecting decimals, exponents, hexadecimal input, and suffixes;
floats retain valid forms such as .5, 1., and 1e-2, while rejecting suffixes and non-finite results;
regression tests cover both the rejected inputs and the valid float forms.
Validation completed with Node 24.14.1:
focused parse tests: 25 passed;
full test suite: 438 passed, 2 skipped;
type-check, lint, and build passed.
As this repository is a public read-only mirror, maintainers can recreate this change in the internal monorepo as described in CONTRIBUTING.md.
Thanks for this, and for the clear write-up and tests. This repo is a read-only mirror, so we've recreated the change in our internal monorepo with you credited as co-author on the commit. It will ship in the next @opensea/cli release.
We made one small change: the integer helper checks Number.isSafeInteger instead of Number.isFinite. A string that already matches ^[+-]?\d+$ is finite unless it runs past 308 digits, and --before/--after take Unix timestamps, where silent rounding above 2^53 is the case worth catching. We also added a trailing-newline case to each rejection table.
Because inputs like 10foo used to be accepted, this goes out as a minor version bump rather than a patch.
Closing this PR since the change now lives in the monorepo. Appreciate you taking the time!
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
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.
Motivation
Number.parseIntandNumber.parseFloataccept numeric prefixes while silently ignoring trailing input. As a result, malformed CLI option values such as10foo,1.9(for integers),0.5oops, and0.01%were accepted. Non-finite values such asInfinitycould also pass float parsing.Solution
Validate the entire input before conversion and require the result to be finite:
.5,1., and1e-2, while rejecting suffixes and non-finite results;Validation completed with Node 24.14.1:
As this repository is a public read-only mirror, maintainers can recreate this change in the internal monorepo as described in
CONTRIBUTING.md.