11import python
2-
3-
42import semmle.python.security.TaintTracking
53import semmle.python.security.strings.Untrusted
64import semmle.python.web.Http
75import semmle.python.web.bottle.General
86
9- private Object theBottleRequestObject ( ) {
10- result = theBottleModule ( ) .attr ( "request" )
11- }
7+ private Value theBottleRequestObject ( ) { result = theBottleModule ( ) .attr ( "request" ) }
128
139class BottleRequestKind extends TaintKind {
14-
15- BottleRequestKind ( ) {
16- this = "bottle.request"
17- }
10+ BottleRequestKind ( ) { this = "bottle.request" }
1811
1912 override TaintKind getTaintOfAttribute ( string name ) {
2013 result instanceof BottleFormsDict and
@@ -26,34 +19,23 @@ class BottleRequestKind extends TaintKind {
2619 result .( DictKind ) .getValue ( ) instanceof FileUpload and
2720 name = "files"
2821 }
29-
3022}
3123
3224private class RequestSource extends TaintSource {
25+ RequestSource ( ) { this .( ControlFlowNode ) .pointsTo ( theBottleRequestObject ( ) ) }
3326
34- RequestSource ( ) {
35- this .( ControlFlowNode ) .refersTo ( theBottleRequestObject ( ) )
36- }
37-
38- override predicate isSourceOf ( TaintKind kind ) {
39- kind instanceof BottleRequestKind
40- }
41-
27+ override predicate isSourceOf ( TaintKind kind ) { kind instanceof BottleRequestKind }
4228}
4329
44-
4530class BottleFormsDict extends TaintKind {
46-
47- BottleFormsDict ( ) {
48- this = "bottle.FormsDict"
49- }
31+ BottleFormsDict ( ) { this = "bottle.FormsDict" }
5032
5133 override TaintKind getTaintForFlowStep ( ControlFlowNode fromnode , ControlFlowNode tonode ) {
5234 /* Cannot use `getTaintOfAttribute(name)` as it wouldn't bind `name` */
5335 exists ( string name |
54- fromnode = tonode .( AttrNode ) .getObject ( name ) and
36+ fromnode = tonode .( AttrNode ) .getObject ( name ) and
5537 result instanceof UntrustedStringKind
56- |
38+ |
5739 name != "get" and name != "getunicode" and name != "getall"
5840 )
5941 }
@@ -67,10 +49,7 @@ class BottleFormsDict extends TaintKind {
6749}
6850
6951class FileUpload extends TaintKind {
70-
71- FileUpload ( ) {
72- this = "bottle.FileUpload"
73- }
52+ FileUpload ( ) { this = "bottle.FileUpload" }
7453
7554 override TaintKind getTaintOfAttribute ( string name ) {
7655 name = "filename" and result instanceof UntrustedStringKind
@@ -79,37 +58,23 @@ class FileUpload extends TaintKind {
7958 or
8059 name = "file" and result instanceof UntrustedFile
8160 }
82-
8361}
8462
8563class UntrustedFile extends TaintKind {
86-
8764 UntrustedFile ( ) { this = "Untrusted file" }
88-
8965}
9066
9167//
9268// TO DO.. File uploads -- Should check about file uploads for other frameworks as well.
9369// Move UntrustedFile to shared location
9470//
95-
96-
9771/** Parameter to a bottle request handler function */
9872class BottleRequestParameter extends TaintSource {
99-
10073 BottleRequestParameter ( ) {
101- exists ( BottleRoute route |
102- route .getNamedArgument ( ) = this .( ControlFlowNode ) .getNode ( )
103- )
104- }
105-
106- override predicate isSourceOf ( TaintKind kind ) {
107- kind instanceof UntrustedStringKind
74+ exists ( BottleRoute route | route .getNamedArgument ( ) = this .( ControlFlowNode ) .getNode ( ) )
10875 }
10976
110- override string toString ( ) {
111- result = "bottle handler function argument"
112- }
77+ override predicate isSourceOf ( TaintKind kind ) { kind instanceof UntrustedStringKind }
11378
79+ override string toString ( ) { result = "bottle handler function argument" }
11480}
115-
0 commit comments