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.

ifttt: Ensure topic and body are strings, and not dicts / arrays.

Alex Vandiver5ccbd0eadec6
diff --git a/zerver/webhooks/ifttt/fixtures/invalid_payload_with_dict_content.json b/zerver/webhooks/ifttt/fixtures/invalid_payload_with_dict_content.json
new file mode 100644
index 00000000000..c9ab47d053a
--- /dev/null
+++ b/zerver/webhooks/ifttt/fixtures/invalid_payload_with_dict_content.json
@@ -0,0 +1,4 @@
+{
+ "topic": "Email sent from [email protected]",
+ "content": {"wrong": "example"}
+}
diff --git a/zerver/webhooks/ifttt/fixtures/invalid_payload_with_dict_topic.json b/zerver/webhooks/ifttt/fixtures/invalid_payload_with_dict_topic.json
new file mode 100644
index 00000000000..d10a3880e69
--- /dev/null
+++ b/zerver/webhooks/ifttt/fixtures/invalid_payload_with_dict_topic.json
@@ -0,0 +1,4 @@
+{
+ "topic": {"wrong": "example"},
+ "content": "Email subject: Subject"
+}
diff --git a/zerver/webhooks/ifttt/tests.py b/zerver/webhooks/ifttt/tests.py
index a28963ad8e3..78f5b73ba5d 100644
--- a/zerver/webhooks/ifttt/tests.py
+++ b/zerver/webhooks/ifttt/tests.py
@@ -28,3 +28,15 @@ class IFTTTHookTests(WebhookTestCase):
payload = self.get_body("invalid_payload_with_missing_content")
result = self.client_post(self.url, payload, content_type="application/json")
self.assert_json_error(result, "Content can't be empty")
+
+ def test_ifttt_when_topic_is_dict(self) -> None:
+ self.url = self.build_webhook_url()
+ payload = self.get_body("invalid_payload_with_dict_topic")
+ result = self.client_post(self.url, payload, content_type="application/json")
+ self.assert_json_error(result, "Topic must be a string")
+
+ def test_ifttt_when_content_is_dict(self) -> None:
+ self.url = self.build_webhook_url()
+ payload = self.get_body("invalid_payload_with_dict_content")
+ result = self.client_post(self.url, payload, content_type="application/json")
+ self.assert_json_error(result, "Content must be a string")
diff --git a/zerver/webhooks/ifttt/view.py b/zerver/webhooks/ifttt/view.py
index 5b7a887f8ac..45203545d04 100644
--- a/zerver/webhooks/ifttt/view.py
+++ b/zerver/webhooks/ifttt/view.py
@@ -29,5 +29,11 @@ def api_iftt_app_webhook(
if content is None:
raise JsonableError(_("Content can't be empty"))
+ if not isinstance(topic, str):
+ raise JsonableError(_("Topic must be a string"))
+
+ if not isinstance(content, str):
+ raise JsonableError(_("Content must be a string"))
+
check_send_webhook_message(request, user_profile, topic, content)
return json_success()