File tree Expand file tree Collapse file tree 5 files changed +55
-1
lines changed
test/library-tests/web/stdlib Expand file tree Collapse file tree 5 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -7,3 +7,4 @@ import semmle.python.web.bottle.Response
7
7
import semmle.python.web.turbogears.Response
8
8
import semmle.python.web.falcon.Response
9
9
import semmle.python.web.cherrypy.Response
10
+ import semmle.python.web.stdlib.Response
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Provides the sinks for HTTP servers defined with standard library (stdlib).
3
+ */
4
+
5
+ import python
6
+ import semmle.python.security.TaintTracking
7
+ import semmle.python.web.Http
8
+
9
+ private predicate is_wfile ( AttrNode wfile ) {
10
+ exists ( ClassValue cls |
11
+ // Python 2
12
+ cls .getABaseType + ( ) = Value:: named ( "BaseHTTPServer.BaseHTTPRequestHandler" )
13
+ or
14
+ // Python 3
15
+ cls .getABaseType + ( ) = Value:: named ( "http.server.BaseHTTPRequestHandler" )
16
+ |
17
+ wfile .getObject ( "wfile" ) .pointsTo ( ) .getClass ( ) = cls
18
+ )
19
+ }
20
+
21
+ /** Sink for `h.wfile.write` where `h` is an instance of BaseHTTPRequestHandler. */
22
+ class StdLibWFileWriteSink extends HttpResponseTaintSink {
23
+ StdLibWFileWriteSink ( ) {
24
+ exists ( CallNode call |
25
+ is_wfile ( call .getFunction ( ) .( AttrNode ) .getObject ( "write" ) ) and
26
+ call .getArg ( 0 ) = this
27
+ )
28
+ }
29
+
30
+ override predicate sinks ( TaintKind kind ) { kind instanceof ExternalStringKind }
31
+ }
32
+
33
+ /** Sink for `h.wfile.writelines` where `h` is an instance of BaseHTTPRequestHandler. */
34
+ class StdLibWFileWritelinesSink extends HttpResponseTaintSink {
35
+ StdLibWFileWritelinesSink ( ) {
36
+ exists ( CallNode call |
37
+ is_wfile ( call .getFunction ( ) .( AttrNode ) .getObject ( "writelines" ) ) and
38
+ call .getArg ( 0 ) = this
39
+ )
40
+ }
41
+
42
+ override predicate sinks ( TaintKind kind ) { kind instanceof ExternalStringSequenceKind }
43
+ }
Original file line number Diff line number Diff line change
1
+ | test.py:72:26:72:58 | Taint sink | externally controlled string |
2
+ | test.py:73:31:73:54 | Taint sink | [externally controlled string] |
Original file line number Diff line number Diff line change
1
+ import python
2
+ import semmle.python.web.HttpResponse
3
+ import semmle.python.security.strings.Untrusted
4
+
5
+ from HttpResponseTaintSink sink , TaintKind kind
6
+ where sink .sinks ( kind )
7
+ select sink , kind
Original file line number Diff line number Diff line change @@ -69,7 +69,8 @@ def do_GET(self):
69
69
self .send_response (200 )
70
70
self .send_header ("Content-type" , "text/plain; charset=utf-8" )
71
71
self .end_headers ()
72
- self .wfile .write (b"Hello BaseHTTPRequestHandler" )
72
+ self .wfile .write (b"Hello BaseHTTPRequestHandler\n " )
73
+ self .wfile .writelines ([b"1\n " , b"2\n " , b"3\n " ])
73
74
print (self .headers )
74
75
75
76
You can’t perform that action at this time.
0 commit comments