webhooks/jira: Handle anomalous payloads properly.

We recently ran into a payload in production that didn't contain
an event type at all. A payload where we can't figure out the event
type is quite rare. Instead of letting these payloads run amok, we
should raise a more informative exception for such unusual payloads.
If we encounter too many of these, then we can choose to conduct a
deeper investigation on a case-by-case basis.

With some changes by Tim Abbott.
This commit is contained in:
Eeshan Garg
2021-09-13 14:23:54 -04:00
committed by Tim Abbott
parent c5c3ab66d6
commit 2393342e03
8 changed files with 110 additions and 32 deletions

View File

@@ -4,7 +4,7 @@ from typing import Any, Callable, Dict, Optional
from django.http import HttpRequest, HttpResponse
from zerver.decorator import log_exception_to_webhook_logger, webhook_view
from zerver.decorator import log_unsupported_webhook_event, webhook_view
from zerver.lib.exceptions import UnsupportedWebhookEventType
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
@@ -45,9 +45,8 @@ class Helper:
def log_unsupported(self, event: str) -> None:
summary = f"The '{event}' event isn't currently supported by the GitHub webhook"
log_exception_to_webhook_logger(
log_unsupported_webhook_event(
summary=summary,
unsupported_event=True,
)