Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 91a1cc9

Browse files
committed
Python: Add cherrypy handler function return values as taint sinks.
1 parent 6c82be8 commit 91a1cc9

5 files changed

Lines changed: 44 additions & 0 deletions

File tree

python/ql/src/semmle/python/web/HttpResponse.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ import semmle.python.web.twisted.Response
66
import semmle.python.web.bottle.Response
77
import semmle.python.web.turbogears.Response
88
import semmle.python.web.falcon.Response
9+
import semmle.python.web.cherrypy.Response

python/ql/src/semmle/python/web/cherrypy/General.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class CherryPyExposedFunction extends Function {
1313

1414
CherryPyExposedFunction() {
1515
this.getADecorator().refersTo(CherryPy::expose())
16+
or
17+
this.getADecorator().(Call).getFunc().refersTo(CherryPy::expose())
1618
}
1719

1820
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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.cherrypy.General
7+
8+
9+
10+
class CherryPyExposedFunctionResult extends TaintSink {
11+
12+
CherryPyExposedFunctionResult() {
13+
exists(Return ret |
14+
ret.getScope() instanceof CherryPyExposedFunction and
15+
ret.getValue().getAFlowNode() = this
16+
)
17+
}
18+
19+
override predicate sinks(TaintKind kind) {
20+
kind instanceof StringKind
21+
}
22+
23+
override string toString() {
24+
result = "cherrypy handler function result"
25+
}
26+
27+
}
28+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| red.py:8 | Str | externally controlled string |
2+
| test.py:11 | BinaryExpr | externally controlled string |
3+
| test.py:17 | BinaryExpr | externally controlled string |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
import python
3+
4+
import semmle.python.web.HttpRequest
5+
import semmle.python.web.HttpResponse
6+
import semmle.python.security.strings.Untrusted
7+
8+
from TaintSink sink, TaintKind kind
9+
where sink.sinks(kind)
10+
select sink.getLocation().toString(), sink.(ControlFlowNode).getNode().toString(), kind

0 commit comments

Comments
 (0)