Skip to content

Commit 88885a2

Browse files
committed
Model the RestClient HTTP client
1 parent 4cf520c commit 88885a2

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
private import codeql.ruby.frameworks.http_clients.NetHTTP
66
private import codeql.ruby.frameworks.http_clients.Excon
77
private import codeql.ruby.frameworks.http_clients.Faraday
8+
private import codeql.ruby.frameworks.http_clients.RestClient
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 `RestClient`.
7+
* ```ruby
8+
* RestClient.get("http://example.com").body
9+
* ```
10+
*/
11+
class RestClientHTTPRequest extends HTTP::Client::Request::Range {
12+
DataFlow::Node request;
13+
DataFlow::CallNode responseBody;
14+
15+
RestClientHTTPRequest() {
16+
exists(API::Node requestNode |
17+
requestNode =
18+
API::getTopLevelMember("RestClient")
19+
.getReturn(["get", "head", "delete", "options", "post", "put", "patch"]) and
20+
request = requestNode.getAnImmediateUse() and
21+
responseBody = requestNode.getAMethodCall("body") and
22+
this = request.asExpr().getExpr()
23+
)
24+
}
25+
26+
override DataFlow::Node getResponseBody() { result = responseBody }
27+
28+
override string getFramework() { result = "RestClient" }
29+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| RestClient.rb:3:9:3:45 | call to get | RestClient.rb:4:1:4:10 | call to body |
2+
| RestClient.rb:6:9:6:59 | call to post | RestClient.rb:7:1:7:10 | call to body |
3+
| RestClient.rb:9:9:9:58 | call to put | RestClient.rb:10:1:10:10 | call to body |
4+
| RestClient.rb:12:9:12:60 | call to patch | RestClient.rb:13:1:13:10 | call to body |
5+
| RestClient.rb:15:9:15:47 | call to delete | RestClient.rb:16:1:16:10 | call to body |
6+
| RestClient.rb:18:9:18:45 | call to head | RestClient.rb:19:1:19:10 | call to body |
7+
| RestClient.rb:21:9:21:48 | call to options | RestClient.rb:22:1:22:10 | call to body |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import codeql.ruby.frameworks.http_clients.RestClient
2+
import codeql.ruby.DataFlow
3+
4+
query DataFlow::Node restClientHTTPRequests(RestClientHTTPRequest e) {
5+
result = e.getResponseBody()
6+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require "rest-client"
2+
3+
resp1 = RestClient.get("http://example.com/")
4+
resp1.body
5+
6+
resp2 = RestClient.post("http://example.com", some: "data")
7+
resp2.body
8+
9+
resp3 = RestClient.put("http://example.com", some: "data")
10+
resp3.body
11+
12+
resp4 = RestClient.patch("http://example.com", some: "data")
13+
resp4.body
14+
15+
resp5 = RestClient.delete("http://example.com")
16+
resp5.body
17+
18+
resp6 = RestClient.head("http://example.com")
19+
resp6.body
20+
21+
resp7 = RestClient.options("http://example.com")
22+
resp7.body

0 commit comments

Comments
 (0)