File tree Expand file tree Collapse file tree 5 files changed +48
-0
lines changed
test/library-tests/frameworks Expand file tree Collapse file tree 5 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ private import codeql.ruby.frameworks.ActionController
66private import codeql.ruby.frameworks.ActiveRecord
77private import codeql.ruby.frameworks.ActiveStorage
88private import codeql.ruby.frameworks.ActionView
9+ private import codeql.ruby.frameworks.ActiveSupport
910private import codeql.ruby.frameworks.GraphQL
1011private import codeql.ruby.frameworks.Rails
1112private import codeql.ruby.frameworks.StandardLibrary
Original file line number Diff line number Diff line change 1+ /**
2+ * Modeling for `ActiveSupport`, which is a utility gem that ships with Rails.
3+ * https://rubygems.org/gems/activesupport
4+ */
5+
6+ import codeql.ruby.Concepts
7+ import codeql.ruby.DataFlow
8+ import codeql.ruby.frameworks.StandardLibrary
9+
10+ /**
11+ * Modeling for `ActiveSupport`.
12+ */
13+ module ActiveSupport {
14+ /**
15+ * Extensions to core classes
16+ */
17+ module CoreExtensions {
18+ /**
19+ * Extensions to the `String` class
20+ */
21+ module String {
22+ /**
23+ * A call to `String#constantize`, which tries to find a declared constant with the given name.
24+ * Passing user input to this method may result in instantiation of arbitrary Ruby classes.
25+ */
26+ class Constantize extends CodeExecution:: Range , DataFlow:: CallNode {
27+ // We treat this an `UnknownMethodCall` in order to match every call to `constantize` that isn't overridden.
28+ // We can't (yet) rely on API Graphs or dataflow to tell us that the receiver is a String.
29+ Constantize ( ) {
30+ this .asExpr ( ) .getExpr ( ) .( UnknownMethodCall ) .getMethodName ( ) = "constantize"
31+ }
32+
33+ override DataFlow:: Node getCode ( ) { result = this .getReceiver ( ) }
34+ }
35+ }
36+ }
37+ }
Original file line number Diff line number Diff line change 1+ | active_support.rb:1:1:1:22 | call to constantize | active_support.rb:1:1:1:10 | "Foo::Bar" |
2+ | active_support.rb:3:1:3:13 | call to constantize | active_support.rb:3:1:3:1 | call to a |
Original file line number Diff line number Diff line change 1+ import codeql.ruby.frameworks.ActiveSupport
2+
3+ query DataFlow:: Node constantizeCalls ( ActiveSupport:: CoreExtensions:: String:: Constantize c ) {
4+ result = c .getCode ( )
5+ }
Original file line number Diff line number Diff line change 1+ "Foo::Bar" . constantize
2+
3+ a . constantize
You can’t perform that action at this time.
0 commit comments