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.

zilencer: Validate access_token in registration transfer verification.

Mateusz Manderafdda39fee8c4
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
index 7426caf6854..b8f26db1acc 100644
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -3043,6 +3043,14 @@ class RegistrationTakeoverFlowTest(ZulipTestCase):
)
self.assert_json_error(result, "Registration not found for this hostname")
+ for access_token in ["../../user_uploads/foo", "sometoken?", "sometoken#", "some%2Ftoken"]:
+ result = self.client_post(
+ "/api/v1/remotes/server/register/verify_challenge",
+ {"hostname": self.hostname, "access_token": access_token},
+ )
+ self.assert_json_error(result, "access_token has invalid format")
+ self.assert_length(responses.calls, 0)
+
responses.get(
"https://example.com/api/v1/zulip-services/verify/sometoken/",
json={"verification_secret": "foo"},
diff --git a/zilencer/views.py b/zilencer/views.py
index 350a194863e..7881567886d 100644
--- a/zilencer/views.py
+++ b/zilencer/views.py
@@ -356,7 +356,7 @@ def verify_registration_transfer_challenge_ack_endpoint(
request: HttpRequest,
*,
hostname: str,
- access_token: str,
+ access_token: Annotated[str, StringConstraints(pattern="^[a-zA-Z0-9_-]+$")],
) -> HttpResponse:
"""
The host should POST to this endpoint to announce it is ready to serve the received