Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

altcha: More error-proofing around settings validation.

Alex Vandiver8af90294d8d8
diff --git a/zerver/forms.py b/zerver/forms.py
index 1fbd6140550..b927c515104 100644
--- a/zerver/forms.py
+++ b/zerver/forms.py
@@ -403,6 +403,8 @@ class CaptchaRealmCreationForm(RealmCreationForm):
def clean_captcha(self) -> str:
payload = self.data.get("captcha", "")
+ if not settings.USING_CAPTCHA or not settings.ALTCHA_HMAC_KEY: # nocoverage
+ raise forms.ValidationError(_("Challenges are not enabled."))
try:
ok, err = verify_solution(payload, settings.ALTCHA_HMAC_KEY, check_expires=True)
diff --git a/zerver/views/antispam.py b/zerver/views/antispam.py
index 897201c77b7..8d38db01760 100644
--- a/zerver/views/antispam.py
+++ b/zerver/views/antispam.py
@@ -25,6 +25,9 @@ class AltchaPayload(BaseModel):
def get_challenge(
request: HttpRequest,
) -> HttpResponseBase:
+ if not settings.USING_CAPTCHA or not settings.ALTCHA_HMAC_KEY: # nocoverage
+ raise JsonableError(_("Challenges are not enabled."))
+
now = timezone_now()
expires = now + timedelta(minutes=1)
try: