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.

canarytoken: Strengthen types using WildValue.

Anders Kaseorg02393ecad754
diff --git a/zerver/webhooks/canarytoken/view.py b/zerver/webhooks/canarytoken/view.py
index ca6713841dc..6b5ba4d685f 100644
--- a/zerver/webhooks/canarytoken/view.py
+++ b/zerver/webhooks/canarytoken/view.py
@@ -1,11 +1,12 @@
# Webhooks for external integrations.
-from typing import Any, Dict, Optional
+from typing import Optional
from django.http import HttpRequest, HttpResponse
from zerver.decorator import webhook_view
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
+from zerver.lib.validator import WildValue, check_string, to_wild_value
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
@@ -15,7 +16,7 @@ from zerver.models import UserProfile
def api_canarytoken_webhook(
request: HttpRequest,
user_profile: UserProfile,
- message: Dict[str, Any] = REQ(argument_type="body"),
+ message: WildValue = REQ(argument_type="body", converter=to_wild_value),
user_specified_topic: Optional[str] = REQ("topic", default=None),
) -> HttpResponse:
"""
@@ -28,9 +29,9 @@ def api_canarytoken_webhook(
"""
topic = "canarytoken alert"
body = (
- f"**:alert: Canarytoken has been triggered on {message['time']}!**\n\n"
- f"{message['memo']} \n\n"
- f"[Manage this canarytoken]({message['manage_url']})"
+ f"**:alert: Canarytoken has been triggered on {message['time'].tame(check_string)}!**\n\n"
+ f"{message['memo'].tame(check_string)} \n\n"
+ f"[Manage this canarytoken]({message['manage_url'].tame(check_string)})"
)
if user_specified_topic: