Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] add tests for Python FastAPI header injection #3779

Merged
merged 6 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifests/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ tests/:
test_header_injection.py:
TestHeaderInjection:
'*': v2.10.0
fastapi: missing_feature
fastapi: v2.20.0.dev
TestHeaderInjectionExclusionAccessControlAllow: missing_feature
TestHeaderInjectionExclusionContentEncoding: missing_feature
TestHeaderInjectionExclusionPragma: missing_feature
Expand Down
20 changes: 20 additions & 0 deletions utils/build/docker/python/fastapi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ async def set_cookie(request: Request):
)


@app.post("/iast/header_injection/test_insecure", response_class=PlainTextResponse)
async def iast_header_injection_insecure(request: Request):
form_data = await request.form()
header_value = form_data.get("test")
response = PlainTextResponse("OK")
# label iast_header_injection
response.headers["Header-Injection"] = header_value
return response


@app.post("/iast/header_injection/test_secure", response_class=PlainTextResponse)
async def iast_header_injection_secure(request: Request):
form_data = await request.form()
header_value = form_data.get("test")
response = PlainTextResponse("OK")
# label iast_header_injection
response.headers["Vary"] = header_value
return response


@app.get("/sample_rate_route/{i}", response_class=PlainTextResponse)
async def sample_rate(i):
return "OK"
Expand Down
Loading