Skip to content

Commit 8362caa

Browse files
authored
Merge pull request #11417 from alexrford/ruby/activesupport-json_escape
Ruby: model ActiveSupport `json_escape` flow
2 parents 3c7f751 + e6446e5 commit 8362caa

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,26 @@ module ActiveSupport {
312312
}
313313
}
314314

315+
/**
316+
* `ActiveSupport::ERB`
317+
*/
318+
module Erb {
319+
/**
320+
* `ActiveSupport::ERB::Util`
321+
*/
322+
module Util {
323+
private class JsonEscapeSummary extends SimpleSummarizedCallable {
324+
JsonEscapeSummary() { this = "json_escape" }
325+
326+
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
327+
input = "Argument[0]" and
328+
output = "ReturnValue" and
329+
preservesValue = false
330+
}
331+
}
332+
}
333+
}
334+
315335
/**
316336
* Type summaries for extensions to the `Pathname` module.
317337
*/

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ edges
186186
| active_support.rb:290:7:290:16 | call to source : | active_support.rb:291:8:291:8 | x : |
187187
| active_support.rb:291:8:291:8 | x : | active_support.rb:291:8:291:17 | call to deep_dup |
188188
| active_support.rb:291:8:291:8 | x : | active_support.rb:291:8:291:17 | call to deep_dup |
189+
| active_support.rb:303:7:303:16 | call to source : | active_support.rb:304:19:304:19 | a : |
190+
| active_support.rb:304:7:304:19 | call to json_escape : | active_support.rb:305:8:305:8 | b |
191+
| active_support.rb:304:19:304:19 | a : | active_support.rb:304:7:304:19 | call to json_escape : |
189192
| hash_extensions.rb:2:14:2:24 | call to source : | hash_extensions.rb:3:9:3:9 | h [element :a] : |
190193
| hash_extensions.rb:2:14:2:24 | call to source : | hash_extensions.rb:3:9:3:9 | h [element :a] : |
191194
| hash_extensions.rb:3:9:3:9 | h [element :a] : | hash_extensions.rb:3:9:3:24 | call to stringify_keys [element] : |
@@ -532,6 +535,10 @@ nodes
532535
| active_support.rb:291:8:291:8 | x : | semmle.label | x : |
533536
| active_support.rb:291:8:291:17 | call to deep_dup | semmle.label | call to deep_dup |
534537
| active_support.rb:291:8:291:17 | call to deep_dup | semmle.label | call to deep_dup |
538+
| active_support.rb:303:7:303:16 | call to source : | semmle.label | call to source : |
539+
| active_support.rb:304:7:304:19 | call to json_escape : | semmle.label | call to json_escape : |
540+
| active_support.rb:304:19:304:19 | a : | semmle.label | a : |
541+
| active_support.rb:305:8:305:8 | b | semmle.label | b |
535542
| hash_extensions.rb:2:14:2:24 | call to source : | semmle.label | call to source : |
536543
| hash_extensions.rb:2:14:2:24 | call to source : | semmle.label | call to source : |
537544
| 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,9 @@ def m_try(method)
298298
x.try!(:upcase).try!(:downcase)
299299
x.try!(method)
300300
end
301+
302+
def m_json_escape
303+
a = source "a"
304+
b = json_escape a
305+
sink b # $hasTaintFlow=a
306+
end

0 commit comments

Comments
 (0)