diff --git a/rules/S3330/python/rule.adoc b/rules/S3330/python/rule.adoc index 84cbc9e225..7a14b167dc 100644 --- a/rules/S3330/python/rule.adoc +++ b/rules/S3330/python/rule.adoc @@ -6,33 +6,64 @@ include::../recommended.adoc[] == Sensitive Code Example -Flask: +Using Flask: +[source,python,diff-id=11,diff-type=noncompliant] ---- from flask import Response @app.route('/') def index(): response = Response() - response.set_cookie('key', 'value') # Sensitive + response.set_cookie('key', 'value') # Sensitive return response ---- +Using FastAPI: + +[source,python,diff-id=21,diff-type=noncompliant] +---- +from fastapi import FastAPI, Response + +app = FastAPI() + +@app.get('/') +async def index(response: Response): + response.set_cookie('key', 'value') # Sensitive + return {"message": "Hello world!"} +---- + + == Compliant Solution -Flask: +Using Flask: -[source,python] +[source,python,diff-id=11,diff-type=compliant] ---- from flask import Response @app.route('/') def index(): response = Response() - response.set_cookie('key', 'value', httponly=True) # Compliant + response.set_cookie('key', 'value', httponly=True) return response ---- +Using FastAPI: + +[source,python,diff-id=21,diff-type=compliant] +---- +from fastapi import FastAPI, Response + +app = FastAPI() + +@app.get('/') +async def index(response: Response): + response.set_cookie('key', 'value', httponly=True) + return {"message": "Hello world!"} +---- + + include::../see.adoc[] ifdef::env-github,rspecator-view[]