@@ -9,6 +9,7 @@ import semmle.code.java.frameworks.javase.Http
9
9
import semmle.code.java.dataflow.DataFlow
10
10
import semmle.code.java.dataflow.TaintTracking
11
11
private import semmle.code.java.StringFormat
12
+ private import semmle.code.java.dataflow.ExternalFlow
12
13
13
14
/**
14
15
* A unit class for adding additional taint steps that are specific to server-side request forgery (SSRF) attacks.
@@ -30,185 +31,14 @@ private class DefaultRequestForgeryAdditionalTaintStep extends RequestForgeryAdd
30
31
or
31
32
// propagate to a URL when its host is assigned to
32
33
exists ( UrlConstructorCall c | c .getHostArg ( ) = pred .asExpr ( ) | succ .asExpr ( ) = c )
33
- or
34
- // propagate to a RequestEntity when its url is assigned to
35
- exists ( MethodAccess m |
36
- m .getMethod ( ) .getDeclaringType ( ) instanceof SpringRequestEntity and
37
- (
38
- m .getMethod ( ) .hasName ( [ "get" , "post" , "head" , "delete" , "options" , "patch" , "put" ] ) and
39
- m .getArgument ( 0 ) = pred .asExpr ( ) and
40
- m = succ .asExpr ( )
41
- or
42
- m .getMethod ( ) .hasName ( "method" ) and
43
- m .getArgument ( 1 ) = pred .asExpr ( ) and
44
- m = succ .asExpr ( )
45
- )
46
- )
47
- or
48
- // propagate from a `RequestEntity<>$BodyBuilder` to a `RequestEntity`
49
- // when the builder is tainted
50
- exists ( MethodAccess m , RefType t |
51
- m .getMethod ( ) .getDeclaringType ( ) = t and
52
- t .hasQualifiedName ( "org.springframework.http" , "RequestEntity<>$BodyBuilder" ) and
53
- m .getMethod ( ) .hasName ( "body" ) and
54
- m .getQualifier ( ) = pred .asExpr ( ) and
55
- m = succ .asExpr ( )
56
- )
57
34
}
58
35
}
59
36
60
37
/** A data flow sink for server-side request forgery (SSRF) vulnerabilities. */
61
38
abstract class RequestForgerySink extends DataFlow:: Node { }
62
39
63
- /**
64
- * An argument to a url `openConnection` or `openStream` call
65
- * taken as a sink for request forgery vulnerabilities.
66
- */
67
- private class UrlOpen extends RequestForgerySink {
68
- UrlOpen ( ) {
69
- exists ( MethodAccess ma |
70
- ma .getMethod ( ) instanceof UrlOpenConnectionMethod or
71
- ma .getMethod ( ) instanceof UrlOpenStreamMethod
72
- |
73
- this .asExpr ( ) = ma .getQualifier ( )
74
- )
75
- }
76
- }
77
-
78
- /**
79
- * An argument to an Apache `setURI` call taken as a
80
- * sink for request forgery vulnerabilities.
81
- */
82
- private class ApacheSetUri extends RequestForgerySink {
83
- ApacheSetUri ( ) {
84
- exists ( MethodAccess ma |
85
- ma .getReceiverType ( ) instanceof ApacheHttpRequest and
86
- ma .getMethod ( ) .hasName ( "setURI" )
87
- |
88
- this .asExpr ( ) = ma .getArgument ( 0 )
89
- )
90
- }
91
- }
92
-
93
- /**
94
- * An argument to any Apache `HttpRequest` instantiation taken as a
95
- * sink for request forgery vulnerabilities.
96
- */
97
- private class ApacheHttpRequestInstantiation extends RequestForgerySink {
98
- ApacheHttpRequestInstantiation ( ) {
99
- exists ( ClassInstanceExpr c | c .getConstructedType ( ) instanceof ApacheHttpRequest |
100
- this .asExpr ( ) = c .getArgument ( 0 )
101
- )
102
- }
103
- }
104
-
105
- /**
106
- * An argument to an Apache `RequestBuilder` method call taken as a
107
- * sink for request forgery vulnerabilities.
108
- */
109
- private class ApacheHttpRequestBuilderArgument extends RequestForgerySink {
110
- ApacheHttpRequestBuilderArgument ( ) {
111
- exists ( MethodAccess ma |
112
- ma .getReceiverType ( ) instanceof TypeApacheHttpRequestBuilder and
113
- ma .getMethod ( ) .hasName ( [ "setURI" , "get" , "post" , "put" , "optons" , "head" , "delete" ] )
114
- |
115
- this .asExpr ( ) = ma .getArgument ( 0 )
116
- )
117
- }
118
- }
119
-
120
- /**
121
- * An argument to any `java.net.http.HttpRequest` instantiation taken as a
122
- * sink for request forgery vulnerabilities.
123
- */
124
- private class HttpRequestNewBuilder extends RequestForgerySink {
125
- HttpRequestNewBuilder ( ) {
126
- exists ( MethodAccess call |
127
- call .getCallee ( ) .hasName ( "newBuilder" ) and
128
- call .getMethod ( ) .getDeclaringType ( ) .hasQualifiedName ( "java.net.http" , "HttpRequest" )
129
- |
130
- this .asExpr ( ) = call .getArgument ( 0 )
131
- )
132
- }
133
- }
134
-
135
- /**
136
- * An argument to an `HttpBuilder` `uri` call taken as a
137
- * sink for request forgery vulnerabilities.
138
- */
139
- private class HttpBuilderUriArgument extends RequestForgerySink {
140
- HttpBuilderUriArgument ( ) {
141
- exists ( MethodAccess ma | ma .getMethod ( ) instanceof HttpBuilderUri |
142
- this .asExpr ( ) = ma .getArgument ( 0 )
143
- )
144
- }
145
- }
146
-
147
- /**
148
- * An argument to a Spring `RestTemplate` method call taken as a
149
- * sink for request forgery vulnerabilities.
150
- */
151
- private class SpringRestTemplateArgument extends RequestForgerySink {
152
- SpringRestTemplateArgument ( ) {
153
- this .asExpr ( ) = any ( SpringRestTemplateUrlMethodAccess m ) .getUrlArgument ( )
154
- }
155
- }
156
-
157
- /**
158
- * An argument to a `javax.ws.rs.Client` `target` method call taken as a
159
- * sink for request forgery vulnerabilities.
160
- */
161
- private class JaxRsClientTarget extends RequestForgerySink {
162
- JaxRsClientTarget ( ) {
163
- exists ( MethodAccess ma |
164
- ma .getMethod ( ) .getDeclaringType ( ) instanceof JaxRsClient and
165
- ma .getMethod ( ) .hasName ( "target" )
166
- |
167
- this .asExpr ( ) = ma .getArgument ( 0 )
168
- )
169
- }
170
- }
171
-
172
- /**
173
- * A URI argument to an `org.springframework.http.RequestEntity` constructor call
174
- * taken as a sink for request forgery vulnerabilities.
175
- */
176
- private class RequestEntityUriArg extends RequestForgerySink {
177
- RequestEntityUriArg ( ) {
178
- exists ( ClassInstanceExpr e , Argument a |
179
- e .getConstructedType ( ) instanceof SpringRequestEntity and
180
- e .getAnArgument ( ) = a and
181
- a .getType ( ) instanceof TypeUri and
182
- this .asExpr ( ) = a
183
- )
184
- }
185
- }
186
-
187
- /**
188
- * A Spring Rest Template method
189
- * that takes a URL as an argument.
190
- */
191
- private class SpringRestTemplateUrlMethod extends Method {
192
- SpringRestTemplateUrlMethod ( ) {
193
- this .getDeclaringType ( ) instanceof SpringRestTemplate and
194
- this .hasName ( [
195
- "doExecute" , "postForEntity" , "postForLocation" , "postForObject" , "put" , "exchange" ,
196
- "execute" , "getForEntity" , "getForObject" , "patchForObject"
197
- ] )
198
- }
199
- }
200
-
201
- /**
202
- * A call to a Spring Rest Template method
203
- * that takes a URL as an argument.
204
- */
205
- private class SpringRestTemplateUrlMethodAccess extends MethodAccess {
206
- SpringRestTemplateUrlMethodAccess ( ) { this .getMethod ( ) instanceof SpringRestTemplateUrlMethod }
207
-
208
- /**
209
- * Gets the URL argument of this template call.
210
- */
211
- Argument getUrlArgument ( ) { result = this .getArgument ( 0 ) }
40
+ private class UrlOpenSinkAsRequestForgerySink extends RequestForgerySink {
41
+ UrlOpenSinkAsRequestForgerySink ( ) { sinkNode ( this , "open-url" ) }
212
42
}
213
43
214
44
/** A sanitizer for request forgery vulnerabilities. */
0 commit comments