diff --git a/backend/api/validators.py b/backend/api/validators.py index 1a5650f..183790a 100644 --- a/backend/api/validators.py +++ b/backend/api/validators.py @@ -1,5 +1,9 @@ import re import base64 +import logging + +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) def validate_username(username): if username is None: @@ -20,12 +24,17 @@ def validate_lang(lang): def validate_image(image): if image is None: return True + + if not image.startswith('data:image/'): + return False + try: - decoded_image = base64.b64decode(image) - if len(decoded_image) > 1 * 1024 * 1024: + decoded_image = base64.b64decode(image.split(',')[1]) + + if len(decoded_image) * 3 / 4 > 1_048_576: return False return True - except: + except Exception as _: return False def validate_phone_number(phone): diff --git a/backend/api/views/users.py b/backend/api/views/users.py index e4bb14d..b0fe108 100644 --- a/backend/api/views/users.py +++ b/backend/api/views/users.py @@ -277,6 +277,8 @@ def put(self, request, *args, **kwargs): if target_user_id == "user_ai": return Response({"error": "There's no escaping prune, nice try."}, status=status.HTTP_400_BAD_REQUEST) + if target_user_id == me.userID: + return Response({"error": "You cannot create a relationship with yourself"}, status=status.HTTP_400_BAD_REQUEST) try: target_user = User.objects.get(userID=target_user_id)