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.

sentry: Ignore all SuspiciousOperation loggers.

Alex Vandiver596cf2580bf4
diff --git a/zerver/middleware.py b/zerver/middleware.py
index 31ab5af5833..42d9fa5b9ed 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 21b00dd44b4..92b0f34d2c8 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")