Skip to content

Commit 9293010

Browse files
committed
JS: Fix some FPs in IncorrectSuffixCheck
1 parent 649979d commit 9293010

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

javascript/ql/src/Security/CWE-020/IncorrectSuffixCheck.ql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ class UnsafeIndexOfComparison extends EqualityTest {
139139
not test.isInclusive() and
140140
value = -1
141141
)
142+
) and
143+
// Check for indexOf being <0, or <=-1
144+
not exists(RelationalComparison test |
145+
test.getLesserOperand() = indexOf.getAnEquivalentIndexOfCall().getAUse() and
146+
exists(int value | value = test.getGreaterOperand().getIntValue() |
147+
value < 0
148+
or
149+
not test.isInclusive() and
150+
value = 0
151+
)
142152
)
143153
}
144154

javascript/ql/test/query-tests/Security/CWE-020/tst.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,13 @@ function withIndexOfCheckBad(x, y) {
7979
function plus(x, y) {
8080
return x.indexOf("." + y) === x.length - (y.length + 1); // NOT OK
8181
}
82+
83+
function withIndexOfCheckLower(x, y) {
84+
let index = x.indexOf(y);
85+
return !(index < 0) && index === x.length - y.length - 1; // OK
86+
}
87+
88+
function withIndexOfCheckLowerEq(x, y) {
89+
let index = x.indexOf(y);
90+
return !(index <= -1) && index === x.length - y.length - 1; // OK
91+
}

0 commit comments

Comments
 (0)