Skip to content

Commit 2bb933f

Browse files
committed
Python: Modernise tornado library
1 parent 3e38339 commit 2bb933f

File tree

7 files changed

+21
-12
lines changed

7 files changed

+21
-12
lines changed

python/ql/src/semmle/python/web/tornado/Tornado.qll

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@ import python
33
import semmle.python.security.TaintTracking
44
import semmle.python.web.Http
55

6-
private ClassObject theTornadoRequestHandlerClass() {
7-
result = ModuleObject::named("tornado.web").attr("RequestHandler")
6+
private ClassValue theTornadoRequestHandlerClass() {
7+
result = Value::named("tornado.web.RequestHandler")
88
}
99

10-
ClassObject aTornadoRequestHandlerClass() {
11-
result.getASuperType() = theTornadoRequestHandlerClass()
10+
ClassValue aTornadoRequestHandlerClass() {
11+
result.getABaseType+() = theTornadoRequestHandlerClass()
1212
}
1313

14-
/** Holds if `node` is likely to refer to an instance of a tornado
14+
/** Holds if `node` is likely to refer to an instance of a tornado
1515
* `RequestHandler` class.
1616
*/
17-
1817
predicate isTornadoRequestHandlerInstance(ControlFlowNode node) {
19-
node.refersTo(_, aTornadoRequestHandlerClass(), _)
18+
node.pointsTo().getClass() = aTornadoRequestHandlerClass()
2019
or
2120
/* In some cases, the points-to analysis won't capture all instances we care
22-
* about. For these, we use the following syntactic check. First, that
23-
* `node` appears inside a method of a subclass of
21+
* about. For these, we use the following syntactic check. First, that
22+
* `node` appears inside a method of a subclass of
2423
* `tornado.web.RequestHandler`:*/
25-
node.getScope().getEnclosingScope().(Class).getClassObject() = aTornadoRequestHandlerClass() and
24+
node.getScope().getEnclosingScope() = aTornadoRequestHandlerClass().getScope() and
2625
/* Secondly, that `node` refers to the `self` argument: */
2726
node.isLoad() and node.(NameNode).isSelf()
2827
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| class DeepInheritance | test.py:23 |
12
| class Handler1 | test.py:4 |
23
| class Handler2 | test.py:8 |
34
| class Handler3 | test.py:14 |

python/ql/test/library-tests/web/tornado/Classes.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import python
44
import semmle.python.TestUtils
55

66
import semmle.python.web.tornado.Tornado
7-
from ClassObject cls
7+
from ClassValue cls
88
where cls = aTornadoRequestHandlerClass()
9-
select cls.toString(), remove_library_prefix(cls.getPyClass().getLocation())
9+
select cls.toString(), remove_library_prefix(cls.getScope().getLocation())
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
| test.py:6 | Attribute() | externally controlled string |
22
| test.py:12 | name | externally controlled string |
33
| test.py:20 | url | externally controlled string |
4+
| test.py:26 | Attribute() | externally controlled string |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
| test.py:6 | Attribute() | externally controlled string |
22
| test.py:10 | Attribute() | [externally controlled string] |
33
| test.py:17 | Attribute | tornado.request.HttpRequest |
4+
| test.py:26 | Attribute() | externally controlled string |

python/ql/test/library-tests/web/tornado/Taint.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
| test.py:19 | Subscript | externally controlled string |
1010
| test.py:19 | h | {externally controlled string} |
1111
| test.py:20 | url | externally controlled string |
12+
| test.py:26 | Attribute() | externally controlled string |

python/ql/test/library-tests/web/tornado/test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ def get(self):
1818
h = req.headers
1919
url = h["url"]
2020
self.redirect(url)
21+
22+
23+
class DeepInheritance(Handler3):
24+
25+
def get(self):
26+
self.write(self.get_argument("also_xss"))

0 commit comments

Comments
 (0)