Skip to content

Commit cde1c87

Browse files
authored
Fix TooManyFieldsSent exception (#12556)
Fixes https://read-the-docs.sentry.io/issues/6575101604
1 parent 6ac9d75 commit cde1c87

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

readthedocs/core/middleware.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import structlog
22
from django.conf import settings
3+
from django.core.exceptions import TooManyFieldsSent
34
from django.http import HttpResponse
45

56

@@ -21,7 +22,19 @@ def __init__(self, get_response):
2122
self.get_response = get_response
2223

2324
def __call__(self, request):
24-
for key, value in request.GET.items():
25+
try:
26+
query_params = request.GET.items()
27+
except TooManyFieldsSent:
28+
log.info(
29+
"Too many GET parameters in request.",
30+
url=request.build_absolute_uri(),
31+
)
32+
return HttpResponse(
33+
"The number of GET parameters exceeded the maximum allowed.",
34+
status=400,
35+
)
36+
37+
for key, value in query_params:
2538
if "\x00" in value:
2639
log.info(
2740
"NULL (0x00) characters in GET attributes.",

0 commit comments

Comments
 (0)