Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
registration: Prevent injecting arbitrary strings via query param.
Alex Vandiverbedb68b2fee0
diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 95733c6ebc0..3426c29e808 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -2935,6 +2935,24 @@ class UserSignUpTest(ZulipTestCase):form.errors["email"][0],)+ def test_signup_confirm_injection(self) -> None:+ result = self.client_get("/accounts/send_confirm/[email protected]")+ self.assert_in_success_response(+ [+ 'check your email account (<span class="user_email semi-bold">[email protected]</span>)'+ ],+ result,+ )++ result = self.client_get(+ "/accounts/send_confirm/?email={quote(email)}",+ {"email": "[email protected] for example"},+ )+ self.assertEqual(result.status_code, 400)+ self.assert_in_response(+ "The email address you are trying to sign up with is not valid", result+ )+def test_access_signup_page_in_root_domain_without_realm(self) -> None:result = self.client_get("/register", subdomain="", follow=True)self.assert_in_success_response(["Find your Zulip accounts"], result)diff --git a/zerver/views/registration.py b/zerver/views/registration.pyindex cea8e9fffc3..4ac79924566 100644--- a/zerver/views/registration.py+++ b/zerver/views/registration.py@@ -914,6 +914,18 @@ def create_realm(request: HttpRequest, creation_key: Optional[str] = None) -> Ht@has_request_variablesdef signup_send_confirm(request: HttpRequest, email: str = REQ("email")) -> HttpResponse:+ try:+ # Because we interpolate the email directly into the template+ # from the query parameter, do a simple validation that it+ # looks a at least a bit like an email address.+ validators.validate_email(email)+ except ValidationError:+ return TemplateResponse(+ request,+ "zerver/invalid_email.html",+ context={"invalid_email": True},+ status=400,+ )return TemplateResponse(request,"zerver/accounts_send_confirm.html",