-
Notifications
You must be signed in to change notification settings - Fork 725
Expand file tree
/
Copy pathSpringRequestMappingMethodCheckSample.java
More file actions
137 lines (107 loc) · 3.72 KB
/
SpringRequestMappingMethodCheckSample.java
File metadata and controls
137 lines (107 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package checks.spring;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/home")
public class SpringRequestMappingMethodCheckSample {
@RequestMapping("/") // Noncompliant {{Make sure allowing safe and unsafe HTTP methods is safe here.}}
// ^^^^^^^^^^^^^^
String home() {
return "Hello from get";
}
@RequestMapping(path = "/index", method = RequestMethod.GET)
String index() {
return "Hello from index";
}
@RequestMapping(path = "/list", method = {RequestMethod.POST})
String list() {
return "Hello from list";
}
@GetMapping(path = "/get")
String get() {
return "Hello from get";
}
@RequestMapping(path = "/delete", method = {RequestMethod.GET, RequestMethod.POST}) // Noncompliant {{Make sure allowing safe and unsafe HTTP methods is safe here.}}
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
String delete(@RequestParam("id") String id) {
return "Hello from delete";
}
@RequestMapping(path = "/safe", method = {RequestMethod.GET, RequestMethod.HEAD, RequestMethod.OPTIONS, RequestMethod.TRACE}) // Compliant
String safe(@RequestParam("id") String id) {
return "safe";
}
@RequestMapping(path = "/unsafe", method = {RequestMethod.DELETE, RequestMethod.PATCH, RequestMethod.POST, RequestMethod.PUT}) // Compliant
String unsafe(@RequestParam("id") String id) {
return "unsafe";
}
@RequestMapping(path = "/all", method = { // Noncompliant
RequestMethod.GET, RequestMethod.HEAD, RequestMethod.OPTIONS, RequestMethod.TRACE,
RequestMethod.DELETE, RequestMethod.PATCH, RequestMethod.POST, RequestMethod.PUT
})
String all(@RequestParam("id") String id) {
return "all";
}
@RestController
@RequestMapping(path = "/other", method = RequestMethod.GET)
public static class OtherController {
@RequestMapping("/")
String get() {
return "Hello from get";
}
@RequestMapping(value = "/post", method = RequestMethod.POST) // Noncompliant
String post() {
return "Hello from post";
}
@RequestMapping(value = "/put", method = RequestMethod.PUT) // Noncompliant
String put() {
return "Hello from put";
}
@RequestMapping(value = "/delete", method = RequestMethod.DELETE) // Noncompliant
String delete() {
return "Hello from delete";
}
}
@RestController
@RequestMapping(path = "/update", method = RequestMethod.POST)
public static class UpdateController {
@RequestMapping(value = "/", method = RequestMethod.GET) // Noncompliant
String get() {
return "Hello from get";
}
@RequestMapping(value = "/head", method = RequestMethod.HEAD) // Noncompliant
String head() {
return "Hello from head";
}
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
String delete() {
return "Hello from delete";
}
}
public static class DerivedController extends OtherController {
@RequestMapping("/")
String get() {
return "Hello from get";
}
}
interface X {}
@RequestMapping(path = "/other", method = RequestMethod.GET)
interface InterfaceController extends X {
}
@RestController
public static class ControllerImpl implements InterfaceController {
@RequestMapping("/")
String get() {
return "Hello from get";
}
}
interface Dummy { }
public static class DummyFoo implements Dummy {
@RequestMapping(path = "/other") // Noncompliant
String get() {
return "Hello from get";
}
}
}