File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
lib/codeql/ruby/frameworks
test/library-tests/frameworks Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -275,7 +275,18 @@ private class ActiveRecordModelFinderCall extends ActiveRecordModelInstantiation
275
275
exists ( MethodCall call , Expr recv |
276
276
call = this .asExpr ( ) .getExpr ( ) and
277
277
recv = getUltimateReceiver ( call ) and
278
- resolveConstant ( recv ) = cls .getAQualifiedName ( ) and
278
+ (
279
+ // The receiver refers to an `ActiveRecordModelClass` by name
280
+ resolveConstant ( recv ) = cls .getAQualifiedName ( )
281
+ or
282
+ // The receiver is self, and the call is within a singleton method of
283
+ // the `ActiveRecordModelClass`
284
+ recv instanceof SelfVariableAccess and
285
+ exists ( SingletonMethod callScope |
286
+ callScope = call .getCfgScope ( ) and
287
+ callScope = cls .getAMethod ( )
288
+ )
289
+ ) and
279
290
call .getMethodName ( ) = finderMethodName ( )
280
291
)
281
292
}
@@ -293,7 +304,10 @@ private class ActiveRecordModelClassSelfReference extends ActiveRecordModelInsta
293
304
m = this .getCfgScope ( ) and
294
305
m .getEnclosingModule ( ) = cls and
295
306
m = cls .getAMethod ( )
296
- )
307
+ ) and
308
+ // In a singleton method, `self` refers to the class itself rather than an
309
+ // instance of that class
310
+ not this .getSelfScope ( ) instanceof SingletonMethod
297
311
}
298
312
299
313
final override ActiveRecordModelClass getClass ( ) { result = cls }
Original file line number Diff line number Diff line change @@ -45,9 +45,8 @@ potentiallyUnsafeSqlExecutingMethodCall
45
45
| ActiveRecordInjection.rb:75:5:75:29 | call to order |
46
46
| ActiveRecordInjection.rb:80:7:80:40 | call to find_by |
47
47
activeRecordModelInstantiations
48
- | ActiveRecordInjection.rb:8:3:11:5 | self (authenticate) | ActiveRecordInjection.rb:5:1:17:3 | User |
48
+ | ActiveRecordInjection.rb:10:5:10:68 | call to find | ActiveRecordInjection.rb:5:1:17:3 | User |
49
49
| ActiveRecordInjection.rb:15:5:15:40 | call to find_by | ActiveRecordInjection.rb:1:1:3:3 | UserGroup |
50
- | ActiveRecordInjection.rb:20:3:24:5 | self (delete_by) | ActiveRecordInjection.rb:19:1:25:3 | Admin |
51
50
| ActiveRecordInjection.rb:80:7:80:40 | call to find_by | ActiveRecordInjection.rb:5:1:17:3 | User |
52
51
| ActiveRecordInjection.rb:85:5:85:33 | call to find_by | ActiveRecordInjection.rb:5:1:17:3 | User |
53
52
| ActiveRecordInjection.rb:88:5:88:34 | call to find | ActiveRecordInjection.rb:5:1:17:3 | User |
You can’t perform that action at this time.
0 commit comments