We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
500 Error on unsanitized URL query params 
**Describe the bug**
Error response with 500 Internal server Error is returned to the clients when a unsanitized URL query param is sent to the service.

**To Reproduce**
Steps to reproduce the behavior:
- Check: https://safe-config.safe.global/api/v1/safe-apps/?url=%00

**Expected behavior**
URL input is sanitized beforehand.

**Environment**
 - Staging & production
 - All chains


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/safe_apps/views.py`
Content:
```
1 from typing import Any
2 
3 from django.db.models import Q, QuerySet
4 from django.utils.decorators import method_decorator
5 from django.views.decorators.cache import cache_page
6 from drf_yasg import openapi
7 from drf_yasg.utils import swagger_auto_schema
8 from rest_framework.generics import ListAPIView
9 from rest_framework.request import Request
10 from rest_framework.response import Response
11 
12 from .models import SafeApp
13 from .serializers import SafeAppsResponseSerializer
14 
15 
16 class SafeAppsListView(ListAPIView):
17     serializer_class = SafeAppsResponseSerializer
18     pagination_class = None
19 
20     _swagger_chain_id_param = openapi.Parameter(
21         "chainId",
22         openapi.IN_QUERY,
23         description="Used to filter Safe Apps that are available on `chainId`",
24         type=openapi.TYPE_INTEGER,
25     )
26     _swagger_client_url_param = openapi.Parameter(
27         "clientUrl",
28         openapi.IN_QUERY,
29         description="Used to filter Safe Apps that are available on `clientUrl`",
30         type=openapi.TYPE_STRING,
31     )
32     _swagger_url_param = openapi.Parameter(
33         "url",
34         openapi.IN_QUERY,
35         description="Filter Safe Apps available from `url`. `url` needs to be an exact match",
36         type=openapi.TYPE_STRING,
37     )
38 
39     @method_decorator(cache_page(60 * 10, cache="safe-apps"))  # Cache 10 minutes
40     @swagger_auto_schema(
41         manual_parameters=[
42             _swagger_chain_id_param,
43             _swagger_client_url_param,
44             _swagger_url_param,
45         ]
46     )  # type: ignore[misc]
47     def get(self, request: Request, *args: Any, **kwargs: Any) -> Response:
48         """
49         Returns a collection of Safe Apps (across different chains).
50         Each Safe App can optionally include the information about the `Provider`
51         """
52         return super().get(request, *args, **kwargs)
53 
54     def get_queryset(self) -> QuerySet[SafeApp]:
55         queryset = SafeApp.objects.filter(visible=True)
56 
57         chain_id = self.request.query_params.get("chainId")
58         if chain_id is not None and chain_id.isdigit():
59             queryset = queryset.filter(chain_ids__contains=[chain_id])
60 
61         client_url = self.request.query_params.get("clientUrl")
62         if client_url:
63             queryset = queryset.filter(
64                 Q(exclusive_clients__url=client_url) | Q(exclusive_clients__isnull=True)
65             )
66 
67         url = self.request.query_params.get("url")
68         if url:
69             queryset = queryset.filter(url=url)
70 
71         return queryset
72
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/safe_apps/views.py b/src/safe_apps/views.py
--- a/src/safe_apps/views.py
+++ b/src/safe_apps/views.py
@@ -59,13 +59,13 @@
             queryset = queryset.filter(chain_ids__contains=[chain_id])
 
         client_url = self.request.query_params.get("clientUrl")
-        if client_url:
+        if client_url and "\0" not in client_url:
             queryset = queryset.filter(
                 Q(exclusive_clients__url=client_url) | Q(exclusive_clients__isnull=True)
             )
 
         url = self.request.query_params.get("url")
-        if url:
+        if url and "\0" not in url:
             queryset = queryset.filter(url=url)
 
         return queryset

