|
| 1 | +import python |
| 2 | + |
| 3 | +import semmle.python.security.TaintTracking |
| 4 | +import semmle.python.security.strings.Untrusted |
| 5 | +import semmle.python.web.Http |
| 6 | +import semmle.python.web.bottle.General |
| 7 | + |
| 8 | + |
| 9 | +/** A django.http.response.Response object |
| 10 | + * This isn't really a "taint", but we use the value tracking machinery to |
| 11 | + * track the flow of response objects. |
| 12 | + */ |
| 13 | +class BottleResponse extends TaintKind { |
| 14 | + |
| 15 | + BottleResponse() { |
| 16 | + this = "bottle.response" |
| 17 | + } |
| 18 | + |
| 19 | +} |
| 20 | + |
| 21 | +private Object theBottleResponseObject() { |
| 22 | + result = theBottleModule().getAttribute("request") |
| 23 | +} |
| 24 | + |
| 25 | +class BottleResponseBodyAssignment extends TaintSink { |
| 26 | + |
| 27 | + BottleResponseBodyAssignment() { |
| 28 | + exists(DefinitionNode lhs | |
| 29 | + lhs.getValue() = this and |
| 30 | + lhs.(AttrNode).getObject("body").refersTo(theBottleResponseObject()) |
| 31 | + ) |
| 32 | + } |
| 33 | + |
| 34 | + override predicate sinks(TaintKind kind) { |
| 35 | + kind instanceof StringKind |
| 36 | + } |
| 37 | + |
| 38 | +} |
| 39 | + |
| 40 | +class BottleHandlerFunctionResult extends TaintSink { |
| 41 | + |
| 42 | + BottleHandlerFunctionResult() { |
| 43 | + exists(BottleRoute route, Return ret | |
| 44 | + ret.getScope() = route.getFunction() and |
| 45 | + ret.getValue().getAFlowNode() = this |
| 46 | + ) |
| 47 | + } |
| 48 | + |
| 49 | + override predicate sinks(TaintKind kind) { |
| 50 | + kind instanceof UntrustedStringKind |
| 51 | + } |
| 52 | + |
| 53 | + override string toString() { |
| 54 | + result = "bottle handler function result" |
| 55 | + } |
| 56 | + |
| 57 | +} |
| 58 | + |
0 commit comments