Skip to content

Commit a66c9fa

Browse files
committed
fixed some securty vunerabilities
1 parent 027617c commit a66c9fa

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

bruc/views.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@
3535
from django.contrib.auth.models import User
3636
from rest_framework_simplejwt.tokens import RefreshToken
3737
from rest_framework.permissions import IsAuthenticated, AllowAny, BasePermission, IsAuthenticatedOrReadOnly
38+
from rest_framework.throttling import AnonRateThrottle
3839
from django.contrib.auth.models import User as DjangoUser
3940

4041
from datetime import datetime, time
4142
from django.utils.timezone import make_aware
4243

44+
class SponsorGuestThrottle(AnonRateThrottle):
45+
rate = '30/hour'
46+
4347
class MailerViewSet(viewsets.ModelViewSet):
4448
queryset = Mailer.objects.all()
4549
serializer_class = MailerSerializer
@@ -238,7 +242,7 @@ class SponsorsViewSet(viewsets.ModelViewSet):
238242
serializer_class = SponsorsSerializer
239243
filter_backends = [DynamicSearchFilter, filters.OrderingFilter]
240244
ordering_fields = ['order']
241-
permission_classes = [AllowAny]
245+
permission_classes = [IsAuthenticated]
242246

243247
@action(detail=False, methods=['get'], permission_classes=[AllowAny], url_path='public')
244248
def public(self, request):
@@ -261,6 +265,7 @@ def public(self, request):
261265
detail=False,
262266
methods=['get', 'post', 'delete'],
263267
permission_classes=[AllowAny],
268+
throttle_classes=[SponsorGuestThrottle],
264269
url_path='public/guests'
265270
)
266271
def public_guests(self, request):
@@ -300,7 +305,7 @@ def public_guests(self, request):
300305
if not sponsor:
301306
return Response({"detail": "Sponsor not found"}, status=404)
302307

303-
guest = Guests.objects.filter(id=guest_id, tag__icontains=sponsor.slug).first()
308+
guest = Guests.objects.filter(id=guest_id, tag__istartswith=sponsor.slug).first()
304309
if not guest:
305310
return Response({"detail": "Guest not found"}, status=404)
306311

@@ -460,7 +465,7 @@ def has_permission(self, request, view):
460465
class BrucosiFormResponseViewSet(viewsets.ModelViewSet):
461466
queryset = BrucosiFormResponse.objects.all()
462467
serializer_class = BrucosiFormResponseSerializer
463-
permission_classes = [AllowAny]
468+
permission_classes = [AllowPostAnyOtherwiseAuthenticated]
464469

465470
@action(detail=False, methods=['post'], url_path='brucosi-form-submit')
466471
def brucosi_form_submit(self, request):

brucifer/settings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY")
2929

3030
# SECURITY WARNING: don't run with debug turned on in production!
31-
DEBUG = True
31+
DEBUG = os.getenv("DJANGO_DEBUG", "False") == "True"
3232

33-
ALLOWED_HOSTS = ['*']
33+
_allowed = os.getenv("DJANGO_ALLOWED_HOSTS", "localhost,127.0.0.1")
34+
ALLOWED_HOSTS = [h.strip() for h in _allowed.split(",") if h.strip()]
3435

3536
# Application definition
3637

0 commit comments

Comments
 (0)