Repository navigation
JS: Stop treating parseInt and parseFloat as whole-string number guards - #23121
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The shared guard change can introduce prototype-pollution false positives for numerically guarded keys, requiring a query-specific guard and regression coverage.
2 open issues
What changed in this PR
This PR corrects JavaScript taint analysis so numeric-prefix parsing no longer sanitizes the original string, allowing injection queries to detect trailing payloads.
Changes:
- Removes
parseIntandparseFloathandling fromisNumberGuard, preserving whole-value checks. - Updates
parseIntalert expectations and addsparseFloatregression coverage plus a safe parsed-value case. - Adds a change note describing potentially newly reported alerts.
| File | Description |
|---|---|
javascript/ql/test/query-tests/Security/CWE-078/UnsafeShellCommandConstruction/UnsafeShellCommandConstruction.expected |
Records alerts for unsafe numeric-prefix guards. |
javascript/ql/test/query-tests/Security/CWE-078/UnsafeShellCommandConstruction/lib/lib.js |
Updates guard expectations and adds regression cases. |
javascript/ql/lib/semmle/javascript/dataflow/TaintTracking.qll |
Stops treating prefix parsing as whole-string validation. |
javascript/ql/lib/change-notes/2026-11-12-isnumberguard-parseint.md |
Documents the analysis change and affected alerts. |
Review effort: Max (auto)
| @@ -989,13 +989,6 @@ module TaintTracking { | |||
| | | |||
| operand = isNaN.getArgument(0).asExpr() | |||
| or | |||
Contributor
There was a problem hiding this comment.
This should be investigated before merging.
| @@ -989,13 +989,6 @@ module TaintTracking { | |||
| | | |||
| operand = isNaN.getArgument(0).asExpr() | |||
| or | |||
owen-mc
previously approved these changes
Nov 12, 2026
sam-robson
force-pushed
the
sam-robson/js-isnumberguard-parseint
branch
from
November 13, 2026 09:56
0d6c833 to
162de33
Compare
owen-mc
requested changes
Nov 13, 2026
Comment on lines
-992
to
-998
| exists(DataFlow::CallNode parse | | ||
| parse = DataFlow::globalVarRef(["parseInt", "parseFloat"]).getACall() | ||
| | | ||
| parse = isNaN.getArgument(0) and | ||
| operand = parse.getArgument(0).asExpr() | ||
| ) | ||
| or |
Contributor
There was a problem hiding this comment.
A corresponding disjunct should be added to the characteristic predicate of NumberGuard for prototype pollution, as the case that is being removed is still valid for the purpose of that class.
owen-mc
approved these changes
Nov 13, 2026
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.


Fixes #23115
Summary
TaintTracking::isNumberGuardtreatedisNaN(parseInt(x))andisNaN(parseFloat(x))as checks thatxis a number. Both functions read only a leading numeric prefix and ignore trailing characters, so the original stringxcan still carry a payload to a sink. Remove theparseIntandparseFloatbranch fromisNumberGuard. Whole-value checks such asisNaN(x),isNaN(+x),isNaN(x - 0), andtypeof x === "number"remain unchanged.Evidence
codeql test runpasses onUnsafeShellCommandConstructionand the otherisNumberGuardquery suites.