Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with query string parsing #111

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions wagtail_transfer/auth.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import logging
import hashlib
import hmac
import re

from urllib.parse import unquote

from django.conf import settings
from django.core.exceptions import PermissionDenied

logger = logging.getLogger(__name__)

GROUP_QUERY_WITH_DIGEST = re.compile('(?P<query_before>.*?)&?digest=(?P<digest>[^&]*)(?P<query_after>.*)')


def check_get_digest_wrapper(view_func):
"""
Check the digest of a request matches its GET parameters
This is useful when wrapping vendored API views
"""
def decorated_view(request, *args, **kwargs):
query_string = request.META.get('QUERY_STRING', '')
query_string = unquote(request.META.get('QUERY_STRING', ''))
logger.info(f"Parsed Querystring: {query_string}")
match = GROUP_QUERY_WITH_DIGEST.match(query_string)
if not match:
raise PermissionDenied
Expand Down Expand Up @@ -52,7 +59,7 @@ def check_digest(message, digest):

expected_digest = hmac.new(key, message, hashlib.sha1).hexdigest()
if not hmac.compare_digest(digest, expected_digest):
raise PermissionDenied
raise PermissionDenied


def digest_for_source(source, message):
Expand Down