1+ /**
2+ * Provides modeling for the `ActionView` library.
3+ */
4+
15private import codeql.ruby.AST
26private import codeql.ruby.Concepts
37private import codeql.ruby.controlflow.CfgNodes
@@ -6,6 +10,9 @@ private import codeql.ruby.dataflow.RemoteFlowSources
610private import codeql.ruby.ast.internal.Module
711private import ActionController
812
13+ /**
14+ * Holds if this AST node is in a context where `ActionView` methods are available.
15+ */
916predicate inActionViewContext ( AstNode n ) {
1017 // Within a template
1118 n .getLocation ( ) .getFile ( ) instanceof ErbFile
@@ -33,6 +40,9 @@ abstract class HtmlEscapeCall extends MethodCall {
3340 HtmlEscapeCall ( ) { this .getMethodName ( ) = [ "html_escape" , "html_escape_once" , "h" ] }
3441}
3542
43+ /**
44+ * A call to a Rails method that escapes HTML.
45+ */
3646class RailsHtmlEscaping extends Escaping:: Range , DataFlow:: CallNode {
3747 RailsHtmlEscaping ( ) { this .asExpr ( ) .getExpr ( ) instanceof HtmlEscapeCall }
3848
@@ -55,6 +65,9 @@ private class ActionViewContextCall extends MethodCall {
5565 inActionViewContext ( this )
5666 }
5767
68+ /**
69+ * Holds if this call is located inside an ERb template.
70+ */
5871 predicate isInErbFile ( ) { this .getLocation ( ) .getFile ( ) instanceof ErbFile }
5972}
6073
@@ -132,6 +145,9 @@ private class ActionViewRenderToCall extends ActionViewContextCall, RenderToCall
132145class LinkToCall extends ActionViewContextCall {
133146 LinkToCall ( ) { this .getMethodName ( ) = "link_to" }
134147
148+ /**
149+ * Gets the path argument to the call.
150+ */
135151 Expr getPathArgument ( ) {
136152 // When `link_to` is called with a block, it uses the first argument as the
137153 // path, and otherwise the second argument.
0 commit comments