Skip to content

Commit ad2eaf0

Browse files
committed
Ruby: Flow for ActiveSupport String extensions
Add taint flow summaries for ActiveSupport String extensions which transform the string in various ways, for example `camelcase` and `underscore`. DCA suggests this increases the sensitivity of rb/code-injection, catching cases such as params[:foo].camelcase.constantize
1 parent be45314 commit ad2eaf0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
private import ruby
77
private import codeql.ruby.Concepts
88
private import codeql.ruby.DataFlow
9+
private import codeql.ruby.dataflow.FlowSummary
910

1011
/**
1112
* Modeling for `ActiveSupport`.
@@ -32,6 +33,28 @@ module ActiveSupport {
3233

3334
override DataFlow::Node getCode() { result = this.getReceiver() }
3435
}
36+
37+
/**
38+
* Flow summary for methods which transform the receiver in some way, possibly preserving taint.
39+
*/
40+
private class StringTransformSummary extends SummarizedCallable {
41+
// We're modelling a lot of different methods, so we make up a name for this summary.
42+
StringTransformSummary() { this = "ActiveSupportStringTransform" }
43+
44+
override MethodCall getACall() {
45+
result.getMethodName() =
46+
[
47+
"camelize", "camelcase", "classify", "dasherize", "deconstantize", "demodulize",
48+
"foreign_key", "humanize", "indent", "parameterize", "pluralize", "singularize",
49+
"squish", "strip_heredoc", "tableize", "titlecase", "titleize", "underscore",
50+
"upcase_first"
51+
]
52+
}
53+
54+
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
55+
input = "Argument[self]" and output = "ReturnValue" and preservesValue = false
56+
}
57+
}
3558
}
3659
}
3760
}

0 commit comments

Comments
 (0)