Skip to content

Commit cd7b79f

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: add tests for org.apache.hc.client5.http.fluent
1 parent 1afa5af commit cd7b79f

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

java/ql/lib/ext/org.apache.hc.client5.http.fluent.model.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ extensions:
33
pack: codeql/java-all
44
extensible: sinkModel
55
data:
6+
# ! `Request` only extends `Object`, no subclasses listed
67
- ["org.apache.hc.client5.http.fluent", "Request", True, "create", "(Method,URI)", "", "Argument[1]", "%-url", "manual"]
78
- ["org.apache.hc.client5.http.fluent", "Request", True, "create", "(String,String)", "", "Argument[1]", "%-url", "manual"]
89
- ["org.apache.hc.client5.http.fluent", "Request", True, "create", "(String,URI)", "", "Argument[1]", "%-url", "manual"]

java/ql/test/query-tests/security/CWE-918/ApacheHttp5SSRF.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.apache.hc.client5.http.classic.methods.HttpTrace;
2929
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
3030

31-
// import org.apache.hc.client5.http.fluent.Request;
31+
import org.apache.hc.client5.http.fluent.Request;
3232
// import org.apache.hc.client5.http.protocol.RedirectLocations;
3333
// import org.apache.hc.client5.http.utils.URIUtils;
3434

@@ -187,8 +187,8 @@ protected void doGet2(HttpServletRequest request, HttpServletResponse response)
187187
ClassicHttpRequests.create("method", uri.toString()); // $ SSRF
188188
ClassicHttpRequests.create("method", uri); // $ SSRF
189189

190-
BasicHttpRequests.delete(uri.toString()); // $ SSRF
191-
BasicHttpRequests.delete(uri); // $ SSRF
190+
ClassicHttpRequests.delete(uri.toString()); // $ SSRF
191+
ClassicHttpRequests.delete(uri); // $ SSRF
192192

193193
ClassicHttpRequests.get(uri.toString()); // $ SSRF
194194
ClassicHttpRequests.get(uri); // $ SSRF
@@ -243,4 +243,46 @@ protected void doGet2(HttpServletRequest request, HttpServletResponse response)
243243
// TODO: handle exception
244244
}
245245
}
246+
247+
// org.apache.hc.client5.http.fluent
248+
protected void doGet3(HttpServletRequest request, HttpServletResponse response)
249+
throws ServletException, IOException {
250+
try {
251+
252+
String uriSink = request.getParameter("uri");
253+
URI uri = new URI(uriSink);
254+
255+
// org.apache.hc.client5.http.fluent.Request
256+
Request.create(Method.CONNECT, uri); // $ SSRF
257+
Request.create("method", uri.toString()); // $ SSRF
258+
Request.create("method", uri); // $ SSRF
259+
260+
Request.delete(uri.toString()); // $ SSRF
261+
Request.delete(uri); // $ SSRF
262+
263+
Request.get(uri.toString()); // $ SSRF
264+
Request.get(uri); // $ SSRF
265+
266+
Request.head(uri.toString()); // $ SSRF
267+
Request.head(uri); // $ SSRF
268+
269+
Request.options(uri.toString()); // $ SSRF
270+
Request.options(uri); // $ SSRF
271+
272+
Request.patch(uri.toString()); // $ SSRF
273+
Request.patch(uri); // $ SSRF
274+
275+
Request.post(uri.toString()); // $ SSRF
276+
Request.post(uri); // $ SSRF
277+
278+
Request.put(uri.toString()); // $ SSRF
279+
Request.put(uri); // $ SSRF
280+
281+
Request.trace(uri.toString()); // $ SSRF
282+
Request.trace(uri); // $ SSRF
283+
284+
} catch (Exception e) {
285+
// TODO: handle exception
286+
}
287+
}
246288
}

0 commit comments

Comments
 (0)