Skip to content

Commit 3c47e58

Browse files
committed
Python: Add test for missing data-flow step in aiohttp.web
1 parent 2dbbf52 commit 3c47e58

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
This file is a test of an extra data-flow step that we want to have for
3+
aiohttp.web.Application
4+
5+
We don't really have an established way to test extra data-flow steps in external
6+
libraries right now, so for now I've just used our normal taint-flow testing ¯\_(ツ)_/¯
7+
8+
see https://docs.aiohttp.org/en/stable/web_advanced.html#application-s-config
9+
"""
10+
11+
from aiohttp import web
12+
13+
# to make code runable
14+
TAINTED_STRING = "TAINTED_STRING"
15+
def ensure_tainted(*args, **kwargs):
16+
pass
17+
18+
ensure_tainted(
19+
TAINTED_STRING # $ tainted
20+
)
21+
22+
23+
async def example(request: web.Request): # $ requestHandler
24+
return web.Response(text=f'example {request.app["foo"]=}') # $ HttpResponse
25+
26+
27+
async def also_works(request: web.Request): # $ requestHandler
28+
return web.Response(text=f'also_works {request.config_dict["foo"]=}') # $ HttpResponse
29+
30+
31+
async def taint_test(request: web.Request): # $ requestHandler
32+
ensure_tainted(
33+
request.app["ts"], # $ MISSING: tainted
34+
request.config_dict["ts"], # $ MISSING: tainted
35+
)
36+
return web.Response(text="ok") # $ HttpResponse
37+
38+
39+
app = web.Application()
40+
app.router.add_get("", example) # $ routeSetup=""
41+
app.router.add_get("/also-works", also_works) # $ routeSetup="/also-works"
42+
app.router.add_get("/taint-test", taint_test) # $ routeSetup="/taint-test"
43+
app["foo"] = 42
44+
app["ts"] = TAINTED_STRING
45+
46+
47+
if __name__ == "__main__":
48+
web.run_app(app)

0 commit comments

Comments
 (0)