Java: Update CWE-918 model coverage for Apache HttpClient execute sinks#21804
Java: Update CWE-918 model coverage for Apache HttpClient execute sinks#21804Copilot wants to merge 6 commits into
execute sinks#21804Conversation
Agent-Logs-Url: https://github.com/github/codeql/sessions/bd4fa112-dbc3-47e8-9cef-9b1b13c7e549 Co-authored-by: owen-mc <[email protected]>
Request sinks
|
(1) Please delete your current changes on this branch. (2) Please update java/ql/lib/ext/org.apache.http.client.model.yml to: (3) Please add tests for the models in that file. Look at the other SSRF tests in java/ql/test/query-tests/security/CWE-918/ApacheHttpSSRF.java for an example to follow. You will have to add stubs and add the path to them in the file java/ql/test/query-tests/security/CWE-918/options . Look at that file to see where the stubs should be located. You can look at existing stubs to see what they should be like. |
Agent-Logs-Url: https://github.com/github/codeql/sessions/3db201db-a1b5-4353-a94a-14a8d156dd3b Co-authored-by: owen-mc <[email protected]>
Done in 043ec85. I removed the previous fluent-only test/stub changes, updated Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Request sinksexecute sinks
owen-mc
left a comment
There was a problem hiding this comment.
Adds some missing sinks.
There was a problem hiding this comment.
Pull request overview
This PR expands CodeQL’s Java SSRF (CWE-918) coverage by modeling additional Apache HttpClient 4.x HttpClient#execute(...) overloads as request-forgery sinks, and adds a dedicated regression test plus stubs to exercise those overloads.
Changes:
- Added sink models for the full set of
org.apache.http.client.HttpClient#execute(...)overloads takingHttpHost/HttpUriRequest. - Added a new CWE-918 regression test and minimal stubs for
HttpClientandResponseHandler, wiring the stub directory into the test classpath. - Updated the
RequestForgery.expectedbaseline and added a Java pack change note describing the analysis impact.
Show a summary per file
| File | Description |
|---|---|
| java/ql/lib/ext/org.apache.http.client.model.yml | Adds request-forgery sink models for HttpClient.execute(...) overloads. |
| java/ql/test/query-tests/security/CWE-918/ApacheHttpClientExecuteSSRF.java | New regression test covering each newly modeled overload. |
| java/ql/test/stubs/apache-http-client-4.4.13/org/apache/http/client/HttpClient.java | Adds an HttpClient stub exposing the modeled execute(...) overloads. |
| java/ql/test/stubs/apache-http-client-4.4.13/org/apache/http/client/ResponseHandler.java | Adds a ResponseHandler stub required by HttpClient.execute(...) overloads. |
| java/ql/test/query-tests/security/CWE-918/options | Extends the test classpath to include the new Apache HttpClient stub directory. |
| java/ql/test/query-tests/security/CWE-918/RequestForgery.expected | Updates expected results/baseline to include new alerts and model listing changes. |
| java/ql/lib/change-notes/2026-05-07-apache-httpclient-ssrf-sinks.md | Documents the user-visible analysis improvement for Java SSRF queries. |
Copilot's findings
- Files reviewed: 6/7 changed files
- Comments generated: 1
| HttpHost host = new HttpHost(sink); | ||
| HttpRequest req = new BasicHttpRequest("GET", "/"); | ||
| HttpUriRequest uriReq = (HttpUriRequest) (Object) sink; | ||
| HttpContext context = null; | ||
| HttpClient client = null; | ||
| ResponseHandler<Object> handler = null; |
There was a problem hiding this comment.
I agree that this is confusing. Also, the source is named sink, which is confusing as well.
execute sinksexecute sinks
| pack: codeql/java-all | ||
| extensible: sinkModel | ||
| data: | ||
| - ["org.apache.http.client", "HttpClient", True, "execute", "(HttpHost,HttpRequest)", "", "Argument[0]", "request-forgery", "ai-manual"] |
There was a problem hiding this comment.
Is this right? Based on the type names and the models below, which target the HttpUriRequest argument, I'd expect the sink to be the HttpRequest argument (possibly in addition to HttpHost).
| pack: codeql/java-all | ||
| extensible: sinkModel | ||
| data: | ||
| - ["org.apache.http.client", "HttpClient", True, "execute", "(HttpHost,HttpRequest)", "", "Argument[0]", "request-forgery", "ai-manual"] |
There was a problem hiding this comment.
The models look good, but I'm not sure if maybe Argument[1] is also a sink here.
https://codeql.github.com/codeql-query-help/javascript/js-host-header-forgery-in-email-generation/
The request here will have the headers of the outgoing request so if they are user controlled, they could for example cause a malicious redirect or something like that depending on the server that reads it.
I will approve it, but do check this out too
BazookaMusic
left a comment
There was a problem hiding this comment.
Actually I checked it and Anders is correct, HttpHost is the base url and then httprequest contains the relative url.
It's still request forgery if tainted data goes into the relative url
|
@BazookaMusic Our request forgery queries only alert for being able to change the host, so actually it sounds like that model is correct. |
Replaces the earlier fluent-
Requestfocused changes with targeted SSRF model updates and regression tests fororg.apache.http.client.HttpClient#executesinks.What this addresses
java/ql/lib/ext/org.apache.http.client.model.ymlto cover all requestedrequest-forgerysink overloads forHttpClient.execute(...).// $ Sourceand// $ Alertexpectations).Model updates
HttpClient.execute(HttpHost, HttpRequest)HttpClient.execute(HttpHost, HttpRequest, HttpContext)HttpClient.execute(HttpHost, HttpRequest, ResponseHandler)HttpClient.execute(HttpHost, HttpRequest, ResponseHandler, HttpContext)HttpClient.execute(HttpUriRequest)HttpClient.execute(HttpUriRequest, HttpContext)HttpClient.execute(HttpUriRequest, ResponseHandler)HttpClient.execute(HttpUriRequest, ResponseHandler, HttpContext)Test coverage added
java/ql/test/query-tests/security/CWE-918/ApacheHttpClientExecuteSSRF.javaHttpClient.executeoverloads listed above.Stub + test configuration updates
java/ql/test/stubs/apache-http-client-4.4.13/org/apache/http/client/HttpClient.javajava/ql/test/stubs/apache-http-client-4.4.13/org/apache/http/client/ResponseHandler.javajava/ql/test/query-tests/security/CWE-918/optionsto include${testdir}/../../../stubs/apache-http-client-4.4.13.Replaced previous branch content
java/ql/test/query-tests/security/CWE-918/ApacheHttpFluentSSRF.javajava/ql/test/stubs/apache-http-fluent-4.5.14/org/apache/http/client/fluent/Request.javaExample from new test
Original prompt
Created from VS Code.