Skip to content

Commit 0a98559

Browse files
committed
Ruby: Add flow summaries for ActiveSupport::JSON
1 parent 375403f commit 0a98559

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,17 @@ module ActiveSupport {
374374
]
375375
}
376376
}
377+
378+
/** `ActiveSupport::JSON` */
379+
module Json {
380+
private class JsonSummary extends ModelInput::SummaryModelCsv {
381+
override predicate row(string row) {
382+
row =
383+
[
384+
"activesupport;;Member[ActiveSupport].Member[JSON].Method[encode,dump];Argument[0];ReturnValue;taint",
385+
"activesupport;;Member[ActiveSupport].Member[JSON].Method[decode,load];Argument[0];ReturnValue;taint",
386+
]
387+
}
388+
}
389+
}
377390
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ edges
189189
| active_support.rb:303:7:303:16 | call to source : | active_support.rb:304:19:304:19 | a : |
190190
| active_support.rb:304:7:304:19 | call to json_escape : | active_support.rb:305:8:305:8 | b |
191191
| active_support.rb:304:19:304:19 | a : | active_support.rb:304:7:304:19 | call to json_escape : |
192+
| active_support.rb:309:9:309:18 | call to source : | active_support.rb:310:37:310:37 | x : |
193+
| active_support.rb:310:37:310:37 | x : | active_support.rb:310:10:310:38 | call to encode |
194+
| active_support.rb:314:9:314:18 | call to source : | active_support.rb:315:37:315:37 | x : |
195+
| active_support.rb:315:37:315:37 | x : | active_support.rb:315:10:315:38 | call to decode |
196+
| active_support.rb:319:9:319:18 | call to source : | active_support.rb:320:35:320:35 | x : |
197+
| active_support.rb:320:35:320:35 | x : | active_support.rb:320:10:320:36 | call to dump |
198+
| active_support.rb:324:9:324:18 | call to source : | active_support.rb:325:35:325:35 | x : |
199+
| active_support.rb:325:35:325:35 | x : | active_support.rb:325:10:325:36 | call to load |
192200
| hash_extensions.rb:2:14:2:24 | call to source : | hash_extensions.rb:3:9:3:9 | h [element :a] : |
193201
| hash_extensions.rb:2:14:2:24 | call to source : | hash_extensions.rb:3:9:3:9 | h [element :a] : |
194202
| hash_extensions.rb:3:9:3:9 | h [element :a] : | hash_extensions.rb:3:9:3:24 | call to stringify_keys [element] : |
@@ -539,6 +547,18 @@ nodes
539547
| active_support.rb:304:7:304:19 | call to json_escape : | semmle.label | call to json_escape : |
540548
| active_support.rb:304:19:304:19 | a : | semmle.label | a : |
541549
| active_support.rb:305:8:305:8 | b | semmle.label | b |
550+
| active_support.rb:309:9:309:18 | call to source : | semmle.label | call to source : |
551+
| active_support.rb:310:10:310:38 | call to encode | semmle.label | call to encode |
552+
| active_support.rb:310:37:310:37 | x : | semmle.label | x : |
553+
| active_support.rb:314:9:314:18 | call to source : | semmle.label | call to source : |
554+
| active_support.rb:315:10:315:38 | call to decode | semmle.label | call to decode |
555+
| active_support.rb:315:37:315:37 | x : | semmle.label | x : |
556+
| active_support.rb:319:9:319:18 | call to source : | semmle.label | call to source : |
557+
| active_support.rb:320:10:320:36 | call to dump | semmle.label | call to dump |
558+
| active_support.rb:320:35:320:35 | x : | semmle.label | x : |
559+
| active_support.rb:324:9:324:18 | call to source : | semmle.label | call to source : |
560+
| active_support.rb:325:10:325:36 | call to load | semmle.label | call to load |
561+
| active_support.rb:325:35:325:35 | x : | semmle.label | x : |
542562
| hash_extensions.rb:2:14:2:24 | call to source : | semmle.label | call to source : |
543563
| hash_extensions.rb:2:14:2:24 | call to source : | semmle.label | call to source : |
544564
| 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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,23 @@ def m_json_escape
304304
b = json_escape a
305305
sink b # $hasTaintFlow=a
306306
end
307+
308+
def m_json_encode
309+
x = source "a"
310+
sink ActiveSupport::JSON.encode(x) # $hasTaintFlow=a
311+
end
312+
313+
def m_json_decode
314+
x = source "a"
315+
sink ActiveSupport::JSON.decode(x) # $hasTaintFlow=a
316+
end
317+
318+
def m_json_dump
319+
x = source "a"
320+
sink ActiveSupport::JSON.dump(x) # $hasTaintFlow=a
321+
end
322+
323+
def m_json_load
324+
x = source "a"
325+
sink ActiveSupport::JSON.load(x) # $hasTaintFlow=a
326+
end

0 commit comments

Comments
 (0)