forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServlets.qll
More file actions
324 lines (294 loc) · 9.49 KB
/
Servlets.qll
File metadata and controls
324 lines (294 loc) · 9.49 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/**
* Provides classes and predicates for working with the Java Servlet API.
*/
import semmle.code.java.Type
/**
* The interface `javax.servlet.ServletRequest` or
* `javax.servlet.http.HttpServletRequest`.
*/
library class ServletRequest extends RefType {
ServletRequest() {
hasQualifiedName("javax.servlet", "ServletRequest") or
this instanceof HttpServletRequest
}
}
/**
* The interface `javax.servlet.http.HttpServletRequest`.
*/
library class HttpServletRequest extends RefType {
HttpServletRequest() { hasQualifiedName("javax.servlet.http", "HttpServletRequest") }
}
/**
* The method `getParameter(String)` or `getParameterValues(String)`
* declared in `javax.servlet.ServletRequest`.
*/
library class ServletRequestGetParameterMethod extends Method {
ServletRequestGetParameterMethod() {
getDeclaringType() instanceof ServletRequest and
(
hasName("getParameter") or
hasName("getParameterValues")
) and
getNumberOfParameters() = 1 and
getParameter(0).getType() instanceof TypeString
}
}
/**
* The method `getParameterNames()` declared in `javax.servlet.ServletRequest`.
*/
library class ServletRequestGetParameterNamesMethod extends Method {
ServletRequestGetParameterNamesMethod() {
getDeclaringType() instanceof ServletRequest and
hasName("getParameterNames") and
getNumberOfParameters() = 0
}
}
/**
* The method `getParameterMap()` declared in `javax.servlet.ServletRequest`.
*/
library class ServletRequestGetParameterMapMethod extends Method {
ServletRequestGetParameterMapMethod() {
getDeclaringType() instanceof ServletRequest and
hasName("getParameterMap") and
getNumberOfParameters() = 0
}
}
/**
* The method `getQueryString()` declared in `javax.servlet.http.HttpServletRequest`.
*/
library class HttpServletRequestGetQueryStringMethod extends Method {
HttpServletRequestGetQueryStringMethod() {
getDeclaringType() instanceof HttpServletRequest and
hasName("getQueryString") and
getNumberOfParameters() = 0
}
}
/**
* The method `getPathInfo()` declared in `javax.servlet.http.HttpServletRequest`.
*/
library class HttpServletRequestGetPathMethod extends Method {
HttpServletRequestGetPathMethod() {
getDeclaringType() instanceof HttpServletRequest and
hasName("getPathInfo") and
getNumberOfParameters() = 0
}
}
/**
* The method `getHeader(String)` declared in `javax.servlet.http.HttpServletRequest`.
*/
library class HttpServletRequestGetHeaderMethod extends Method {
HttpServletRequestGetHeaderMethod() {
getDeclaringType() instanceof HttpServletRequest and
hasName("getHeader") and
getNumberOfParameters() = 1 and
getParameter(0).getType() instanceof TypeString
}
}
/**
* The method `getHeaders(String)` declared in `javax.servlet.http.HttpServletRequest`.
*/
library class HttpServletRequestGetHeadersMethod extends Method {
HttpServletRequestGetHeadersMethod() {
getDeclaringType() instanceof HttpServletRequest and
hasName("getHeaders") and
getNumberOfParameters() = 1 and
getParameter(0).getType() instanceof TypeString
}
}
/**
* The method `getHeaderNames()` declared in `javax.servlet.http.HttpServletRequest`.
*/
library class HttpServletRequestGetHeaderNamesMethod extends Method {
HttpServletRequestGetHeaderNamesMethod() {
getDeclaringType() instanceof HttpServletRequest and
hasName("getHeaderNames") and
getNumberOfParameters() = 0
}
}
/**
* The method `getRequestURL()` declared in `javax.servlet.http.HttpServletRequest`.
*/
library class HttpServletRequestGetRequestURLMethod extends Method {
HttpServletRequestGetRequestURLMethod() {
getDeclaringType() instanceof HttpServletRequest and
hasName("getRequestURL") and
getNumberOfParameters() = 0
}
}
/**
* The method `getRequestURI()` declared in `javax.servlet.http.HttpServletRequest`.
*/
library class HttpServletRequestGetRequestURIMethod extends Method {
HttpServletRequestGetRequestURIMethod() {
getDeclaringType() instanceof HttpServletRequest and
hasName("getRequestURI") and
getNumberOfParameters() = 0
}
}
/**
* The method `getRemoteUser()` declared in `javax.servlet.http.HttpServletRequest`.
*/
library class HttpServletRequestGetRemoteUserMethod extends Method {
HttpServletRequestGetRemoteUserMethod() {
getDeclaringType() instanceof HttpServletRequest and
hasName("getRemoteUser") and
getNumberOfParameters() = 0
}
}
/**
* The method `getInputStream()` or `getReader()` declared in `javax.servlet.ServletRequest`.
*/
library class ServletRequestGetBodyMethod extends Method {
ServletRequestGetBodyMethod() {
getDeclaringType() instanceof ServletRequest and
(hasName("getInputStream") or hasName("getReader"))
}
}
/**
* The interface `javax.servlet.ServletResponse` or
* `javax.servlet.http.HttpServletResponse`.
*/
class ServletResponse extends RefType {
ServletResponse() {
hasQualifiedName("javax.servlet", "ServletResponse") or
this instanceof HttpServletResponse
}
}
/**
* The interface `javax.servlet.http.HttpServletResponse`.
*/
class HttpServletResponse extends RefType {
HttpServletResponse() { hasQualifiedName("javax.servlet.http", "HttpServletResponse") }
}
/**
* The method `sendError(int,String)` declared in `javax.servlet.http.HttpServletResponse`.
*/
class HttpServletResponseSendErrorMethod extends Method {
HttpServletResponseSendErrorMethod() {
getDeclaringType() instanceof HttpServletResponse and
hasName("sendError") and
getNumberOfParameters() = 2 and
getParameter(0).getType().hasName("int") and
getParameter(1).getType() instanceof TypeString
}
}
/**
* The method `sendRedirect(String)` declared in `javax.servlet.http.HttpServletResponse`.
*/
class HttpServletResponseSendRedirectMethod extends Method {
HttpServletResponseSendRedirectMethod() {
getDeclaringType() instanceof HttpServletResponse and
hasName("sendRedirect") and
getNumberOfParameters() = 1 and
getParameter(0).getType() instanceof TypeString
}
}
/**
* The method `getWriter()` declared in `javax.servlet.ServletResponse`.
*/
class ServletResponseGetWriterMethod extends Method {
ServletResponseGetWriterMethod() {
getDeclaringType() instanceof ServletResponse and
hasName("getWriter") and
getNumberOfParameters() = 0
}
}
/**
* The method `getOutputStream()` declared in `javax.servlet.ServletResponse`.
*/
class ServletResponseGetOutputStreamMethod extends Method {
ServletResponseGetOutputStreamMethod() {
getDeclaringType() instanceof ServletResponse and
hasName("getOutputStream") and
getNumberOfParameters() = 0
}
}
/** The class `javax.servlet.http.Cookie`. */
library class TypeCookie extends Class {
TypeCookie() { hasQualifiedName("javax.servlet.http", "Cookie") }
}
/**
* The method `getValue(String)` declared in `javax.servlet.http.Cookie`.
*/
library class CookieGetValueMethod extends Method {
CookieGetValueMethod() {
getDeclaringType() instanceof TypeCookie and
hasName("getValue") and
getReturnType() instanceof TypeString
}
}
/**
* The method `getName()` declared in `javax.servlet.http.Cookie`.
*/
library class CookieGetNameMethod extends Method {
CookieGetNameMethod() {
getDeclaringType() instanceof TypeCookie and
hasName("getName") and
getReturnType() instanceof TypeString and
getNumberOfParameters() = 0
}
}
/**
* The method `getComment()` declared in `javax.servlet.http.Cookie`.
*/
library class CookieGetCommentMethod extends Method {
CookieGetCommentMethod() {
getDeclaringType() instanceof TypeCookie and
hasName("getComment") and
getReturnType() instanceof TypeString and
getNumberOfParameters() = 0
}
}
/**
* The method `addCookie(String)` declared in `javax.servlet.http.Cookie`.
*/
class ResponseAddCookieMethod extends Method {
ResponseAddCookieMethod() {
getDeclaringType() instanceof HttpServletResponse and
hasName("addCookie")
}
}
/**
* The method `addHeader` declared in `javax.servlet.http.HttpServletResponse`.
*/
class ResponseAddHeaderMethod extends Method {
ResponseAddHeaderMethod() {
getDeclaringType() instanceof HttpServletResponse and
hasName("addHeader")
}
}
/**
* The method `setHeader` declared in `javax.servlet.http.HttpServletResponse`.
*/
class ResponseSetHeaderMethod extends Method {
ResponseSetHeaderMethod() {
getDeclaringType() instanceof HttpServletResponse and
hasName("setHeader")
}
}
/**
* A class that has `javax.servlet.Servlet` as an ancestor.
*/
class ServletClass extends Class {
ServletClass() { getAnAncestor().hasQualifiedName("javax.servlet", "Servlet") }
}
/**
* The set of `Servlet` listener types that can be specified in a `web.xml` file.
*
* Note: There are a number of other listener interfaces in the `javax.servlet` package that cannot
* be configured in `web.xml` and therefore are not covered by this class.
*/
class ServletWebXMLListenerType extends RefType {
ServletWebXMLListenerType() {
hasQualifiedName("javax.servlet", "ServletContextAttributeListener") or
hasQualifiedName("javax.servlet", "ServletContextListener") or
hasQualifiedName("javax.servlet", "ServletRequestAttributeListener") or
hasQualifiedName("javax.servlet", "ServletRequestListener") or
hasQualifiedName("javax.servlet.http", "HttpSessionAttributeListener") or
hasQualifiedName("javax.servlet.http", "HttpSessionIdListener") or
hasQualifiedName("javax.servlet.http", "HttpSessionListener")
// Listeners that are not configured in `web.xml`:
// - `HttpSessionActivationListener`
// - `HttpSessionBindingListener`
}
}