-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify rule S6287: Add FastAPI support (APPSEC-1252) (#3390)
- Loading branch information
1 parent
8d5e029
commit 241c6bb
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,7 @@ | |
* pyDes | ||
* PyJWT | ||
* python-jwt | ||
* FastAPI | ||
* python-jose | ||
* ssl | ||
// Docker | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
== How to fix it in FastAPI | ||
|
||
=== Code examples | ||
|
||
include::../../common/fix/code-rationale.adoc[] | ||
|
||
==== Noncompliant code example | ||
|
||
[source,python,diff-id=11,diff-type=noncompliant] | ||
---- | ||
from fastapi import APIRouter | ||
from fastapi.responses import Response, RedirectResponse | ||
from fastapi.requests import Request | ||
router = APIRouter() | ||
@router.get('/check-cookie') | ||
async def check_cookie(request: Request, response: Response, cookie: str | None = None): | ||
if "session" not in request.cookies.keys(): | ||
response.set_cookie("session", cookie) # Noncompliant | ||
---- | ||
|
||
==== Compliant solution | ||
|
||
[source,python,diff-id=11,diff-type=compliant] | ||
---- | ||
from fastapi import APIRouter | ||
from fastapi.responses import Response, RedirectResponse | ||
from fastapi.requests import Request | ||
router = APIRouter() | ||
@router.get('/check-cookie') | ||
async def check_cookie(request: Request): | ||
if "session" not in request.cookies.keys(): | ||
return RedirectResponse("/getcookie") | ||
---- | ||
|
||
include::../../common/fix/how-does-this-work.adoc[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters