File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed
lib/codeql/ruby/frameworks
test/library-tests/frameworks/rack Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ private import codeql.ruby.DataFlow
9
9
* Provides modeling for the Rack library.
10
10
*/
11
11
module Rack {
12
+ import codeql.ruby.typetracking.TypeTracker
13
+
12
14
/**
13
15
* A class that may be a rack application.
14
16
* This is a class that has a `call` method that takes a single argument
@@ -20,7 +22,7 @@ module Rack {
20
22
AppCandidate ( ) {
21
23
call = this .getInstanceMethod ( "call" ) and
22
24
call .getNumberOfParameters ( ) = 1 and
23
- exists ( DataFlow :: LocalSourceNode resp | isRackResponse ( resp ) | resp . flowsTo ( call .getReturn ( ) ) )
25
+ call .getReturn ( ) = trackRackResponse ( )
24
26
}
25
27
26
28
/**
@@ -37,4 +39,15 @@ module Rack {
37
39
exists ( DataFlow:: LocalSourceNode n | n .asExpr ( ) = arr | n .flowsTo ( r ) )
38
40
)
39
41
}
42
+
43
+ private DataFlow:: LocalSourceNode trackRackResponse ( TypeTracker t ) {
44
+ t .start ( ) and
45
+ isRackResponse ( result )
46
+ or
47
+ exists ( TypeTracker t2 | result = trackRackResponse ( t2 ) .track ( t2 , t ) )
48
+ }
49
+
50
+ private DataFlow:: Node trackRackResponse ( ) {
51
+ trackRackResponse ( TypeTracker:: end ( ) ) .flowsTo ( result )
52
+ }
40
53
}
Original file line number Diff line number Diff line change 1
1
| rack.rb:1:1:5:3 | HelloWorld | rack.rb:2:12:2:14 | env |
2
2
| rack.rb:7:1:16:3 | Proxy | rack.rb:12:12:12:18 | the_env |
3
3
| rack.rb:18:1:31:3 | Logger | rack.rb:24:12:24:14 | env |
4
+ | rack.rb:45:1:61:3 | Baz | rack.rb:46:12:46:14 | env |
Original file line number Diff line number Diff line change @@ -41,3 +41,21 @@ def call(env)
41
41
nil
42
42
end
43
43
end
44
+
45
+ class Baz
46
+ def call ( env )
47
+ run ( env )
48
+ end
49
+
50
+ def run ( env )
51
+ if env [ :foo ] == "foo"
52
+ [ 200 , { } , "foo" ]
53
+ else
54
+ error
55
+ end
56
+ end
57
+
58
+ def error
59
+ [ 400 , { } , "nope" ]
60
+ end
61
+ end
You can’t perform that action at this time.
0 commit comments