Skip to content

Commit d3c8ce3

Browse files
committed
Ruby: ActiveSupport extends Pathname with an existence method that may return itself
1 parent fc810dd commit d3c8ce3

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,31 @@ module ActiveSupport {
140140
}
141141
}
142142

143+
/**
144+
* Type summaries for extensions to the `Pathname` module.
145+
*/
146+
private class PathnameTypeSummary extends ModelInput::TypeModelCsv {
147+
override predicate row(string row) {
148+
// package1;type1;package2;type2;path
149+
row =
150+
[
151+
// Pathname#existence : Pathname
152+
";Pathname;;Pathname;Method[existence].ReturnValue",
153+
]
154+
}
155+
}
156+
157+
/** Taint flow summaries for extensions to the `Pathname` module. */
158+
private class PathnameTaintSummary extends ModelInput::SummaryModelCsv {
159+
override predicate row(string row) {
160+
row =
161+
[
162+
// Pathname#existence
163+
";Pathname;Method[existence];Argument[self];ReturnValue;taint",
164+
]
165+
}
166+
}
167+
143168
/**
144169
* `ActiveSupport::SafeBuffer` wraps a string, providing HTML-safe methods
145170
* for concatenation.

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ edges
136136
| active_support.rb:191:34:191:34 | a : | active_support.rb:191:7:191:35 | call to new : |
137137
| active_support.rb:192:7:192:7 | x : | active_support.rb:192:7:192:16 | call to to_param : |
138138
| active_support.rb:192:7:192:16 | call to to_param : | active_support.rb:193:8:193:8 | y |
139+
| active_support.rb:197:7:197:16 | call to source : | active_support.rb:198:20:198:20 | a : |
140+
| active_support.rb:198:7:198:21 | call to new : | active_support.rb:199:7:199:7 | x : |
141+
| active_support.rb:198:20:198:20 | a : | active_support.rb:198:7:198:21 | call to new : |
142+
| active_support.rb:199:7:199:7 | x : | active_support.rb:199:7:199:17 | call to existence : |
143+
| active_support.rb:199:7:199:17 | call to existence : | active_support.rb:200:8:200:8 | y |
144+
| active_support.rb:199:7:199:17 | call to existence : | active_support.rb:201:7:201:7 | y : |
145+
| active_support.rb:201:7:201:7 | y : | active_support.rb:201:7:201:17 | call to existence : |
146+
| active_support.rb:201:7:201:17 | call to existence : | active_support.rb:202:8:202:8 | z |
139147
nodes
140148
| active_support.rb:9:9:9:18 | call to source : | semmle.label | call to source : |
141149
| active_support.rb:10:10:10:10 | x : | semmle.label | x : |
@@ -310,6 +318,15 @@ nodes
310318
| active_support.rb:192:7:192:7 | x : | semmle.label | x : |
311319
| active_support.rb:192:7:192:16 | call to to_param : | semmle.label | call to to_param : |
312320
| active_support.rb:193:8:193:8 | y | semmle.label | y |
321+
| active_support.rb:197:7:197:16 | call to source : | semmle.label | call to source : |
322+
| active_support.rb:198:7:198:21 | call to new : | semmle.label | call to new : |
323+
| active_support.rb:198:20:198:20 | a : | semmle.label | a : |
324+
| active_support.rb:199:7:199:7 | x : | semmle.label | x : |
325+
| active_support.rb:199:7:199:17 | call to existence : | semmle.label | call to existence : |
326+
| active_support.rb:200:8:200:8 | y | semmle.label | y |
327+
| active_support.rb:201:7:201:7 | y : | semmle.label | y : |
328+
| active_support.rb:201:7:201:17 | call to existence : | semmle.label | call to existence : |
329+
| active_support.rb:202:8:202:8 | z | semmle.label | z |
313330
subpaths
314331
#select
315332
| active_support.rb:106:10:106:13 | ...[...] | active_support.rb:104:10:104:17 | call to source : | active_support.rb:106:10:106:13 | ...[...] | $@ | active_support.rb:104:10:104:17 | call to source : | call to source : |

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,12 @@ def m_safe_buffer_to_param
192192
y = x.to_param
193193
sink y # $hasTaintFlow=a
194194
end
195+
196+
def m_pathname_existence
197+
a = source "a"
198+
x = Pathname.new(a)
199+
y = x.existence
200+
sink y # $hasTaintFlow=a
201+
z = y.existence
202+
sink z # $hasTaintFlow=a
203+
end

0 commit comments

Comments
 (0)