Skip to content

Commit 04190ea

Browse files
committed
Python: Add file-like modeling to werkzeug FileStorage
1 parent 5f5c0b1 commit 04190ea

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

python/ql/src/semmle/python/frameworks/Werkzeug.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ private import python
99
private import semmle.python.dataflow.new.DataFlow
1010
private import semmle.python.dataflow.new.TaintTracking
1111
private import semmle.python.ApiGraphs
12+
private import semmle.python.frameworks.Stdlib
1213

1314
/**
1415
* Provides models for the `Werkzeug` PyPI package.
@@ -107,6 +108,21 @@ module Werkzeug {
107108
)
108109
}
109110
}
111+
112+
/** A file-like object instance that originates from a `FileStorage`. */
113+
class FileStorageFileLikeInstances extends Stdlib::FileLikeObject::InstanceSource {
114+
FileStorageFileLikeInstances() {
115+
this.(DataFlow::AttrRead).accesses(instance(), "stream")
116+
or
117+
// All the attributes of the wrapper stream are proxied by the file storage
118+
// so it’s possible to do storage.read() instead of the long form
119+
// storage.stream.read().
120+
//
121+
// due to the `InstanceSourceApiNode` stuff, we can't just make
122+
// `InstanceSource` extend `Stdlib::FileLikeObject::InstanceSource`
123+
this = any(InstanceSourceApiNode api).getAnImmediateUse()
124+
}
125+
}
110126
}
111127
}
112128
}

python/ql/test/library-tests/frameworks/flask/taint_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def test_taint(name = "World!", number="0", foo="foo"): # $requestHandler route
7070
request.files['key'], # $ tainted
7171
request.files['key'].filename, # $ MISSING: tainted
7272
request.files['key'].stream, # $ MISSING: tainted
73+
request.files['key'].read(), # $ MISSING: tainted
74+
request.files['key'].stream.read(), # $ MISSING: tainted
7375
request.files.get('key'), # $ tainted
7476
request.files.get('key').filename, # $ MISSING: tainted
7577
request.files.get('key').stream, # $ MISSING: tainted

0 commit comments

Comments
 (0)