summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorvarunkasyap <varunkasyap@hotmail.com>2025-11-26 14:28:24 -0300
committerNatalia <124304+nessita@users.noreply.github.com>2025-11-26 17:31:17 -0300
commite6973490373dca340e36f2db3eae1eb26a6a2d80 (patch)
tree614503d6f6049610d3789dd4ea7802c0d687235f /django
parent7d7f27bc9881dede6337212db1e9ccdbd37addae (diff)
[4.2.x] Fixed #36743 -- Increased URL max length enforced in HttpResponseRedirectBase.
Refs CVE-2025-64458. The previous limit of 2048 characters reused the URLValidator constant and proved too restrictive for legitimate redirects to some third-party services. This change introduces a separate `MAX_URL_REDIRECT_LENGTH` constant (defaulting to 16384) and uses it in HttpResponseRedirectBase. Thanks Jacob Walls for report and review. Backport of a8cf8c292cfee98fe6cc873ca5221935f1d02271 from main.
Diffstat (limited to 'django')
-rw-r--r--django/http/response.py10
-rw-r--r--django/utils/http.py1
2 files changed, 8 insertions, 3 deletions
diff --git a/django/http/response.py b/django/http/response.py
index 763fd2a8ac..28b8fa6d36 100644
--- a/django/http/response.py
+++ b/django/http/response.py
@@ -21,7 +21,11 @@ from django.http.cookie import SimpleCookie
from django.utils import timezone
from django.utils.datastructures import CaseInsensitiveMapping
from django.utils.encoding import iri_to_uri
-from django.utils.http import MAX_URL_LENGTH, content_disposition_header, http_date
+from django.utils.http import (
+ MAX_URL_REDIRECT_LENGTH,
+ content_disposition_header,
+ http_date,
+)
from django.utils.regex_helper import _lazy_re_compile
_charset_from_content_type_re = _lazy_re_compile(
@@ -615,9 +619,9 @@ class HttpResponseRedirectBase(HttpResponse):
super().__init__(*args, **kwargs)
self["Location"] = iri_to_uri(redirect_to)
redirect_to_str = str(redirect_to)
- if len(redirect_to_str) > MAX_URL_LENGTH:
+ if len(redirect_to_str) > MAX_URL_REDIRECT_LENGTH:
raise DisallowedRedirect(
- f"Unsafe redirect exceeding {MAX_URL_LENGTH} characters"
+ f"Unsafe redirect exceeding {MAX_URL_REDIRECT_LENGTH} characters"
)
parsed = urlparse(redirect_to_str)
if parsed.scheme and parsed.scheme not in self.allowed_schemes:
diff --git a/django/utils/http.py b/django/utils/http.py
index 244ff7e866..0804937f38 100644
--- a/django/utils/http.py
+++ b/django/utils/http.py
@@ -48,6 +48,7 @@ ASCTIME_DATE = _lazy_re_compile(r"^\w{3} %s %s %s %s$" % (__M, __D2, __T, __Y))
RFC3986_GENDELIMS = ":/?#[]@"
RFC3986_SUBDELIMS = "!$&'()*+,;="
MAX_URL_LENGTH = 2048
+MAX_URL_REDIRECT_LENGTH = 16384
# TODO: Remove when dropping support for PY38.
# Unsafe bytes to be removed per WHATWG spec.