Skip to content

Commit 57ca36b

Browse files
committed
Tidy Spring test
1 parent 8b080a9 commit 57ca36b

File tree

1 file changed

+36
-65
lines changed

1 file changed

+36
-65
lines changed

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

Lines changed: 36 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -28,72 +28,43 @@ protected void doGet(HttpServletRequest request2, HttpServletResponse response2)
2828
RestTemplate restTemplate = new RestTemplate();
2929
HttpEntity<String> request = new HttpEntity<>(new String("bar"));
3030
try {
31-
{
32-
ResponseEntity<String> response =
33-
restTemplate.getForEntity(fooResourceUrl + "/1", String.class); // $ SSRF
34-
}
35-
36-
{
37-
ResponseEntity<String> response =
38-
restTemplate.exchange(fooResourceUrl, HttpMethod.POST, request, String.class); // $ SSRF
39-
}
40-
{
41-
ResponseEntity<String> response =
42-
restTemplate.execute(fooResourceUrl, HttpMethod.POST, null, null, "test"); // $ SSRF
43-
}
44-
{
45-
String response =
46-
restTemplate.getForObject(fooResourceUrl, String.class, "test"); // $ SSRF
47-
}
48-
{
49-
String body = new String("body");
50-
URI uri = new URI(fooResourceUrl);
51-
RequestEntity<String> requestEntity =
52-
RequestEntity.post(uri).body(body); // $ SSRF
53-
ResponseEntity<String> response = restTemplate.exchange(requestEntity, String.class);
54-
RequestEntity.get(uri); // $ SSRF
55-
RequestEntity.put(uri); // $ SSRF
56-
RequestEntity.delete(uri); // $ SSRF
57-
RequestEntity.options(uri); // $ SSRF
58-
RequestEntity.patch(uri); // $ SSRF
59-
RequestEntity.head(uri); // $ SSRF
60-
RequestEntity.method(null, uri); // $ SSRF
61-
}
62-
{
63-
String response = restTemplate.patchForObject(fooResourceUrl, new String("object"), // $ SSRF
64-
String.class, "hi");
65-
}
66-
{
67-
ResponseEntity<String> response = restTemplate.postForEntity(new URI(fooResourceUrl), // $ SSRF
68-
new String("object"), String.class);
69-
}
70-
{
71-
URI response = restTemplate.postForLocation(fooResourceUrl, new String("object")); // $ SSRF
72-
}
73-
{
74-
String response =
75-
restTemplate.postForObject(fooResourceUrl, new String("object"), String.class); // $ SSRF
76-
}
77-
{
31+
restTemplate.getForEntity(fooResourceUrl + "/1", String.class); // $ SSRF
32+
restTemplate.exchange(fooResourceUrl, HttpMethod.POST, request, String.class); // $ SSRF
33+
restTemplate.execute(fooResourceUrl, HttpMethod.POST, null, null, "test"); // $ SSRF
34+
restTemplate.getForObject(fooResourceUrl, String.class, "test"); // $ SSRF
35+
restTemplate.patchForObject(fooResourceUrl, new String("object"), String.class, "hi"); // $ SSRF
36+
restTemplate.postForEntity(new URI(fooResourceUrl), new String("object"), String.class); // $ SSRF
37+
restTemplate.postForLocation(fooResourceUrl, new String("object")); // $ SSRF
38+
restTemplate.postForObject(fooResourceUrl, new String("object"), String.class); // $ SSRF
7839
restTemplate.put(fooResourceUrl, new String("object")); // $ SSRF
79-
}
80-
{
81-
URI uri = new URI(fooResourceUrl);
82-
MultiValueMap<String, String> headers = null;
83-
java.lang.reflect.Type type = null;
84-
new RequestEntity<String>(null, uri); // $ SSRF
85-
new RequestEntity<String>(headers, null, uri); // $ SSRF
86-
new RequestEntity<String>("body", null, uri); // $ SSRF
87-
new RequestEntity<String>("body", headers, null, uri); // $ SSRF
88-
new RequestEntity<String>("body", null, uri, type); // $ SSRF
89-
new RequestEntity<String>("body", headers, null, uri, type); // $ SSRF
90-
}
91-
{
92-
URI uri = new URI(fooResourceUrl);
93-
restTemplate.delete(uri); // $ SSRF
94-
restTemplate.headForHeaders(uri); // $ SSRF
95-
restTemplate.optionsForAllow(uri); // $ SSRF
96-
}
40+
restTemplate.delete(fooResourceUrl); // $ SSRF
41+
restTemplate.headForHeaders(fooResourceUrl); // $ SSRF
42+
restTemplate.optionsForAllow(fooResourceUrl); // $ SSRF
43+
{
44+
String body = new String("body");
45+
URI uri = new URI(fooResourceUrl);
46+
RequestEntity<String> requestEntity =
47+
RequestEntity.post(uri).body(body); // $ SSRF
48+
ResponseEntity<String> response = restTemplate.exchange(requestEntity, String.class);
49+
RequestEntity.get(uri); // $ SSRF
50+
RequestEntity.put(uri); // $ SSRF
51+
RequestEntity.delete(uri); // $ SSRF
52+
RequestEntity.options(uri); // $ SSRF
53+
RequestEntity.patch(uri); // $ SSRF
54+
RequestEntity.head(uri); // $ SSRF
55+
RequestEntity.method(null, uri); // $ SSRF
56+
}
57+
{
58+
URI uri = new URI(fooResourceUrl);
59+
MultiValueMap<String, String> headers = null;
60+
java.lang.reflect.Type type = null;
61+
new RequestEntity<String>(null, uri); // $ SSRF
62+
new RequestEntity<String>(headers, null, uri); // $ SSRF
63+
new RequestEntity<String>("body", null, uri); // $ SSRF
64+
new RequestEntity<String>("body", headers, null, uri); // $ SSRF
65+
new RequestEntity<String>("body", null, uri, type); // $ SSRF
66+
new RequestEntity<String>("body", headers, null, uri, type); // $ SSRF
67+
}
9768
} catch (org.springframework.web.client.RestClientException | java.net.URISyntaxException e) {}
9869
}
9970
}

0 commit comments

Comments
 (0)