1
- /**
2
- * @kind path-problem
3
- */
4
-
5
1
import codeql.ruby.AST
6
2
import codeql.ruby.CFG
7
- import TestUtilities.InlineFlowTest
8
- import ValueFlowTest< DefaultFlowConfig >
9
- import ValueFlow:: PathGraph
3
+ import ruby
4
+ import codeql.ruby.DataFlow
5
+ import codeql.ruby.AST
6
+ import codeql.ruby.TaintTracking
7
+ import codeql.ruby.frameworks.data.internal.ApiGraphModels
8
+ import codeql.ruby.ApiGraphs
9
+ import codeql.ruby.dataflow.RemoteFlowSources
10
+ private import codeql.ruby.CFG
11
+ private import codeql.ruby.dataflow.BarrierGuards
12
+ import codeql.ruby.ast.internal.Module
13
+ import codeql.ruby.dataflow.internal.DataFlowPrivate
14
+ import codeql.ruby.dataflow.SSA
15
+
16
+ from ErbFlow:: PartialPathNode source , ErbFlow:: PartialPathNode sink
17
+ where ErbFlow:: partialFlow ( source , sink , _)
18
+ select source , sink
19
+
20
+ module ErbFlow = TaintTracking:: Global< Erb > :: FlowExplorationFwd< explorationLimit / 0 > ;
21
+
22
+ module Erb implements DataFlow:: ConfigSig {
23
+ predicate isSource ( DataFlow:: Node node ) { node .( DataFlow:: CallNode ) .getMethodName ( ) = "source" }
24
+
25
+ predicate isSink ( DataFlow:: Node node ) {
26
+ node = any ( DataFlow:: CallNode c | c .getMethodName ( ) = "sink" ) .getArgument ( _)
27
+ }
28
+
29
+ predicate isAdditionalFlowStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
30
+ isFlowFromViewSelfToTemplate ( node1 , node2 )
31
+ }
32
+ }
33
+
34
+ int explorationLimit ( ) { result = 10 }
35
+
36
+ predicate isFlowFromViewSelfToTemplate ( DataFlow:: Node node1 , SsaSelfDefinitionNode node2 ) {
37
+ exists ( DataFlow:: CallNode call , DataFlow:: ClassNode view |
38
+ call .getMethodName ( ) = "render" and
39
+ call .getArgument ( 0 ) = node1 and
40
+ view .trackInstance ( ) .getAValueReachableFromSource ( ) = node1 and
41
+ exists ( ErbFile template |
42
+ view = getTemplateAssociatedViewClass ( template ) and node2 .getLocation ( ) .getFile ( ) = template
43
+ ) and
44
+ node2 .getSelfScope ( ) instanceof Toplevel and
45
+ node2 .getDefinitionExt ( ) instanceof Ssa:: SelfDefinition
46
+ )
47
+ }
10
48
11
- from ValueFlow:: PathNode source , ValueFlow:: PathNode sink
12
- where ValueFlow:: flowPath ( source , sink )
13
- select sink , source , sink , "$@" , source , source .toString ( )
49
+ DataFlow:: ClassNode getTemplateAssociatedViewClass ( ErbFile template ) {
50
+ // template is in same directory as view
51
+ exists ( File viewFile | viewFile = result .getADeclaration ( ) .getFile ( ) |
52
+ template .getParentContainer ( ) .getAbsolutePath ( ) =
53
+ viewFile .getParentContainer ( ) .getAbsolutePath ( ) and
54
+ viewFile .getStem ( ) = template .getStem ( )
55
+ )
56
+ }
0 commit comments