Skip to content

Commit

Permalink
don't look for csrf token in form if already found in header (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantownsend authored Dec 13, 2021
1 parent 86731db commit cfd92ec
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions piccolo_api/csrf/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,13 @@ async def dispatch(
if not cookie_token:
return Response("No CSRF cookie found", status_code=403)

if self.allow_header_param:
header_token = request.headers.get(self.header_name, None)
else:
header_token = None
header_token = (
request.headers.get(self.header_name)
if self.allow_header_param
else None
)

if self.allow_form_param:
if self.allow_form_param and not header_token:
form_data = await request.form()
form_token = form_data.get(self.cookie_name, None)
request.scope.update({"form": form_data})
Expand Down

0 comments on commit cfd92ec

Please sign in to comment.