Skip to content

Commit 86d1e5b

Browse files
Add additional type tracking for request attributes
1 parent f85ee38 commit 86d1e5b

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

python/ql/lib/semmle/python/frameworks/Pyramid.qll

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ private import semmle.python.dataflow.new.FlowSummary
1313
private import semmle.python.frameworks.internal.PoorMansFunctionResolution
1414
private import semmle.python.frameworks.internal.InstanceTaintStepsHelper
1515
private import semmle.python.frameworks.data.ModelsAsData
16+
private import semmle.python.frameworks.Stdlib
1617

1718
/**
1819
* Provides models for the `pyramid` PyPI package.
@@ -122,10 +123,22 @@ module Pyramid {
122123
}
123124

124125
override string getMethodName() {
125-
result in ["as_bytes", "copy", "copy_body", "copy_get", "path_info_peek", "path_info_pop"]
126+
result in ["as_bytes", "copy", "copy_get", "path_info_peek", "path_info_pop"]
126127
}
127128

128129
override string getAsyncMethodName() { none() }
129130
}
131+
132+
private class RequestCopyCall extends InstanceSource, DataFlow::MethodCallNode {
133+
RequestCopyCall() { this.calls(instance(), ["copy", "copy_get"]) }
134+
}
135+
136+
private class RequestBodyFileLike extends Stdlib::FileLikeObject::InstanceSource instanceof DataFlow::AttrRead
137+
{
138+
RequestBodyFileLike() {
139+
this.getObject() = instance() and
140+
this.getAttributeName() = ["body_file", "body_file_raw", "body_file_seekable"]
141+
}
142+
}
130143
}
131144
}

python/ql/test/library-tests/frameworks/pyramid/pyramid_test.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ def test1(request):
3030
request.as_bytes, # $ tainted
3131

3232
request.body, # $ tainted
33-
request.body_file, # $ tainted
34-
request.body_file_raw, # $ tainted
35-
request.body_file_seekable,# $ tainted
36-
request.body_file.read(), # $ MISSING:tainted
33+
request.body_file.read(), # $ tainted
34+
request.body_file_raw.read(), # $ tainted
35+
request.body_file_seekable.read(),# $ tainted
3736

3837
request.json, # $ tainted
3938
request.json_body, # $ tainted
@@ -61,9 +60,9 @@ def test1(request):
6160
request.GET.values(), # $ tainted
6261

6362
request.copy(), # $ tainted
64-
request.copy_body(), # $ tainted
6563
request.copy_get(), # $ tainted
66-
request.copy().GET['a'] # $ MISSING:tainted
64+
request.copy().GET['a'], # $ tainted
65+
request.copy_get().body # $ tainted
6766
)
6867

6968
def test2(request):

0 commit comments

Comments
 (0)