Skip to content

Commit d5529e3

Browse files
committed
ensure an indexOf call is equivalent with itself. (getAUse() is used later to find matching indexOf calls)
1 parent 905d904 commit d5529e3

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class IndexOfCall extends DataFlow::MethodCallNode {
4444
* Gets an `indexOf` call with the same receiver, argument, and method name, including this call itself.
4545
*/
4646
IndexOfCall getAnEquivalentIndexOfCall() {
47+
result = this
48+
or
4749
exists(DataFlow::Node recv, string m |
4850
this.receiverAndMethodName(recv, m) and result.receiverAndMethodName(recv, m)
4951
|

javascript/ql/test/query-tests/Security/CWE-020/IncorrectSuffixCheck/IncorrectSuffixCheck.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@
99
| tst.js:67:32:67:71 | x.index ... gth - 1 | This suffix check is missing a length comparison to correctly handle indexOf returning -1. |
1010
| tst.js:76:25:76:57 | index = ... gth - 1 | This suffix check is missing a length comparison to correctly handle indexOf returning -1. |
1111
| tst.js:80:10:80:57 | x.index ... th + 1) | This suffix check is missing a length comparison to correctly handle indexOf returning -1. |
12-
| tst.js:105:23:105:80 | ind === ... gth - 1 | This suffix check is missing a length comparison to correctly handle indexOf returning -1. |
1312
| tst.js:110:65:110:164 | trusted ... gth - 1 | This suffix check is missing a length comparison to correctly handle indexOf returning -1. |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function sameCheck(allowedOrigin) {
102102
const trustedAuthority = "example.com";
103103

104104
const ind = trustedAuthority.indexOf("." + allowedOrigin);
105-
return ind > 0 && ind === trustedAuthority.length - allowedOrigin.length - 1; // OK - but currently failing
105+
return ind > 0 && ind === trustedAuthority.length - allowedOrigin.length - 1; // OK
106106
}
107107

108108
function sameConcatenation(allowedOrigin) {

0 commit comments

Comments
 (0)