Skip to content

Commit 200c8f2

Browse files
committed
Add some HTMLEscaping implementations for Rails
1 parent 2e65f9b commit 200c8f2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ private class ActionControllerHtmlSafeCall extends HtmlSafeCall {
134134
}
135135
}
136136

137+
// A call to `html_escape` from within a controller.
138+
private class ActionControllerHtmlEscapeCall extends HtmlEscapeCall {
139+
ActionControllerHtmlEscapeCall() {
140+
this.getEnclosingModule() instanceof ActionControllerControllerClass
141+
}
142+
}
143+
137144
/**
138145
* A call to the `redirect_to` method, used in an action to redirect to a
139146
* specific URL/path or to a different action in this controller.

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@ private class ActionViewHtmlSafeCall extends HtmlSafeCall {
2525
ActionViewHtmlSafeCall() { inActionViewContext(this) }
2626
}
2727

28+
/**
29+
* A call to a method named "html_escape", "html_escape_once", or "h".
30+
*/
31+
abstract class HtmlEscapeCall extends MethodCall {
32+
// "h" is aliased to "html_escape" in ActiveSupport
33+
HtmlEscapeCall() { this.getMethodName() = ["html_escape", "html_escape_once", "h"] }
34+
}
35+
36+
class RailsHtmlEscaping extends Escaping::Range, DataFlow::CallNode {
37+
RailsHtmlEscaping() { this.asExpr().getExpr() instanceof HtmlEscapeCall }
38+
39+
override DataFlow::Node getAnInput() { result = this.getArgument(0) }
40+
41+
override DataFlow::Node getOutput() { result = this }
42+
43+
override string getKind() { result = Escaping::getHtmlKind() }
44+
}
45+
46+
// A call to `html_escape` from within a template.
47+
private class ActionViewHtmlEscapeCall extends HtmlEscapeCall {
48+
ActionViewHtmlEscapeCall() { inActionViewContext(this) }
49+
}
50+
2851
// A call in a context where some commonly used `ActionView` methods are available.
2952
private class ActionViewContextCall extends MethodCall {
3053
ActionViewContextCall() {

0 commit comments

Comments
 (0)