Give better error message when invalid data is passed to cauth in d param
authorMagnus Hagander <magnus@hagander.net>
Fri, 15 Aug 2025 12:26:43 +0000 (14:26 +0200)
committerMagnus Hagander <magnus@hagander.net>
Wed, 27 Aug 2025 14:11:54 +0000 (16:11 +0200)
Int he sample cauth provider for django, the incoming data in the 'd'
parameter is supposed to be the three parts required to do a SIV
decryption of it. But if somebody is sitting on an old link or ends up
going through history or something like that it can end up with just two
parameters since that's what the old version of the plugin uses. Instead
of crashing on that, give an error message so the user can just retry.

tools/communityauth/sample/django/auth.py

index c3756902e2a229c7afc4e24d310d5aae64f74472..06cc609c132af3841b6581ce40e12a1be41da4a8 100644 (file)
@@ -211,7 +211,10 @@ We apologize for the inconvenience.
     # Finally, check of we have a data package that tells us where to
     # redirect the user.
     if 'd' in data:
-        (nonces, datas, tags) = data['d'][0].split('$')
+        splitdata = data['d'][0].split('$')
+        if len(splitdata) != 3:
+            return HttpResponse("Invalid login pass-through data received, likely because of an old link. Please try again.")
+        (nonces, datas, tags) = splitdata
         decryptor = AES.new(
             SHA256.new(settings.SECRET_KEY.encode('ascii')).digest()[:32],
             AES.MODE_SIV,