Skip to content

Commit 02fb18f

Browse files
committed
Middleware: use regular HttpResponse and log the suspicious operation
Do not use `raise SuspiciousOperation` here because that ends up into Sentry marked as an error logged via logger `django.security.SuspiciousOperation`. I prefer to use regular `log.info` for these situations so they end up in NewRelic and we can parse them nicely. They are not application errors.
1 parent 389a3f8 commit 02fb18f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

readthedocs/core/middleware.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
MiddlewareNotUsed,
1010
SuspiciousOperation,
1111
)
12+
from django.http import HttpResponse
1213
from django.utils.cache import patch_vary_headers
1314
from django.utils.http import http_date
1415

@@ -211,7 +212,14 @@ def __init__(self, get_response):
211212
def __call__(self, request):
212213
for key, value in request.GET.items():
213214
if "\x00" in value:
214-
raise SuspiciousOperation(
215-
f"There are NULL (0x00) characters in at least one of the parameters ({key}) passed to the request." # noqa
215+
log.info(
216+
"NULL (0x00) characters in GET attributes.",
217+
attribute=key,
218+
value=value,
219+
url=request.build_absolute_uri(),
220+
)
221+
return HttpResponse(
222+
f"There are NULL (0x00) characters in at least one of the parameters ({key}) passed to the request.", # noqa
223+
status=400,
216224
)
217225
return self.get_response(request)

0 commit comments

Comments
 (0)