diff options
| author | Magnus Hagander | 2023-06-07 19:54:42 +0000 |
|---|---|---|
| committer | Magnus Hagander | 2023-06-07 19:54:42 +0000 |
| commit | cb6076778fa6149e7ac2fcdb86d8abacc520edc8 (patch) | |
| tree | a57d2bc2c2f2030d72ad996c2377ba866e146d4e /tools | |
| parent | 1b7c1c922b6532573a503484a6b9c66a21444941 (diff) | |
Give nicer error message when URL data is corrupt
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/communityauth/sample/django/auth.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/tools/communityauth/sample/django/auth.py b/tools/communityauth/sample/django/auth.py index edb87b19..8a595950 100644 --- a/tools/communityauth/sample/django/auth.py +++ b/tools/communityauth/sample/django/auth.py @@ -109,10 +109,15 @@ def auth_receive(request): return HttpResponse("Missing data in url!", status=400) # Set up an AES object and decrypt the data we received - decryptor = AES.new(base64.b64decode(settings.PGAUTH_KEY), - AES.MODE_CBC, - base64.b64decode(str(request.GET['i']), "-_")) - s = decryptor.decrypt(base64.b64decode(str(request.GET['d']), "-_")).rstrip(b' ').decode('utf8') + try: + decryptor = AES.new(base64.b64decode(settings.PGAUTH_KEY), + AES.MODE_CBC, + base64.b64decode(str(request.GET['i']), "-_")) + s = decryptor.decrypt(base64.b64decode(str(request.GET['d']), "-_")).rstrip(b' ').decode('utf8') + except UnicodeDecodeError: + return HttpResponse("Badly encoded data found", 400) + except Exception: + return HttpResponse("Could not decrypt data", status=400) # Now un-urlencode it try: |
