Skip to content

Commit

Permalink
Adds rate limit to /forgot. (getredash#5425)
Browse files Browse the repository at this point in the history
Security vulnerability was disclosed by Sohail Ahmed <https://www.linkedin.com/in/sohail-ahmed-755776184/>
  • Loading branch information
Jesse authored Apr 26, 2021
1 parent f21f7e2 commit 9c8c1bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions redash/handlers/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def verify(token, org_slug=None):


@routes.route(org_scoped_rule("/forgot"), methods=["GET", "POST"])
@limiter.limit(settings.THROTTLE_PASS_RESET_PATTERN)
def forgot_password(org_slug=None):
if not current_org.get_setting("auth_password_login_enabled"):
abort(404)
Expand Down
1 change: 1 addition & 0 deletions redash/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def email_server_is_configured():
RATELIMIT_ENABLED = parse_boolean(os.environ.get("REDASH_RATELIMIT_ENABLED", "true"))
THROTTLE_LOGIN_PATTERN = os.environ.get("REDASH_THROTTLE_LOGIN_PATTERN", "50/hour")
LIMITER_STORAGE = os.environ.get("REDASH_LIMITER_STORAGE", REDIS_URL)
THROTTLE_PASS_RESET_PATTERN = os.environ.get("REDASH_THROTTLE_PASS_RESET_PATTERN", "10/hour")

# CORS settings for the Query Result API (and possibly future external APIs).
# In most cases all you need to do is set REDASH_CORS_ACCESS_CONTROL_ALLOW_ORIGIN
Expand Down
10 changes: 10 additions & 0 deletions tests/handlers/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ def test_throttle_login(self):
response = self.get_request("/login", org=self.factory.org)
self.assertEqual(response.status_code, 429)

def test_throttle_password_reset(self):
limiter.enabled = True
# Extract the limit from settings (ex: '10/hour')
limit = settings.THROTTLE_PASS_RESET_PATTERN.split("/")[0]
for _ in range(0, int(limit)):
self.get_request("/forgot", org=self.factory.org)

response = self.get_request("/forgot", org=self.factory.org)
self.assertEqual(response.status_code, 429)


class TestSession(BaseTestCase):
# really simple test just to trigger this route
Expand Down

0 comments on commit 9c8c1bf

Please sign in to comment.