Skip to content

Commit

Permalink
fixup! Add @sensitive_post_parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Nov 26, 2024
1 parent 171cdff commit f6e27bc
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
2 changes: 2 additions & 0 deletions arches/app/views/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.files.base import ContentFile
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.debug import sensitive_variables
from django.utils import translation
from django.utils.decorators import method_decorator
from django_ratelimit.decorators import ratelimit
Expand Down Expand Up @@ -1128,6 +1129,7 @@ def get(self, request, plugin_id=None):


class SearchExport(View):
@sensitive_variables("user_cred")
@method_decorator(
ratelimit(
key="header:http-authorization", rate=settings.RATE_LIMIT, block=False
Expand Down
8 changes: 5 additions & 3 deletions arches/app/views/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ class Login(LoginView, APIBase):

http_method_names = ["post"]

@sensitive_variables()
@sensitive_post_parameters()
@method_decorator(
ratelimit(key="post:username", rate=settings.RATE_LIMIT, block=False)
(
sensitive_variables(),
sensitive_post_parameters(),
ratelimit(key="post:username", rate=settings.RATE_LIMIT, block=False),
)
)
def post(self, request):
if getattr(request, "limited", False):
Expand Down
73 changes: 45 additions & 28 deletions arches/app/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,24 @@ def get(self, request):
},
)

@sensitive_variables()
@sensitive_post_parameters()
@method_decorator(
ratelimit(
key="post:username",
rate=(
(
"{}/{}".format(
int(settings.RATE_LIMIT.split("/")[0]) * 2,
settings.RATE_LIMIT.split("/")[1],
(
sensitive_variables(),
sensitive_post_parameters(),
ratelimit(
key="post:username",
rate=(
(
"{}/{}".format(
int(settings.RATE_LIMIT.split("/")[0]) * 2,
settings.RATE_LIMIT.split("/")[1],
)
)
)
if isinstance(settings.RATE_LIMIT, str)
else settings.RATE_LIMIT
if isinstance(settings.RATE_LIMIT, str)
else settings.RATE_LIMIT
),
block=False,
),
block=False,
)
)
def post(self, request):
Expand Down Expand Up @@ -371,9 +373,13 @@ def get(self, request):
}
return JSONResponse(messages)

@sensitive_variables()
@sensitive_post_parameters()
@method_decorator(ratelimit(key="user", rate=settings.RATE_LIMIT, block=False))
@method_decorator(
(
sensitive_variables(),
sensitive_post_parameters(),
ratelimit(key="user", rate=settings.RATE_LIMIT, block=False),
)
)
def post(self, request):
messages = {
"invalid_password": None,
Expand Down Expand Up @@ -429,9 +435,13 @@ class PasswordResetConfirmView(auth_views.PasswordResetConfirmView):

@method_decorator(csrf_exempt, name="dispatch")
class UserProfileView(View):
@sensitive_variables()
@sensitive_post_parameters()
@method_decorator(ratelimit(key="post:username", rate=settings.RATE_LIMIT))
@method_decorator(
(
sensitive_variables(),
sensitive_post_parameters(),
ratelimit(key="post:username", rate=settings.RATE_LIMIT),
)
)
def post(self, request):
username = request.POST.get("username", None)
password = request.POST.get("password", None)
Expand All @@ -452,9 +462,13 @@ def post(self, request):

@method_decorator(csrf_exempt, name="dispatch")
class GetClientIdView(View):
@sensitive_variables()
@sensitive_post_parameters()
@method_decorator(ratelimit(key="post:username", rate=settings.RATE_LIMIT))
@method_decorator(
(
sensitive_variables(),
sensitive_post_parameters(),
ratelimit(key="post:username", rate=settings.RATE_LIMIT),
)
)
def post(self, request):
if settings.OAUTH_CLIENT_ID == "":
message = _("Make sure to set your OAUTH_CLIENT_ID in settings.py")
Expand All @@ -473,9 +487,13 @@ def post(self, request):

@method_decorator(csrf_exempt, name="dispatch")
class ServerSettingView(View):
@sensitive_variables()
@sensitive_post_parameters()
@method_decorator(ratelimit(key="post:username", rate=settings.RATE_LIMIT))
@method_decorator(
(
sensitive_variables(),
sensitive_post_parameters(),
ratelimit(key="post:username", rate=settings.RATE_LIMIT),
)
)
def post(self, request):
if settings.OAUTH_CLIENT_ID == "":
message = _("Make sure to set your OAUTH_CLIENT_ID in settings.py")
Expand Down Expand Up @@ -583,8 +601,7 @@ def post(self, request):

@method_decorator(never_cache, name="dispatch")
class TwoFactorAuthenticationLoginView(View):
@sensitive_variables()
@sensitive_post_parameters()
@method_decorator((sensitive_variables(), sensitive_post_parameters()))
def post(self, request):
username = request.POST.get("username", None)
password = request.POST.get("password", None)
Expand Down Expand Up @@ -730,7 +747,7 @@ def post(self, request):

@method_decorator(csrf_exempt, name="dispatch")
class Token(View):
@sensitive_variables()
@method_decorator(sensitive_variables())
def get(self, request):
if settings.DEBUG:
data = {
Expand Down

0 comments on commit f6e27bc

Please sign in to comment.