Skip to content

Commit e899250

Browse files
authored
Merge pull request #1894 from asger-semmle/fp-incorrect-suffix-check
Approved by xiemaisi
2 parents 89cba08 + dfd18a5 commit e899250

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

change-notes/1.23/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| Client-side cross-site scripting (`js/xss`) | More results | More potential vulnerabilities involving functions that manipulate DOM attributes are now recognized. |
2121
| Code injection (`js/code-injection`) | More results | More potential vulnerabilities involving functions that manipulate DOM event handler attributes are now recognized. |
2222
| Prototype pollution (`js/prototype-pollution`) | More results | The query now highlights vulnerable uses of jQuery and Angular, and the results are shown on LGTM by default. |
23+
| Incorrect suffix check (`js/incorrect-suffix-check`) | Fewer false-positive results | The query recognizes valid checks in more cases. |
2324

2425
## Changes to QL libraries
2526

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ class IndexOfCall extends DataFlow::MethodCallNode {
3535
*/
3636
IndexOfCall getAnEquivalentIndexOfCall() {
3737
result.getReceiver().getALocalSource() = this.getReceiver().getALocalSource() and
38-
result.getArgument(0).getALocalSource() = this.getArgument(0).getALocalSource() and
38+
(
39+
result.getArgument(0).getALocalSource() = this.getArgument(0).getALocalSource()
40+
or
41+
result.getArgument(0).getStringValue() = this.getArgument(0).getStringValue()
42+
) and
3943
result.getMethodName() = this.getMethodName()
4044
}
4145

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,11 @@ function withIndexOfCheckLowerEq(x, y) {
8989
let index = x.indexOf(y);
9090
return !(index <= -1) && index === x.length - y.length - 1; // OK
9191
}
92+
93+
function lastIndexNeqMinusOne(x) {
94+
return x.lastIndexOf("example.com") !== -1 && x.lastIndexOf("example.com") === x.length - "example.com".length; // OK
95+
}
96+
97+
function lastIndexEqMinusOne(x) {
98+
return x.lastIndexOf("example.com") === -1 || x.lastIndexOf("example.com") === x.length - "example.com".length; // OK
99+
}

0 commit comments

Comments
 (0)