Skip to content

Commit

Permalink
Add UUID validation for uid parameter in API views
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehco1996 committed Jan 12, 2024
1 parent 5df53e1 commit 6403561
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions apps/api/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import uuid

import pendulum
from django.conf import settings
from django.contrib.auth.decorators import login_required, permission_required
Expand Down Expand Up @@ -58,7 +60,14 @@ class SubscribeView(View):
def get(self, request):
user = None
if uid := request.GET.get("uid"):
user = User.objects.filter(uid=uid).first()
# check if uid is valid
try:
uuid.UUID(uid)
except ValueError:
return HttpResponseBadRequest("invalid uid")
else:
return HttpResponseBadRequest("uid is required")
user = User.objects.filter(uid=uid).first()
if not user:
return HttpResponseBadRequest("user not found")
node_list = m.ProxyNode.get_user_active_nodes(user)
Expand All @@ -83,7 +92,14 @@ class ClashProxyProviderView(View):
def get(self, request):
user = None
if uid := request.GET.get("uid"):
user = User.objects.filter(uid=uid).first()
# check if uid is valid
try:
uuid.UUID(uid)
except ValueError:
return HttpResponseBadRequest("invalid uid")
else:
return HttpResponseBadRequest("uid is required")
user = User.objects.filter(uid=uid).first()
if not user:
return HttpResponseBadRequest("user not found")
node_list = m.ProxyNode.get_user_active_nodes(user)
Expand Down

0 comments on commit 6403561

Please sign in to comment.