11/**
2- * Provides classes and predicates related to `org.apache.http.*`.
2+ * Provides classes and predicates related to `org.apache.http.*` and `org.apache.hc.*` .
33 */
44
55import java
@@ -42,12 +42,13 @@ class TypeApacheHttpRequestBuilder extends Class {
4242}
4343
4444/**
45- * The `request` parameter of an implementation of `org.apache.http.protocol. HttpRequestHandler.handle`.
45+ * The `request` parameter of an implementation of `HttpRequestHandler.handle`.
4646 */
4747class ApacheHttpRequestHandlerParameter extends Parameter {
4848 ApacheHttpRequestHandlerParameter ( ) {
4949 exists ( Method m , Interface i |
50- i .hasQualifiedName ( "org.apache.http.protocol" , "HttpRequestHandler" ) and
50+ i .hasQualifiedName ( [ "org.apache.http.protocol" , "org.apache.hc.core5.http.io" ] ,
51+ "HttpRequestHandler" ) and
5152 m .getDeclaringType ( ) .extendsOrImplements + ( i ) and
5253 m .hasName ( "handle" ) and
5354 this = m .getParameter ( 0 )
@@ -56,7 +57,7 @@ class ApacheHttpRequestHandlerParameter extends Parameter {
5657}
5758
5859/**
59- * A call that sets the entity of an instance of `org.apache.http.HttpResponse`.
60+ * A call that sets the entity of an instance of `org.apache.http.HttpResponse` / `org.apache.hc.core5.http.ClassicHttpResponse` .
6061 */
6162class ApacheHttpResponseSetEntityCall extends MethodAccess {
6263 int arg ;
@@ -70,6 +71,10 @@ class ApacheHttpResponseSetEntityCall extends MethodAccess {
7071 m .getDeclaringType ( ) .hasQualifiedName ( "org.apache.http.util" , "EntityUtils" ) and
7172 m .hasName ( "updateEntity" ) and
7273 arg = 1
74+ or
75+ m .getDeclaringType ( ) .hasQualifiedName ( "org.apache.hc.core5.http" , "HttpEntityContainer" ) and
76+ m .hasName ( "setEntity" ) and
77+ arg = 0
7378 )
7479 }
7580
@@ -79,6 +84,7 @@ class ApacheHttpResponseSetEntityCall extends MethodAccess {
7984 Expr getEntity ( ) { result = this .getArgument ( arg ) }
8085}
8186
87+ /** A getter that returns tainted data when its qualifier is tainted. */
8288private class ApacheHttpGetter extends TaintPreservingCallable {
8389 ApacheHttpGetter ( ) {
8490 exists ( string pkg , string ty , string mtd , Method m |
@@ -123,6 +129,36 @@ private class ApacheHttpGetter extends TaintPreservingCallable {
123129 pkg = "org.apache.http.params" and
124130 ty = "HttpParams" and
125131 mtd .matches ( "get%Parameter" )
132+ or
133+ pkg = "org.apache.hc.core5.http" and
134+ (
135+ ty = "MessageHeaders" and
136+ mtd = [ "getFirstHeader" , "getHeader" , "getHeaders" , "getLastHeader" , "headerIterator" ]
137+ or
138+ ty = "HttpRequest" and
139+ mtd = [ "getAuthority" , "getPath" , "getRequestUri" , "getScheme" , "getUri" ]
140+ or
141+ ty = "HttpEntityContainer" and
142+ mtd = "getEntity"
143+ or
144+ ty = "NameValuePair" and
145+ mtd = [ "getName" , "getValue" ]
146+ or
147+ ty = "HttpEntity" and
148+ mtd = [ "getContent" , "getTrailers" ]
149+ )
150+ or
151+ pkg = "org.apache.hc.core5.message" and
152+ ty = "RequestLine" and
153+ mtd = [ "getMethod" , "getUri" , "toString" ]
154+ or
155+ pkg = "org.apache.hc.core5.function" and
156+ ty = "Supplier" and
157+ mtd = "get"
158+ or
159+ pkg = "org.apache.hc.core5.net" and
160+ ty = "UriAuthority" and
161+ mtd = [ "getHostName" , "toString" ]
126162 )
127163 }
128164
@@ -131,19 +167,26 @@ private class ApacheHttpGetter extends TaintPreservingCallable {
131167
132168private class UtilMethod extends TaintPreservingCallable {
133169 UtilMethod ( ) {
134- exists ( string ty , string mtd |
170+ exists ( string pkg , string ty , string mtd |
135171 this .isStatic ( ) and
136- this .getDeclaringType ( ) .hasQualifiedName ( "org.apache.http.util" , ty ) and
172+ this .getDeclaringType ( ) .hasQualifiedName ( pkg , ty ) and
137173 this .hasName ( mtd )
138174 |
175+ pkg = [ "org.apache.http.util" , "org.apache.hc.core5.io.entity" ] and
139176 ty = "EntityUtils" and
140- mtd = [ "toString" , "toByteArray" , "getContentCharSet" , "getContentMimeType" ]
177+ mtd = [ "toString" , "toByteArray" , "getContentCharSet" , "getContentMimeType" , "parse" ]
141178 or
179+ pkg = [ "org.apache.http.util" , "org.apache.hc.core5.util" ] and
142180 ty = "EncodingUtils" and
143181 mtd = [ "getAsciiBytes" , "getAsciiString" , "getBytes" , "getString" ]
144182 or
183+ pkg = [ "org.apache.http.util" , "org.apache.hc.core5.util" ] and
145184 ty = "Args" and
146185 mtd = [ "containsNoBlanks" , "notBlank" , "notEmpty" , "notNull" ]
186+ or
187+ pkg = "org.apache.hc.core5.io.entity" and
188+ ty = "HttpEntities" and
189+ mtd = [ "create" , "createGziped" , "createUrlEncoded" , "gzip" , "withTrailers" ]
147190 )
148191 }
149192
@@ -161,25 +204,34 @@ private class EntitySetter extends TaintPreservingCallable {
161204 override predicate transfersTaint ( int src , int sink ) { src = 0 and sink = - 1 }
162205}
163206
164- private class EntityConsructor extends TaintPreservingCallable , Constructor {
165- EntityConsructor ( ) {
207+ private class EntityConstructor extends TaintPreservingCallable , Constructor {
208+ EntityConstructor ( ) {
166209 this .getDeclaringType ( )
167- .hasQualifiedName ( "org.apache.http.entity" ,
210+ .hasQualifiedName ( [ "org.apache.http.entity" , "org.apache.hc.core5.io.entity" ] ,
168211 [
169- "BufferedHttpEntity " , "ByteArrayEntity " , "HttpEntityWrapper " , "InputStreamEntity " ,
170- "StringEntity"
212+ "BasicHttpEntity " , "BufferedHttpEntity " , "ByteArrayEntity " , "HttpEntityWrapper " ,
213+ "InputStreamEntity" , " StringEntity"
171214 ] )
172215 }
173216
174217 override predicate returnsTaintFrom ( int arg ) { arg = 0 }
175218}
176219
220+ private class RequestLineConstructor extends TaintPreservingCallable , Constructor {
221+ RequestLineConstructor ( ) {
222+ this .getDeclaringType ( ) .hasQualifiedName ( "org.apache.hc.core5.http.message" , "RequestLine" )
223+ }
224+
225+ override predicate returnsTaintFrom ( int arg ) { arg = [ 0 , 1 ] }
226+ }
227+
177228private class BufferMethod extends TaintPreservingCallable {
178229 BufferMethod ( ) {
179230 exists ( Method m |
180231 this .( Method ) .overrides * ( m ) and
181232 m .getDeclaringType ( )
182- .hasQualifiedName ( "org.apache.http.util" , [ "ByteArrayBuffer" , "CharArrayBuffer" ] ) and
233+ .hasQualifiedName ( [ "org.apache.http.util" , "org.apache.hc.core5.util" ] ,
234+ [ "ByteArrayBuffer" , "CharArrayBuffer" ] ) and
183235 m .hasName ( [
184236 "append" , "buffer" , "subSequence" , "substring" , "substringTrimmed" , "toByteAray" ,
185237 "toCharArray" , "toString"
0 commit comments