add util.add_samesite_fields(response, value)

This function adds f"SameSite={value}" to each cookie's header
stored in response.

This is needed because starlette does not currently support
the `samesite` argument in Response.set_cookie. It is merged,
however, and waiting for next release.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-06-12 03:23:58 -07:00
parent ec632a7091
commit 91dc3efc75
6 changed files with 23 additions and 5 deletions

View file

@ -14,6 +14,7 @@ from starlette.requests import Request
import aurweb.config
import aurweb.db
from aurweb import util
from aurweb.l10n import get_translator_for_request
from aurweb.schema import Bans, Sessions, Users
@ -140,7 +141,7 @@ async def authenticate(request: Request, redirect: str = None, conn=Depends(aurw
response.set_cookie(key="SSO_ID_TOKEN", value=token["id_token"],
path="/sso/", httponly=True,
secure=secure_cookies)
return response
return util.add_samesite_fields(response, "strict")
else:
# Weve got a severe integrity violation.
raise Exception("Multiple accounts found for SSO account " + sub)