Skip to content

Commit bdbbde3

Browse files
authored
Merge pull request github#13407 from asgerf/rb/restrict-orm-tracking
Ruby: restrict ORM tracking to calls
2 parents 44b0950 + d6741f6 commit bdbbde3

File tree

1 file changed

+9
-1
lines changed
  • ruby/ql/lib/codeql/ruby/security

1 file changed

+9
-1
lines changed

ruby/ql/lib/codeql/ruby/security/XSS.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,22 @@ private module OrmTracking {
285285
* A data flow configuration to track flow from finder calls to field accesses.
286286
*/
287287
private module Config implements DataFlow::ConfigSig {
288-
predicate isSource(DataFlow::Node source) { source instanceof OrmInstantiation }
288+
predicate isSource(DataFlow::Node source) {
289+
// We currently only use ORM instances that come from a call site, so restrict the sources
290+
// to calls. This works around a performance issue that would arise from using 'self' as a source
291+
// in ActiveRecord models. Over time, library models should stop relying on OrmInstantiation and instead
292+
// use API graphs or type-tracking the same way we track other types.
293+
source instanceof OrmInstantiation and source instanceof DataFlow::CallNode
294+
}
289295

290296
// Select any call receiver and narrow down later
291297
predicate isSink(DataFlow::Node sink) { sink = any(DataFlow::CallNode c).getReceiver() }
292298

293299
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
294300
Shared::isAdditionalXssFlowStep(node1, node2)
295301
}
302+
303+
predicate isBarrierIn(DataFlow::Node node) { node instanceof DataFlow::SelfParameterNode }
296304
}
297305

298306
import DataFlow::Global<Config>

0 commit comments

Comments
 (0)