Skip to content

Commit 34065f9

Browse files
committed
Ruby: recognize ActiveRecord find_by_x methods
1 parent 4a02505 commit 34065f9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ruby/ql/lib/codeql/ruby/frameworks/ActiveRecord.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ abstract class ActiveRecordModelInstantiation extends OrmInstantiation::Range,
240240
// Names of class methods on ActiveRecord models that may return one or more
241241
// instances of that model. This also includes the `initialize` method.
242242
// See https://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html
243-
private string finderMethodName() {
243+
private string staticFinderMethodName() {
244244
exists(string baseName |
245245
baseName =
246246
[
@@ -287,7 +287,12 @@ private class ActiveRecordModelFinderCall extends ActiveRecordModelInstantiation
287287
callScope = cls.getAMethod()
288288
)
289289
) and
290-
call.getMethodName() = finderMethodName()
290+
(
291+
call.getMethodName() = staticFinderMethodName()
292+
or
293+
// dynamically generated finder methods
294+
call.getMethodName().indexOf("find_by_") = 0
295+
)
291296
)
292297
}
293298

0 commit comments

Comments
 (0)