Skip to content

Commit 29e3abc

Browse files
committed
Python: FastAPI: Add HTTP header taint example
1 parent 7619d0f commit 29e3abc

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ async def form_example(username: str = Form(None)): # $ requestHandler routedPar
7373
return "ok" # $ HttpResponse
7474

7575

76+
# --- HTTP headers ---
77+
# see https://fastapi.tiangolo.com/tutorial/header-params/
78+
79+
from fastapi import Header
80+
81+
@app.get("/header-example") # $ routeSetup="/header-example"
82+
async def header_example(user_agent: Optional[str] = Header(None)): # $ requestHandler routedParameter=user_agent
83+
ensure_tainted(user_agent) # $ tainted
84+
return "ok" # $ HttpResponse
85+
86+
7687
# --- file upload ---
7788
# see https://fastapi.tiangolo.com/tutorial/request-files/
7889
# see https://fastapi.tiangolo.com/tutorial/request-files/#uploadfile

0 commit comments

Comments
 (0)