-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix #19294, Ruby NetHttpRequest improvements #20101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
category: fix | ||
--- | ||
* Made the following changes to `NetHttpRequest` | ||
* Adds `connectionNode`, like other Ruby HTTP clients | ||
* Makes `requestNode` and `connectionNode` public so subclasses can use them | ||
* Adds detection of `Net::HTTP.start`, a common way to make HTTP requests in Ruby |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,38 +12,55 @@ | |
/** | ||
* A `Net::HTTP` call which initiates an HTTP request. | ||
* ```ruby | ||
* # one-off request | ||
* Net::HTTP.get("http://example.com/") | ||
* Net::HTTP.post("http://example.com/", "some_data") | ||
* req = Net::HTTP.new("example.com") | ||
* response = req.get("/") | ||
* | ||
* # connection re-use | ||
* Net::HTTP.start("http://example.com") do |http| | ||
* http.get("/") | ||
* end | ||
Comment on lines
+20
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that technically |
||
* ``` | ||
*/ | ||
class NetHttpRequest extends Http::Client::Request::Range instanceof DataFlow::CallNode { | ||
private DataFlow::CallNode request; | ||
private API::Node requestNode; | ||
API::Node requestNode; | ||
API::Node connectionNode; | ||
Check noticeCode scanning / CodeQL Field only used in CharPred Note
Field is only used in CharPred.
|
||
private boolean returnsResponseBody; | ||
|
||
NetHttpRequest() { | ||
exists(string method | | ||
request = requestNode.asSource() and | ||
this = request | ||
this = request and | ||
requestNode = connectionNode.getReturn(method) | ||
| | ||
// Net::HTTP.get(...) | ||
method in ["get", "get_response"] and | ||
requestNode = API::getTopLevelMember("Net").getMember("HTTP").getReturn(method) and | ||
connectionNode = API::getTopLevelMember("Net").getMember("HTTP") and | ||
returnsResponseBody = true | ||
or | ||
// Net::HTTP.post(...).body | ||
method in ["post", "post_form"] and | ||
requestNode = API::getTopLevelMember("Net").getMember("HTTP").getReturn(method) and | ||
connectionNode = API::getTopLevelMember("Net").getMember("HTTP") and | ||
returnsResponseBody = false | ||
or | ||
// Net::HTTP.new(..).get(..).body | ||
// Net::HTTP.start(..) do |http| http.get(..) end | ||
method in [ | ||
"get", "get2", "request_get", "head", "head2", "request_head", "delete", "put", "patch", | ||
"post", "post2", "request_post", "request" | ||
] and | ||
requestNode = API::getTopLevelMember("Net").getMember("HTTP").getInstance().getReturn(method) and | ||
connectionNode = | ||
[ | ||
API::getTopLevelMember("Net").getMember("HTTP").getInstance(), | ||
API::getTopLevelMember("Net") | ||
.getMember("HTTP") | ||
.getMethod("start") | ||
.getBlock() | ||
.getParameter(0) | ||
] and | ||
returnsResponseBody = false | ||
) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,11 @@ def get(domain, path) | |
get("example.com", "/").body | ||
|
||
Net::HTTP.post(uri, "some_body") # note: response body not accessed | ||
|
||
http = Net::HTTP.new("https://example.com") | ||
root_get = Net::HTTP::Get.new("/") | ||
http.request(root_get) | ||
Comment on lines
+31
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case was already detected without the above code modifications, but I wanted to make sure that request objects are also detected correctly. |
||
|
||
Net::HTTP.start("https://example.com") do |http| | ||
http.get("/") | ||
end |
Uh oh!
There was an error while loading. Please reload this page.