pull/8268/head
ibuler 2022-05-17 17:02:16 +08:00 committed by Jiangjie.Bai
parent 44ffd09924
commit e5f4b8000e
2 changed files with 12 additions and 19 deletions

View File

@ -45,21 +45,7 @@ class MFAMiddleware:
class SessionCookieMiddleware(MiddlewareMixin):
@staticmethod
def process_response(request, response: HttpResponse):
key = settings.SESSION_COOKIE_NAME_PREFIX_KEY
value = settings.SESSION_COOKIE_NAME_PREFIX
if request.COOKIES.get(key) == value:
return response
response.set_cookie(key, value)
return response
class EncryptedMiddleware:
def __init__(self, get_response):
self.get_response = get_response
@staticmethod
def check_key_pair(request, response):
def set_cookie_public_key(request, response):
pub_key_name = settings.SESSION_RSA_PUBLIC_KEY_NAME
public_key = request.session.get(pub_key_name)
cookie_key = request.COOKIES.get(pub_key_name)
@ -73,7 +59,15 @@ class EncryptedMiddleware:
request.session[pri_key_name] = private_key
response.set_cookie(pub_key_name, public_key_decode)
def __call__(self, request):
response = self.get_response(request)
self.check_key_pair(request, response)
@staticmethod
def set_session_cooke_prefix(request, response):
key = settings.SESSION_COOKIE_NAME_PREFIX_KEY
value = settings.SESSION_COOKIE_NAME_PREFIX
if request.COOKIES.get(key) == value:
return response
response.set_cookie(key, value)
def process_response(self, request, response: HttpResponse):
self.set_session_cooke_prefix(request, response)
self.set_session_cooke_prefix(request, response)
return response

View File

@ -95,7 +95,6 @@ MIDDLEWARE = [
'authentication.backends.cas.middleware.CASMiddleware',
'authentication.middleware.MFAMiddleware',
'authentication.middleware.SessionCookieMiddleware',
'authentication.middleware.EncryptedMiddleware',
'simple_history.middleware.HistoryRequestMiddleware',
]