Skip to content

Commit dc4ddf6

Browse files
committed
Ruby: Recognise ActiveSupport::Logger as a logger
1 parent 14d2ff6 commit dc4ddf6

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ private import ruby
77
private import codeql.ruby.Concepts
88
private import codeql.ruby.DataFlow
99
private import codeql.ruby.dataflow.FlowSummary
10+
private import codeql.ruby.Concepts
11+
private import codeql.ruby.ApiGraphs
12+
private import codeql.ruby.frameworks.stdlib.Logger::Logger as StdlibLogger
1013

1114
/**
1215
* Modeling for `ActiveSupport`.
@@ -122,4 +125,15 @@ module ActiveSupport {
122125
// TODO: index_by, index_with, pick, pluck (they require Hash dataflow)
123126
}
124127
}
128+
129+
/**
130+
* `ActiveSupport::Logger`
131+
*/
132+
module Logger {
133+
private class ActiveSupportLoggerInstance extends StdlibLogger::LoggerInstance {
134+
ActiveSupportLoggerInstance() {
135+
this = API::getTopLevelMember("ActiveSupport").getMember("Logger").getAnInstantiation()
136+
}
137+
}
138+
}
125139
}

ruby/ql/lib/codeql/ruby/frameworks/stdlib/Logger.qll

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,25 @@ module Logger {
3333
)
3434
}
3535

36+
/**
37+
* An instance of a logger that responds to the std lib logging methods.
38+
* This can be extended to recognise additional instances that conform to the
39+
* same interface.
40+
*/
41+
abstract class LoggerInstance extends DataFlow::Node { }
42+
43+
/**
44+
* An instance of the std lib `Logger` class.
45+
*/
46+
private class StdlibLoggerInstance extends LoggerInstance {
47+
StdlibLoggerInstance() { this = loggerInstance() }
48+
}
49+
3650
/**
3751
* A call to a `Logger` instance method that causes a message to be logged.
3852
*/
3953
abstract class LoggerLoggingCall extends Logging::Range, DataFlow::CallNode {
40-
LoggerLoggingCall() { this.getReceiver() = loggerInstance() }
54+
LoggerLoggingCall() { this.getReceiver() instanceof LoggerInstance }
4155
}
4256

4357
/**

0 commit comments

Comments
 (0)