{"golden_diff": "diff --git a/src/safe_apps/views.py b/src/safe_apps/views.py\n--- a/src/safe_apps/views.py\n+++ b/src/safe_apps/views.py\n@@ -59,13 +59,13 @@\n             queryset = queryset.filter(chain_ids__contains=[chain_id])\n \n         client_url = self.request.query_params.get(\"clientUrl\")\n-        if client_url:\n+        if client_url and \"\\0\" not in client_url:\n             queryset = queryset.filter(\n                 Q(exclusive_clients__url=client_url) | Q(exclusive_clients__isnull=True)\n             )\n \n         url = self.request.query_params.get(\"url\")\n-        if url:\n+        if url and \"\\0\" not in url:\n             queryset = queryset.filter(url=url)\n \n         return queryset\n", "issue": "500 Error on unsanitized URL query params \n**Describe the bug**\r\nError response with 500 Internal server Error is returned to the clients when a unsanitized URL query param is sent to the service.\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n- Check: https://safe-config.safe.global/api/v1/safe-apps/?url=%00\r\n\r\n**Expected behavior**\r\nURL input is sanitized beforehand.\r\n\r\n**Environment**\r\n - Staging & production\r\n - All chains\r\n\n", "before_files": [{"content": "from typing import Any\n\nfrom django.db.models import Q, QuerySet\nfrom django.utils.decorators import method_decorator\nfrom django.views.decorators.cache import cache_page\nfrom drf_yasg import openapi\nfrom drf_yasg.utils import swagger_auto_schema\nfrom rest_framework.generics import ListAPIView\nfrom rest_framework.request import Request\nfrom rest_framework.response import Response\n\nfrom .models import SafeApp\nfrom .serializers import SafeAppsResponseSerializer\n\n\nclass SafeAppsListView(ListAPIView):\n    serializer_class = SafeAppsResponseSerializer\n    pagination_class = None\n\n    _swagger_chain_id_param = openapi.Parameter(\n        \"chainId\",\n        openapi.IN_QUERY,\n        description=\"Used to filter Safe Apps that are available on `chainId`\",\n        type=openapi.TYPE_INTEGER,\n    )\n    _swagger_client_url_param = openapi.Parameter(\n        \"clientUrl\",\n        openapi.IN_QUERY,\n        description=\"Used to filter Safe Apps that are available on `clientUrl`\",\n        type=openapi.TYPE_STRING,\n    )\n    _swagger_url_param = openapi.Parameter(\n        \"url\",\n        openapi.IN_QUERY,\n        description=\"Filter Safe Apps available from `url`. `url` needs to be an exact match\",\n        type=openapi.TYPE_STRING,\n    )\n\n    @method_decorator(cache_page(60 * 10, cache=\"safe-apps\"))  # Cache 10 minutes\n    @swagger_auto_schema(\n        manual_parameters=[\n            _swagger_chain_id_param,\n            _swagger_client_url_param,\n            _swagger_url_param,\n        ]\n    )  # type: ignore[misc]\n    def get(self, request: Request, *args: Any, **kwargs: Any) -> Response:\n        \"\"\"\n        Returns a collection of Safe Apps (across different chains).\n        Each Safe App can optionally include the information about the `Provider`\n        \"\"\"\n        return super().get(request, *args, **kwargs)\n\n    def get_queryset(self) -> QuerySet[SafeApp]:\n        queryset = SafeApp.objects.filter(visible=True)\n\n        chain_id = self.request.query_params.get(\"chainId\")\n        if chain_id is not None and chain_id.isdigit():\n            queryset = queryset.filter(chain_ids__contains=[chain_id])\n\n        client_url = self.request.query_params.get(\"clientUrl\")\n        if client_url:\n            queryset = queryset.filter(\n                Q(exclusive_clients__url=client_url) | Q(exclusive_clients__isnull=True)\n            )\n\n        url = self.request.query_params.get(\"url\")\n        if url:\n            queryset = queryset.filter(url=url)\n\n        return queryset\n", "path": "src/safe_apps/views.py"}], "after_files": [{"content": "from typing import Any\n\nfrom django.db.models import Q, QuerySet\nfrom django.utils.decorators import method_decorator\nfrom django.views.decorators.cache import cache_page\nfrom drf_yasg import openapi\nfrom drf_yasg.utils import swagger_auto_schema\nfrom rest_framework.generics import ListAPIView\nfrom rest_framework.request import Request\nfrom rest_framework.response import Response\n\nfrom .models import SafeApp\nfrom .serializers import SafeAppsResponseSerializer\n\n\nclass SafeAppsListView(ListAPIView):\n    serializer_class = SafeAppsResponseSerializer\n    pagination_class = None\n\n    _swagger_chain_id_param = openapi.Parameter(\n        \"chainId\",\n        openapi.IN_QUERY,\n        description=\"Used to filter Safe Apps that are available on `chainId`\",\n        type=openapi.TYPE_INTEGER,\n    )\n    _swagger_client_url_param = openapi.Parameter(\n        \"clientUrl\",\n        openapi.IN_QUERY,\n        description=\"Used to filter Safe Apps that are available on `clientUrl`\",\n        type=openapi.TYPE_STRING,\n    )\n    _swagger_url_param = openapi.Parameter(\n        \"url\",\n        openapi.IN_QUERY,\n        description=\"Filter Safe Apps available from `url`. `url` needs to be an exact match\",\n        type=openapi.TYPE_STRING,\n    )\n\n    @method_decorator(cache_page(60 * 10, cache=\"safe-apps\"))  # Cache 10 minutes\n    @swagger_auto_schema(\n        manual_parameters=[\n            _swagger_chain_id_param,\n            _swagger_client_url_param,\n            _swagger_url_param,\n        ]\n    )  # type: ignore[misc]\n    def get(self, request: Request, *args: Any, **kwargs: Any) -> Response:\n        \"\"\"\n        Returns a collection of Safe Apps (across different chains).\n        Each Safe App can optionally include the information about the `Provider`\n        \"\"\"\n        return super().get(request, *args, **kwargs)\n\n    def get_queryset(self) -> QuerySet[SafeApp]:\n        queryset = SafeApp.objects.filter(visible=True)\n\n        chain_id = self.request.query_params.get(\"chainId\")\n        if chain_id is not None and chain_id.isdigit():\n            queryset = queryset.filter(chain_ids__contains=[chain_id])\n\n        client_url = self.request.query_params.get(\"clientUrl\")\n        if client_url and \"\\0\" not in client_url:\n            queryset = queryset.filter(\n                Q(exclusive_clients__url=client_url) | Q(exclusive_clients__isnull=True)\n            )\n\n        url = self.request.query_params.get(\"url\")\n        if url and \"\\0\" not in url:\n            queryset = queryset.filter(url=url)\n\n        return queryset\n", "path": "src/safe_apps/views.py"}]}