Skip to content

Commit eff763d

Browse files
committed
Ruby: Model to_json ActiveSupport extension
1 parent 5259d4a commit eff763d

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ module ActiveSupport {
104104

105105
override predicate runsArbitraryCode() { none() }
106106
}
107+
108+
/** Flow summary for `Object#to_json`, which serializes the receiver as a JSON string. */
109+
private class ToJsonSummary extends SimpleSummarizedCallable {
110+
ToJsonSummary() { this = "to_json" }
111+
112+
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
113+
input = ["Argument[self]", "Argument[self].Element[any]"] and
114+
output = "ReturnValue" and
115+
preservesValue = false
116+
}
117+
}
107118
}
108119

109120
/**

ruby/ql/test/library-tests/frameworks/active_support/ActiveSupportDataFlow.expected

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ edges
197197
| active_support.rb:320:35:320:35 | x : | active_support.rb:320:10:320:36 | call to dump |
198198
| active_support.rb:324:9:324:18 | call to source : | active_support.rb:325:35:325:35 | x : |
199199
| active_support.rb:325:35:325:35 | x : | active_support.rb:325:10:325:36 | call to load |
200+
| active_support.rb:329:9:329:18 | call to source : | active_support.rb:330:10:330:10 | x : |
201+
| active_support.rb:329:9:329:18 | call to source : | active_support.rb:331:10:331:10 | x : |
202+
| active_support.rb:330:10:330:10 | x : | active_support.rb:332:10:332:10 | y [element 0] : |
203+
| active_support.rb:331:10:331:10 | x : | active_support.rb:331:10:331:18 | call to to_json |
204+
| active_support.rb:332:10:332:10 | y [element 0] : | active_support.rb:332:10:332:18 | call to to_json |
200205
| hash_extensions.rb:2:14:2:24 | call to source : | hash_extensions.rb:3:9:3:9 | h [element :a] : |
201206
| hash_extensions.rb:2:14:2:24 | call to source : | hash_extensions.rb:3:9:3:9 | h [element :a] : |
202207
| hash_extensions.rb:3:9:3:9 | h [element :a] : | hash_extensions.rb:3:9:3:24 | call to stringify_keys [element] : |
@@ -559,6 +564,12 @@ nodes
559564
| active_support.rb:324:9:324:18 | call to source : | semmle.label | call to source : |
560565
| active_support.rb:325:10:325:36 | call to load | semmle.label | call to load |
561566
| active_support.rb:325:35:325:35 | x : | semmle.label | x : |
567+
| active_support.rb:329:9:329:18 | call to source : | semmle.label | call to source : |
568+
| active_support.rb:330:10:330:10 | x : | semmle.label | x : |
569+
| active_support.rb:331:10:331:10 | x : | semmle.label | x : |
570+
| active_support.rb:331:10:331:18 | call to to_json | semmle.label | call to to_json |
571+
| active_support.rb:332:10:332:10 | y [element 0] : | semmle.label | y [element 0] : |
572+
| active_support.rb:332:10:332:18 | call to to_json | semmle.label | call to to_json |
562573
| hash_extensions.rb:2:14:2:24 | call to source : | semmle.label | call to source : |
563574
| hash_extensions.rb:2:14:2:24 | call to source : | semmle.label | call to source : |
564575
| hash_extensions.rb:3:9:3:9 | h [element :a] : | semmle.label | h [element :a] : |

ruby/ql/test/library-tests/frameworks/active_support/active_support.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,10 @@ def m_json_load
324324
x = source "a"
325325
sink ActiveSupport::JSON.load(x) # $hasTaintFlow=a
326326
end
327+
328+
def m_to_json
329+
x = source "a"
330+
y = [x]
331+
sink x.to_json # $hasTaintFlow=a
332+
sink y.to_json # $hasTaintFlow=a
333+
end

0 commit comments

Comments
 (0)