Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
shortcut: Reject payloads whose primary action is missing.
Anders Kaseorgfdae043e94bd
diff --git a/zerver/webhooks/shortcut/tests.py b/zerver/webhooks/shortcut/tests.pyindex 77a16754637..1165936a3a9 100644--- a/zerver/webhooks/shortcut/tests.py+++ b/zerver/webhooks/shortcut/tests.py@@ -13,6 +13,13 @@ class ShortcutWebhookTest(WebhookTestCase):self.url = self.build_webhook_url(legacy_name=legacy_name)self.check_webhook("story_create", "Add cool feature!", expected_message)+ def test_missing_primary_action(self) -> None:+ payload = self.get_body("story_create").replace('"primary_id":11', '"primary_id":12')+ result = self.client_post(self.url, payload, content_type="application/json")+ self.assert_json_error(+ result, "Unable to parse request: Did Clubhouse generate this event?"+ )+def test_story_create(self) -> None:expected_message = "New story [Add cool feature!](https://app.shortcut.com/zulip/story/11) of type **feature** was created."self.check_webhook("story_create", "Add cool feature!", expected_message)diff --git a/zerver/webhooks/shortcut/view.py b/zerver/webhooks/shortcut/view.pyindex 1b3260ddb80..e628e1c5f7a 100644--- a/zerver/webhooks/shortcut/view.py+++ b/zerver/webhooks/shortcut/view.py@@ -3,7 +3,7 @@ from collections.abc import Callable, Iterable, Iteratorfrom django.http import HttpRequest, HttpResponsefrom zerver.decorator import webhook_view-from zerver.lib.exceptions import UnsupportedWebhookEventTypeError+from zerver.lib.exceptions import AnomalousWebhookPayloadError, UnsupportedWebhookEventTypeErrorfrom zerver.lib.partial import partialfrom zerver.lib.response import json_successfrom zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint@@ -78,9 +78,9 @@ STORY_UPDATE_BATCH_ADD_REMOVE_TEMPLATE = "{operation} with {entity}"def get_action_with_primary_id(payload: WildValue) -> WildValue:for action in payload["actions"]:if payload["primary_id"].tame(check_int) == action["id"].tame(check_int):- action_with_primary_id = action+ return action- return action_with_primary_id+ raise AnomalousWebhookPayloadErrordef get_event(payload: WildValue, action: WildValue) -> str | None: