@@ -19,12 +19,10 @@ class SpringControllerAnnotation extends AnnotationType {
1919/**
2020 * An annotation type that identifies Spring rest controllers.
2121 *
22- * Rest controllers are the same as controllers, but imply the @ResponseBody annotation.
22+ * Rest controllers are the same as controllers, but imply the ` @ResponseBody` annotation.
2323 */
2424class SpringRestControllerAnnotation extends SpringControllerAnnotation {
25- SpringRestControllerAnnotation ( ) {
26- hasName ( "RestController" )
27- }
25+ SpringRestControllerAnnotation ( ) { hasName ( "RestController" ) }
2826}
2927
3028/**
@@ -80,7 +78,7 @@ class SpringInitBinderMethod extends SpringControllerMethod {
8078}
8179
8280/**
83- * An `AnnotationType` which is used to indicate a `RequestMapping`.
81+ * An `AnnotationType` that is used to indicate a `RequestMapping`.
8482 */
8583class SpringRequestMappingAnnotationType extends AnnotationType {
8684 SpringRequestMappingAnnotationType ( ) {
@@ -93,7 +91,7 @@ class SpringRequestMappingAnnotationType extends AnnotationType {
9391}
9492
9593/**
96- * An `AnnotationType` which is used to indicate a `ResponseBody`.
94+ * An `AnnotationType` that is used to indicate a `ResponseBody`.
9795 */
9896class SpringResponseBodyAnnotationType extends AnnotationType {
9997 SpringResponseBodyAnnotationType ( ) {
@@ -107,6 +105,7 @@ class SpringResponseBodyAnnotationType extends AnnotationType {
107105 */
108106class SpringRequestMappingMethod extends SpringControllerMethod {
109107 Annotation requestMappingAnnotation ;
108+
110109 SpringRequestMappingMethod ( ) {
111110 // Any method that declares the @RequestMapping annotation, or overrides a method that declares
112111 // the annotation. We have to do this explicit check because the @RequestMapping annotation is
@@ -119,21 +118,18 @@ class SpringRequestMappingMethod extends SpringControllerMethod {
119118 }
120119
121120 /** Gets a request mapping parameter. */
122- SpringRequestMappingParameter getARequestParameter ( ) {
123- result = getAParameter ( )
124- }
121+ SpringRequestMappingParameter getARequestParameter ( ) { result = getAParameter ( ) }
125122
126123 /** Gets the "produces" @RequestMapping annotation value, if present. */
127124 string getProduces ( ) {
128- result = requestMappingAnnotation .getValue ( "produces" ) .( CompileTimeConstantExpr ) .getStringValue ( )
125+ result =
126+ requestMappingAnnotation .getValue ( "produces" ) .( CompileTimeConstantExpr ) .getStringValue ( )
129127 }
130128
131- /** Holds if this is considered an @ResponseBody method. */
129+ /** Holds if this is considered an ` @ResponseBody` method. */
132130 predicate isResponseBody ( ) {
133- getAnAnnotation ( ) .getType ( ) instanceof SpringResponseBodyAnnotationType
134- or
135- getDeclaringType ( ) .getAnAnnotation ( ) .getType ( ) instanceof SpringResponseBodyAnnotationType
136- or
131+ getAnAnnotation ( ) .getType ( ) instanceof SpringResponseBodyAnnotationType or
132+ getDeclaringType ( ) .getAnAnnotation ( ) .getType ( ) instanceof SpringResponseBodyAnnotationType or
137133 getDeclaringType ( ) instanceof SpringRestController
138134 }
139135}
@@ -156,12 +152,14 @@ class SpringServletInputAnnotation extends Annotation {
156152 }
157153}
158154
155+ /** An annotation of the type `org.springframework.web.bind.annotation.ModelAttribute`. */
159156class SpringModelAttributeAnnotation extends Annotation {
160157 SpringModelAttributeAnnotation ( ) {
161158 getType ( ) .hasQualifiedName ( "org.springframework.web.bind.annotation" , "ModelAttribute" )
162159 }
163160}
164161
162+ /** A parameter of a `SpringRequestMappingMethod`. */
165163class SpringRequestMappingParameter extends Parameter {
166164 SpringRequestMappingParameter ( ) { getCallable ( ) instanceof SpringRequestMappingMethod }
167165
@@ -180,29 +178,47 @@ class SpringRequestMappingParameter extends Parameter {
180178 getType ( ) .( RefType ) .getAnAncestor ( ) .hasQualifiedName ( "java.time" , "ZoneId" ) or
181179 getType ( ) .( RefType ) .getAnAncestor ( ) .hasQualifiedName ( "java.io" , "OutputStream" ) or
182180 getType ( ) .( RefType ) .getAnAncestor ( ) .hasQualifiedName ( "java.io" , "Writer" ) or
183- getType ( ) .( RefType ) .getAnAncestor ( ) .hasQualifiedName ( "org.springframework.web.servlet.mvc.support" , "RedirectAttributes" ) or
181+ getType ( )
182+ .( RefType )
183+ .getAnAncestor ( )
184+ .hasQualifiedName ( "org.springframework.web.servlet.mvc.support" , "RedirectAttributes" ) or
184185 // Also covers BindingResult. Note, you can access the field value through this interface, which should be considered tainted
185186 getType ( ) .( RefType ) .getAnAncestor ( ) .hasQualifiedName ( "org.springframework.validation" , "Errors" ) or
186- getType ( ) .( RefType ) .getAnAncestor ( ) .hasQualifiedName ( "org.springframework.web.bind.support" , "SessionStatus" ) or
187- getType ( ) .( RefType ) .getAnAncestor ( ) .hasQualifiedName ( "org.springframework.web.util" , "UriComponentsBuilder" ) or
188- getType ( ) .( RefType ) .getAnAncestor ( ) .hasQualifiedName ( "org.springframework.data.domain" , "Pageable" ) or
187+ getType ( )
188+ .( RefType )
189+ .getAnAncestor ( )
190+ .hasQualifiedName ( "org.springframework.web.bind.support" , "SessionStatus" ) or
191+ getType ( )
192+ .( RefType )
193+ .getAnAncestor ( )
194+ .hasQualifiedName ( "org.springframework.web.util" , "UriComponentsBuilder" ) or
195+ getType ( )
196+ .( RefType )
197+ .getAnAncestor ( )
198+ .hasQualifiedName ( "org.springframework.data.domain" , "Pageable" ) or
189199 this instanceof SpringModel
190200 }
191201
192- predicate isExplicitlyTaintedInput ( ) {
202+ private predicate isExplicitlyTaintedInput ( ) {
193203 // InputStream or Reader parameters allow access to the body of a request
194204 getType ( ) .( RefType ) .getAnAncestor ( ) .hasQualifiedName ( "java.io" , "InputStream" ) or
195205 getType ( ) .( RefType ) .getAnAncestor ( ) .hasQualifiedName ( "java.io" , "Reader" ) or
196206 // The SpringServletInputAnnotations allow access to the URI, request parameters, cookie values and the body of the request
197207 this .getAnAnnotation ( ) instanceof SpringServletInputAnnotation or
198208 // HttpEntity is like @RequestBody, but with a wrapper including the headers
199209 // TODO model unwrapping aspects
200- getType ( ) .( RefType ) .getAnAncestor ( ) .hasQualifiedName ( "org.springframework.http" , "HttpEntity<T>" ) or
201- this .getAnAnnotation ( ) .getType ( ) .hasQualifiedName ( "org.springframework.web.bind.annotation" , "RequestAttribute" ) or
202- this .getAnAnnotation ( ) .getType ( ) .hasQualifiedName ( "org.springframework.web.bind.annotation" , "SessionAttribute" )
210+ getType ( ) .( RefType ) .getASourceSupertype * ( ) instanceof SpringHttpEntity or
211+ this
212+ .getAnAnnotation ( )
213+ .getType ( )
214+ .hasQualifiedName ( "org.springframework.web.bind.annotation" , "RequestAttribute" ) or
215+ this
216+ .getAnAnnotation ( )
217+ .getType ( )
218+ .hasQualifiedName ( "org.springframework.web.bind.annotation" , "SessionAttribute" )
203219 }
204220
205- predicate isImplicitRequestParam ( ) {
221+ private predicate isImplicitRequestParam ( ) {
206222 // Any parameter which is not explicitly handled, is consider to be an `@RequestParam`, if
207223 // it is a simple bean property
208224 not isNotDirectlyTaintedInput ( ) and
@@ -213,23 +229,24 @@ class SpringRequestMappingParameter extends Parameter {
213229 )
214230 }
215231
216- predicate isImplicitModelAttribute ( ) {
232+ private predicate isImplicitModelAttribute ( ) {
217233 // Any parameter which is not explicitly handled, is consider to be an `@ModelAttribute`, if
218234 // it is not an implicit request param
219235 not isNotDirectlyTaintedInput ( ) and
220236 not isExplicitlyTaintedInput ( ) and
221237 not isImplicitRequestParam ( )
222238 }
223239
224- /** Holds if this is an explicit or implicit @ModelAttribute parameter */
240+ /** Holds if this is an explicit or implicit ` @ModelAttribute` parameter. */
225241 predicate isModelAttribute ( ) {
226242 isImplicitModelAttribute ( ) or
227243 getAnAnnotation ( ) instanceof SpringModelAttributeAnnotation
228244 }
229245
230- /** Holds if the input is tainted */
246+ /** Holds if the input is tainted. */
231247 predicate isTaintedInput ( ) {
232- isExplicitlyTaintedInput ( ) or
248+ isExplicitlyTaintedInput ( )
249+ or
233250 // Any parameter which is not explicitly identified, is consider to be an `@RequestParam`, if
234251 // it is a simple bean property) or a @ModelAttribute if not
235252 not isNotDirectlyTaintedInput ( )
@@ -305,18 +322,18 @@ private RefType stripType(Type t) {
305322}
306323
307324/**
308- * A user data type which may be populated from a HTTP request.
325+ * A user data type that may be populated from an HTTP request.
309326 *
310- * This includes types directly referred to as either @ModelAttribute or @RequestBody parameters,
311- * or types which are referred to by those types.
327+ * This includes types directly referred to as either ` @ModelAttribute` or ` @RequestBody` parameters,
328+ * or types that are referred to by those types.
312329 */
313330class SpringUntrustedDataType extends RefType {
314331 SpringUntrustedDataType ( ) {
315332 exists ( SpringRequestMappingParameter p |
316333 p .isModelAttribute ( )
317334 or
318335 p .getAnAnnotation ( ) .( SpringServletInputAnnotation ) .getType ( ) .hasName ( "RequestBody" )
319- |
336+ |
320337 this .fromSource ( ) and
321338 this = stripType ( p .getType ( ) )
322339 )
0 commit comments