Skip to content

Commit

Permalink
handle masked token
Browse files Browse the repository at this point in the history
  • Loading branch information
lijiahua-ay committed Feb 28, 2023
1 parent 7683fcd commit 5954e10
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tastypie/compat.py
Expand Up @@ -47,9 +47,14 @@ def is_ajax(request):

# django 4.0
try:
from django.middleware.csrf import _does_token_match, InvalidTokenFormat
from django.middleware.csrf import _does_token_match, _unmask_cipher_token, CSRF_TOKEN_LENGTH, InvalidTokenFormat # noqa

def compare_sanitized_tokens(request_csrf_token, csrf_token):
csrf_secret = csrf_token
if len(csrf_token) == CSRF_TOKEN_LENGTH:
csrf_secret = _unmask_cipher_token(csrf_token)
return _does_token_match(request_csrf_token, csrf_secret)

compare_sanitized_tokens = _does_token_match
except ImportError:
pass

Expand Down

0 comments on commit 5954e10

Please sign in to comment.