Skip to content

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

Merged
merged 4 commits into from
Aug 12, 2025
Merged

Conversation

mschwager
Copy link
Contributor

This PR makes 3 improvements to the NetHttpRequest class:

@mschwager mschwager requested a review from a team as a code owner July 21, 2025 19:21
@github-actions github-actions bot added the Ruby label Jul 21, 2025
Comment on lines +20 to +24
*
* # connection re-use
* Net::HTTP.start("http://example.com") do |http|
* http.get("/")
* end
Copy link
Contributor Author

@mschwager mschwager Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that technically Net::HTTP.new does not open/reuse connections/sessions: https://docs.ruby-lang.org/en/master/Net/HTTP.html#method-c-new

Comment on lines +31 to +33
http = Net::HTTP.new("https://example.com")
root_get = Net::HTTP::Get.new("/")
http.request(root_get)
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution; changes look good to me, only minor changes needed.

@@ -30,20 +37,27 @@ class NetHttpRequest extends Http::Client::Request::Range instanceof DataFlow::C
|
// 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
requestNode = connectionNode.getReturn(method) and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move requestNode = connectionNode.getReturn(method) up after line 36, and then remove the three duplicated lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's curious to me that you can set requestNode before you've set connectionNode in this situation. I've made the requested change, but I'd like to learn more. Is there some documentation you can point me to describing this behavior, or is that "just the way it works" with queries?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QL is a logic language, so you should not think of x = y as an assignment, but rather as a constraint (x must be equal to y). So the order doesn't really matter.

@mschwager mschwager requested a review from hvitved August 11, 2025 12:15
* ```
*/
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 notice

Code scanning / CodeQL

Field only used in CharPred Note

Field is only used in CharPred.
@hvitved hvitved merged commit 0a67902 into github:main Aug 12, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants