Skip to content

Commit b34fcc6

Browse files
committed
Model the Typhoeus http client
1 parent b5dec5e commit b34fcc6

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ private import codeql.ruby.frameworks.http_clients.RestClient
99
private import codeql.ruby.frameworks.http_clients.HTTParty
1010
private import codeql.ruby.frameworks.http_clients.HTTPClient
1111
private import codeql.ruby.frameworks.http_clients.OpenURI
12+
private import codeql.ruby.frameworks.http_clients.Typhoeus
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
private import ruby
2+
private import codeql.ruby.Concepts
3+
private import codeql.ruby.ApiGraphs
4+
5+
/**
6+
* A call that makes an HTTP request using `Typhoeus`.
7+
* ```ruby
8+
* Typhoeus.get("http://example.com").body
9+
* ```
10+
*/
11+
class TyphoeusHTTPRequest extends HTTP::Client::Request::Range {
12+
DataFlow::Node request;
13+
DataFlow::CallNode responseBody;
14+
15+
TyphoeusHTTPRequest() {
16+
exists(API::Node requestNode | request = requestNode.getAnImmediateUse() |
17+
requestNode =
18+
API::getTopLevelMember("Typhoeus")
19+
.getReturn(["get", "head", "delete", "options", "post", "put", "patch"]) and
20+
responseBody = requestNode.getAMethodCall("body") and
21+
this = request.asExpr().getExpr()
22+
)
23+
}
24+
25+
override DataFlow::Node getResponseBody() { result = responseBody }
26+
27+
override string getFramework() { result = "Typhoeus" }
28+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| Typhoeus.rb:3:9:3:43 | call to get | Typhoeus.rb:4:1:4:10 | call to body |
2+
| Typhoeus.rb:6:9:6:63 | call to post | Typhoeus.rb:7:1:7:10 | call to body |
3+
| Typhoeus.rb:9:9:9:62 | call to put | Typhoeus.rb:10:1:10:10 | call to body |
4+
| Typhoeus.rb:12:9:12:64 | call to patch | Typhoeus.rb:13:1:13:10 | call to body |
5+
| Typhoeus.rb:15:9:15:46 | call to delete | Typhoeus.rb:16:1:16:10 | call to body |
6+
| Typhoeus.rb:18:9:18:44 | call to head | Typhoeus.rb:19:1:19:10 | call to body |
7+
| Typhoeus.rb:21:9:21:47 | call to options | Typhoeus.rb:22:1:22:10 | call to body |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import codeql.ruby.frameworks.http_clients.Typhoeus
2+
import codeql.ruby.DataFlow
3+
4+
query DataFlow::Node typhoeusHTTPRequests(TyphoeusHTTPRequest e) { result = e.getResponseBody() }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require "typhoeus"
2+
3+
resp1 = Typhoeus.get("http://example.com/")
4+
resp1.body
5+
6+
resp2 = Typhoeus.post("http://example.com/", body: "some_data")
7+
resp2.body
8+
9+
resp3 = Typhoeus.put("http://example.com/", body: "some_data")
10+
resp3.body
11+
12+
resp4 = Typhoeus.patch("http://example.com/", body: "some_data")
13+
resp4.body
14+
15+
resp5 = Typhoeus.delete("http://example.com/")
16+
resp5.body
17+
18+
resp6 = Typhoeus.head("http://example.com/")
19+
resp6.body
20+
21+
resp7 = Typhoeus.options("http://example.com/")
22+
resp7.body

0 commit comments

Comments
 (0)