Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible Security Issue: Lack of Rate-Limit in reset_password endpoint can lead to DOS #701

Open
Ashrith-Shetty opened this issue Nov 9, 2022 · 1 comment

Comments

@Ashrith-Shetty
Copy link

Thank you for the great application.

While testing the reset_password endpoint, I found due to lack of rate limiting it can be misused to DOS an email bomb a genuine User.

Anyway, we can mitigate this?

Thanks

@s7m4b4
Copy link

s7m4b4 commented Nov 22, 2022

I was thinking about this too. A potential workaround is to override the reset_password action and leverage DRF's throttling library (https://www.django-rest-framework.org/api-guide/throttling/) e.g.

users/views.py

from djoser.views import UserViewSet as DjoserUserViewSet
from rest_framework.decorators import action
from rest_framework.throttling import ScopedRateThrottle


class UserViewSet(DjoserUserViewSet):
    # required as there's no way to set a throttle scope for actions
    def get_throttles(self):
        if self.action in ["reset_password"]:
            self.throttle_scope = "reset_password"
        return super().get_throttles()

    @action(
        ["post"],
        detail=False,
        throttle_classes=[ScopedRateThrottle],
    )
    def reset_password(self, request, *args, **kwargs):
        return super().reset_password(request, *args, **kwargs)

settings.py

REST_FRAMEWORK = {
   ...
    "DEFAULT_THROTTLE_RATES": {"reset_password": "1/hour"},
   ...
}

It would be great if we could just set a throttle limit per endpoint through Djoser's settings though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants