diff --git a/zerver/middleware.py b/zerver/middleware.py index 31ab5af583..42d9fa5b9e 100644 --- a/zerver/middleware.py +++ b/zerver/middleware.py @@ -384,10 +384,6 @@ class FlushDisplayRecipientCache(MiddlewareMixin): return response class HostDomainMiddleware(MiddlewareMixin): - def __init__(self, get_response: Callable[[Any, WSGIRequest], Union[HttpResponse, BaseException]]) -> None: - super().__init__(get_response) - ignore_logger("django.security.DisallowedHost") - def process_request(self, request: HttpRequest) -> Optional[HttpResponse]: # Match against ALLOWED_HOSTS, which is rather permissive; # failure will raise DisallowedHost, which is a 400. diff --git a/zproject/sentry.py b/zproject/sentry.py index 21b00dd44b..92b0f34d2c 100644 --- a/zproject/sentry.py +++ b/zproject/sentry.py @@ -3,6 +3,7 @@ from typing import TYPE_CHECKING, Optional import sentry_sdk from sentry_sdk.integrations import Integration from sentry_sdk.integrations.django import DjangoIntegration +from sentry_sdk.integrations.logging import ignore_logger from sentry_sdk.integrations.redis import RedisIntegration from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration from sentry_sdk.utils import capture_internal_exceptions @@ -44,3 +45,16 @@ def setup_sentry(dsn: Optional[str], *integrations: Integration) -> None: ], before_send=add_context, ) + + # Ignore all of the loggers from django.security that are for user + # errors; see https://docs.djangoproject.com/en/3.0/ref/exceptions/#suspiciousoperation + ignore_logger("django.security.DisallowedHost") + ignore_logger("django.security.DisallowedModelAdminLookup") + ignore_logger("django.security.DisallowedModelAdminToField") + ignore_logger("django.security.DisallowedRedirect") + ignore_logger("django.security.InvalidSessionKey") + ignore_logger("django.security.RequestDataTooBig") + ignore_logger("django.security.SuspiciousFileOperation") + ignore_logger("django.security.SuspiciousMultipartForm") + ignore_logger("django.security.SuspiciousSession") + ignore_logger("django.security.TooManyFieldsSent")