-
Notifications
You must be signed in to change notification settings - Fork 2k
Java: Update CWE-918 model coverage for Apache HttpClient execute sinks
#21804
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
base: main
Are you sure you want to change the base?
Changes from all commits
26dca55
f5b17b0
043ec85
dd35bc0
dc86476
a159dc1
37589dd
8937e22
d95d998
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,4 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * Improved modeling of Apache HttpClient `execute` method sinks for `java/ssrf` and `java/non-https-url`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,11 @@ extensions: | |
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
| - ["org.apache.http.client", "HttpClient", True, "execute", "(HttpHost,HttpRequest,HttpContext)", "", "Argument[0]", "request-forgery", "ai-manual"] | ||
| - ["org.apache.http.client", "HttpClient", True, "execute", "(HttpHost,HttpRequest,ResponseHandler)", "", "Argument[0]", "request-forgery", "ai-manual"] | ||
| - ["org.apache.http.client", "HttpClient", True, "execute", "(HttpHost,HttpRequest,ResponseHandler,HttpContext)", "", "Argument[0]", "request-forgery", "ai-manual"] | ||
| - ["org.apache.http.client", "HttpClient", True, "execute", "(HttpUriRequest)", "", "Argument[0]", "request-forgery", "ai-manual"] | ||
| - ["org.apache.http.client", "HttpClient", True, "execute", "(HttpUriRequest,HttpContext)", "", "Argument[0]", "request-forgery", "ai-manual"] | ||
| - ["org.apache.http.client", "HttpClient", True, "execute", "(HttpUriRequest,ResponseHandler)", "", "Argument[0]", "request-forgery", "ai-manual"] | ||
| - ["org.apache.http.client", "HttpClient", True, "execute", "(HttpUriRequest,ResponseHandler,HttpContext)", "", "Argument[0]", "request-forgery", "ai-manual"] | ||
| - ["org.apache.http.client", "HttpClient", True, "execute", "(HttpUriRequest)", "", "Argument[0]", "request-forgery", "ai-manual"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import java.io.IOException; | ||
|
|
||
| import org.apache.http.HttpHost; | ||
| import org.apache.http.HttpRequest; | ||
| import org.apache.http.client.HttpClient; | ||
| import org.apache.http.client.ResponseHandler; | ||
| import org.apache.http.client.methods.HttpUriRequest; | ||
| import org.apache.http.client.methods.RequestBuilder; | ||
| import org.apache.http.impl.client.HttpClients; | ||
| import org.apache.http.message.BasicHttpRequest; | ||
| import org.apache.http.protocol.HttpContext; | ||
| import javax.servlet.ServletException; | ||
| import javax.servlet.http.HttpServlet; | ||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
|
|
||
| public class ApacheHttpClientExecuteSSRF extends HttpServlet { | ||
|
|
||
| protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
| throws ServletException, IOException { | ||
| try { | ||
|
|
||
| String source = request.getParameter("host"); // $ Source | ||
|
|
||
| HttpHost host = new HttpHost(source); | ||
| HttpRequest req = new BasicHttpRequest("GET", "/"); | ||
| HttpUriRequest uriReq = RequestBuilder.get(source).build(); // $ Alert | ||
| HttpContext context = null; | ||
| HttpClient client = HttpClients.createDefault(); | ||
| ResponseHandler<Object> handler = null; | ||
|
|
||
| client.execute(host, req); // $ Alert | ||
| client.execute(host, req, context); // $ Alert | ||
| client.execute(host, req, handler); // $ Alert | ||
| client.execute(host, req, handler, context); // $ Alert | ||
| client.execute(uriReq); // $ Alert | ||
| client.execute(uriReq, context); // $ Alert | ||
| client.execute(uriReq, handler); // $ Alert | ||
| client.execute(uriReq, handler, context); // $ Alert | ||
|
|
||
| } catch (Exception e) { | ||
| // TODO: handle exception | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right? Based on the type names and the models below, which target the
HttpUriRequestargument, I'd expect the sink to be theHttpRequestargument (possibly in addition toHttpHost).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed below, this is correct as the query only reports user-controlled data flowing to the host of a URI.