Skip to content

Commit 4f47461

Browse files
committed
Python: Add requested test
1 parent 0db535b commit 4f47461

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
11
import experimental.meta.InlineTaintTest
2-
import MakeInlineTaintTest<TestTaintTrackingConfig>
2+
3+
predicate isSafe(DataFlow::GuardNode g, ControlFlowNode node, boolean branch) {
4+
g.(CallNode).getFunction().(NameNode).getId() = "is_safe" and
5+
node = g.(CallNode).getArg(_) and
6+
branch = true
7+
}
8+
9+
module CustomSanitizerOverridesConfig implements DataFlow::ConfigSig {
10+
predicate isSource = TestTaintTrackingConfig::isSource/1;
11+
12+
predicate isSink = TestTaintTrackingConfig::isSink/1;
13+
14+
predicate isBarrier(DataFlow::Node node) {
15+
node = DataFlow::BarrierGuard<isSafe/3>::getABarrierNode()
16+
}
17+
}
18+
19+
import MakeInlineTaintTest<CustomSanitizerOverridesConfig>

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ def get(self): # $ requestHandler
142142
self.request.url # $ tainted
143143
)
144144

145-
# not a request handler, and not called, btu since we have type-annotation, should be a
145+
# not a request handler, and not called, but since we have type-annotation, should be a
146146
# remote-flow-source.
147-
async def test_heuristic_taint(request: web.Request):
147+
async def test_source_from_type_annotation(request: web.Request):
148148
# picking out just a few of the tests from `test_taint` above, to show that we have
149149
# the same taint-steps :)
150150
ensure_tainted(
@@ -153,10 +153,25 @@ async def test_heuristic_taint(request: web.Request):
153153
await request.content.read(), # $ tainted
154154
)
155155

156+
# Test that since we can reach the `request` object in the helper function, we don't
157+
# introduce a new remote-flow-source, but instead use the one from the caller. (which is
158+
# checked to not be tainted)
159+
async def test_sanitizer(request): # $ requestHandler
160+
ensure_tainted(request, request.url, await request.content.read()) # $ tainted
161+
162+
if (is_safe(request)):
163+
ensure_not_tainted(request, request.url, await request.content.read())
164+
test_safe_helper_function_no_route_with_type(request)
165+
166+
167+
async def test_safe_helper_function_no_route_with_type(request: web.Request):
168+
ensure_not_tainted(request, request.url, await request.content.read()) # $ SPURIOUS: tainted
169+
156170

157171
app = web.Application()
158172
app.router.add_get(r"/test_taint/{name}/{number:\d+}", test_taint) # $ routeSetup="/test_taint/{name}/{number:\d+}"
159173
app.router.add_view(r"/test_taint_class", TaintTestClass) # $ routeSetup="/test_taint_class"
174+
app.router.add_view(r"/test_sanitizer", test_sanitizer) # $ routeSetup="/test_sanitizer"
160175

161176

162177
if __name__ == "__main__":

0 commit comments

Comments
 (0)