Skip to content

Commit 17afab7

Browse files
committed
support that two indexOf() calls use the same string-concatenation in getAnEquivalentIndexOfCall()
1 parent d5529e3 commit 17afab7

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,20 @@ class IndexOfCall extends DataFlow::MethodCallNode {
4949
exists(DataFlow::Node recv, string m |
5050
this.receiverAndMethodName(recv, m) and result.receiverAndMethodName(recv, m)
5151
|
52+
// both directly reference the same value
5253
result.getArgument(0).getALocalSource() = this.getArgument(0).getALocalSource()
5354
or
55+
// both use the same string literal
5456
result.getArgument(0).getStringValue() = this.getArgument(0).getStringValue()
57+
or
58+
// both use the same concatenation of a string and a value
59+
exists(Expr origin, StringLiteral str, AddExpr otherAdd |
60+
this.getArgument(0).asExpr().(AddExpr).hasOperands(origin, str) and
61+
otherAdd = result.getArgument(0).asExpr().(AddExpr)
62+
|
63+
otherAdd.getAnOperand().(StringLiteral).getStringValue() = str.getStringValue() and
64+
otherAdd.getAnOperand().flow().getALocalSource() = origin.flow().getALocalSource()
65+
)
5566
)
5667
}
5768

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,4 +9,3 @@
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: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
@@ -107,5 +107,5 @@ function sameCheck(allowedOrigin) {
107107

108108
function sameConcatenation(allowedOrigin) {
109109
const trustedAuthority = "example.com";
110-
return trustedAuthority.indexOf("." + allowedOrigin) > 0 && trustedAuthority.indexOf("." + allowedOrigin) === trustedAuthority.length - allowedOrigin.length - 1; // OK - but currently failing
110+
return trustedAuthority.indexOf("." + allowedOrigin) > 0 && trustedAuthority.indexOf("." + allowedOrigin) === trustedAuthority.length - allowedOrigin.length - 1; // OK
111111
}

0 commit comments

Comments
 (0)