Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 12a0af1

Browse files
alexrfordnickrolfe
andauthored
Tidy up PotentiallyUnsafeSqlExecutingMethodCall characteristic predicate
Co-authored-by: Nick Rolfe <[email protected]>
1 parent bf43a77 commit 12a0af1

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

ql/src/codeql_ruby/frameworks/ActiveRecord.qll

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ class ActiveRecordModelClassMethodCall extends MethodCall {
5353
}
5454
}
5555

56-
private predicate methodCanTakeSqlFragmentAsFirstArg(string methodName) {
56+
private predicate methodWithSqlFragmentArg(string methodName, int argIndex) {
5757
methodName =
5858
[
5959
"delete_all", "destroy_all", "exists?", "find_by", "find_by_sql", "from", "group", "having",
6060
"joins", "lock", "not", "order", "pluck", "where"
61-
]
61+
] and
62+
argIndex = 0
63+
or
64+
methodName = "calculate" and argIndex = 1
6265
}
6366

6467
class PotentiallyUnsafeSqlExecutingMethodCall extends ActiveRecordModelClassMethodCall {
@@ -73,12 +76,7 @@ class PotentiallyUnsafeSqlExecutingMethodCall extends ActiveRecordModelClassMeth
7376
PotentiallyUnsafeSqlExecutingMethodCall() {
7477
methodName = this.getMethodName() and
7578
sqlFragmentExpr = this.getArgument(sqlFragmentArgumentIndex) and
76-
(
77-
methodName = "calculate" and sqlFragmentArgumentIndex = 1
78-
or
79-
sqlFragmentArgumentIndex = 0 and
80-
methodCanTakeSqlFragmentAsFirstArg(methodName)
81-
) and
79+
methodWithSqlFragmentArg(methodName, sqlFragmentArgumentIndex) and
8280
(
8381
// select only literals containing an interpolated value...
8482
exists(StringInterpolationComponent interpolated |

0 commit comments

Comments
 (0)