File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -38,3 +38,4 @@ private import codeql.ruby.frameworks.Yaml
38
38
private import codeql.ruby.frameworks.Sequel
39
39
private import codeql.ruby.frameworks.Ldap
40
40
private import codeql.ruby.frameworks.Jwt
41
+ private import codeql.ruby.frameworks.ViewComponent
Original file line number Diff line number Diff line change
1
+ private import codeql.ruby.AST
2
+ private import codeql.ruby.DataFlow
3
+ private import codeql.ruby.dataflow.SSA
4
+ private import codeql.ruby.dataflow.internal.DataFlowPrivate as DataFlowPrivate
5
+
6
+ /**
7
+ * Provides modeling for the `view_component` gem.
8
+ */
9
+ module ViewComponent {
10
+ /**
11
+ * A subclass of `ViewComponent::Base`.
12
+ */
13
+ class ComponentClass extends DataFlow:: ClassNode {
14
+ ComponentClass ( ) {
15
+ this = DataFlow:: getConstant ( "ViewComponent" ) .getConstant ( "Base" ) .getADescendentModule ( )
16
+ }
17
+
18
+ /**
19
+ * Returns the template file for this component.
20
+ */
21
+ ErbFile getTemplate ( ) {
22
+ result .getAbsolutePath ( ) =
23
+ this .getLocation ( ) .getFile ( ) .getAbsolutePath ( ) .replaceAll ( ".rb" , ".html.erb" )
24
+ }
25
+ }
26
+
27
+ /**
28
+ * An additional jump step from a `ComponentClass` passed as an argument in a call to `render`
29
+ * to the `self` variable in its corresponding template.
30
+ */
31
+ private predicate jumpStep ( DataFlow:: Node node1 , DataFlowPrivate:: SsaSelfDefinitionNode node2 ) {
32
+ exists ( DataFlow:: CallNode call , ComponentClass component |
33
+ call .getMethodName ( ) = "render" and
34
+ call .getArgument ( 0 ) = node1 and
35
+ component .trackInstance ( ) .getAValueReachableFromSource ( ) = node1 and
36
+ node2 .getLocation ( ) .getFile ( ) = component .getTemplate ( ) and
37
+ node2 .getSelfScope ( ) instanceof Toplevel and
38
+ node2 .getDefinitionExt ( ) instanceof Ssa:: SelfDefinition
39
+ )
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments