@@ -4,15 +4,13 @@ import semmle.python.security.strings.External
44import HttpConstants
55
66/** Generic taint source from a http request */
7- abstract class HttpRequestTaintSource extends TaintSource {
7+ abstract class HttpRequestTaintSource extends TaintSource { }
88
9- }
10-
11- /** Taint kind representing the WSGI environment.
9+ /**
10+ * Taint kind representing the WSGI environment.
1211 * As specified in PEP 3333. https://www.python.org/dev/peps/pep-3333/#environ-variables
1312 */
1413class WsgiEnvironment extends TaintKind {
15-
1614 WsgiEnvironment ( ) { this = "wsgi.environment" }
1715
1816 override TaintKind getTaintForFlowStep ( ControlFlowNode fromnode , ControlFlowNode tonode ) {
@@ -26,122 +24,95 @@ class WsgiEnvironment extends TaintKind {
2624 tonode .( CallNode ) .getFunction ( ) .( AttrNode ) .getObject ( "get" ) = fromnode and
2725 tonode .( CallNode ) .getArg ( 0 ) .pointsTo ( key )
2826 or
29- tonode .( SubscriptNode ) .getObject ( ) = fromnode and tonode .isLoad ( ) and
27+ tonode .( SubscriptNode ) .getObject ( ) = fromnode and
28+ tonode .isLoad ( ) and
3029 tonode .( SubscriptNode ) .getIndex ( ) .pointsTo ( key )
31- |
32- key = Value:: forString ( text ) and result instanceof ExternalStringKind and
30+ |
31+ key = Value:: forString ( text ) and
32+ result instanceof ExternalStringKind and
3333 (
3434 text = "QUERY_STRING" or
3535 text = "PATH_INFO" or
3636 text .prefix ( 5 ) = "HTTP_"
3737 )
3838 )
3939 }
40-
4140}
4241
43- /** A standard morsel object from a HTTP request, a value in a cookie,
44- * typically an instance of `http.cookies.Morsel` */
42+ /**
43+ * A standard morsel object from a HTTP request, a value in a cookie,
44+ * typically an instance of `http.cookies.Morsel`
45+ */
4546class UntrustedMorsel extends TaintKind {
46-
47- UntrustedMorsel ( ) {
48- this = "http.Morsel"
49- }
50-
47+ UntrustedMorsel ( ) { this = "http.Morsel" }
5148
5249 override TaintKind getTaintOfAttribute ( string name ) {
5350 result instanceof ExternalStringKind and
54- (
55- name = "value"
56- )
51+ name = "value"
5752 }
58-
5953}
6054
6155/** A standard cookie object from a HTTP request, typically an instance of `http.cookies.SimpleCookie` */
6256class UntrustedCookie extends TaintKind {
63-
64- UntrustedCookie ( ) {
65- this = "http.Cookie"
66- }
57+ UntrustedCookie ( ) { this = "http.Cookie" }
6758
6859 override TaintKind getTaintForFlowStep ( ControlFlowNode fromnode , ControlFlowNode tonode ) {
6960 tonode .( SubscriptNode ) .getObject ( ) = fromnode and
7061 result instanceof UntrustedMorsel
7162 }
72-
7363}
7464
7565abstract class CookieOperation extends @py_flow_node {
76-
7766 abstract string toString ( ) ;
7867
7968 abstract ControlFlowNode getKey ( ) ;
8069
8170 abstract ControlFlowNode getValue ( ) ;
82-
8371}
8472
85- abstract class CookieGet extends CookieOperation { }
73+ abstract class CookieGet extends CookieOperation { }
8674
87- abstract class CookieSet extends CookieOperation { }
75+ abstract class CookieSet extends CookieOperation { }
8876
8977/** Generic taint sink in a http response */
9078abstract class HttpResponseTaintSink extends TaintSink {
91-
92- override predicate sinks ( TaintKind kind ) {
93- kind instanceof ExternalStringKind
94- }
95-
79+ override predicate sinks ( TaintKind kind ) { kind instanceof ExternalStringKind }
9680}
9781
9882abstract class HttpRedirectTaintSink extends TaintSink {
99-
100- override predicate sinks ( TaintKind kind ) {
101- kind instanceof ExternalStringKind
102- }
103-
83+ override predicate sinks ( TaintKind kind ) { kind instanceof ExternalStringKind }
10484}
10585
10686module Client {
107-
10887 // TODO: user-input in other than URL:
10988 // - `data`, `json` for `requests.post`
11089 // - `body` for `HTTPConnection.request`
11190 // - headers?
112-
11391 // TODO: Add more library support
11492 // - urllib3 https://github.com/urllib3/urllib3
11593 // - httpx https://github.com/encode/httpx
116-
11794 /**
118- * An outgoing http request
119- *
120- * For example:
121- * conn = HTTPConnection('example.com')
122- conn.request('GET', '/path')
123- */
95+ * An outgoing http request
96+ *
97+ * For example:
98+ * conn = HTTPConnection('example.com')
99+ * conn.request('GET', '/path')
100+ */
124101 abstract class HttpRequest extends ControlFlowNode {
125-
126- /* * Get any ControlFlowNode that is used to construct the final URL.
127- *
128- * In the HTTPConnection example, there is a result for both `'example.com'` and for `'/path'`.
129- */
102+ /**
103+ * Get any ControlFlowNode that is used to construct the final URL.
104+ *
105+ * In the HTTPConnection example, there is a result for both `'example.com'` and for `'/path'`.
106+ */
130107 abstract ControlFlowNode getAUrlPart ( ) ;
131108
132109 abstract string getMethodUpper ( ) ;
133110 }
134111
135112 /** Taint sink for the URL-part of an outgoing http request */
136113 class HttpRequestUrlTaintSink extends TaintSink {
114+ HttpRequestUrlTaintSink ( ) { this = any ( HttpRequest r ) .getAUrlPart ( ) }
137115
138- HttpRequestUrlTaintSink ( ) {
139- this = any ( HttpRequest r ) .getAUrlPart ( )
140- }
141-
142- override predicate sinks ( TaintKind kind ) {
143- kind instanceof ExternalStringKind
144- }
145-
116+ override predicate sinks ( TaintKind kind ) { kind instanceof ExternalStringKind }
146117 }
147118}
0 commit comments