misc: remove samesite retro-compatibility code (#60798)

This commit is contained in:
Benjamin Dauvergne 2022-01-18 23:58:12 +01:00
parent 62d5a3e62d
commit 5ff250ccc3
3 changed files with 2 additions and 42 deletions

View File

@ -1,36 +0,0 @@
# authentic2 - versatile identity manager
# Copyright (C) 2010-2019 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django
if django.VERSION < (2, 1):
# Copied from Django >=2.1 / django.http.cookies
from http import cookies
cookies.Morsel._reserved.setdefault('samesite', 'SameSite')
def set_cookie(response, cookie_name, *args, **kwargs):
samesite = kwargs.pop('samesite', None)
response.set_cookie(cookie_name, *args, **kwargs)
if samesite is not None:
response.cookies[cookie_name]['samesite'] = samesite
else:
def set_cookie(response, cookie_name, *args, **kwargs):
response.set_cookie(cookie_name, *args, **kwargs)

View File

@ -37,7 +37,6 @@ from authentic2 import app_settings as a2_app_settings
from authentic2 import constants, hooks
from authentic2 import models as a2_models
from authentic2.a2_rbac.utils import get_default_ou
from authentic2.compat.cookies import set_cookie
from authentic2.crypto import check_hmac_url, hash_chain, hmac_url
from authentic2.forms.passwords import SetPasswordForm
from authentic2.utils import misc as utils_misc
@ -236,8 +235,7 @@ class LoginOrLinkView(View):
# store nonce_seed in a browser cookie to prevent CSRF and check nonce
# in id_token on return by generating the hash chain again
set_cookie(
response,
response.set_cookie(
'fc-state',
value=nonce_seed,
path=reverse('fc-login-or-link'),

View File

@ -30,7 +30,6 @@ from django.utils.translation import get_language
from django.utils.translation import ugettext as _
from django.views.generic.base import View
from authentic2.compat.cookies import set_cookie
from authentic2.decorators import setting_enabled
from authentic2.utils.misc import authenticate, good_next_url, login, redirect
@ -96,8 +95,7 @@ def oidc_login(request, pk, next_url=None, *args, **kwargs):
# it to user SameSite=Lax. See
# https://developer.mozilla.org/fr/docs/Web/HTTP/Headers/Set-Cookie/SameSite
# for more explanations.
set_cookie(
response,
response.set_cookie(
'oidc-state',
value=state_id,
path=reverse('oidc-login-callback'),