diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-05-12 15:27:59 -0400 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-05-12 15:58:53 -0400 |
| commit | 335c6d0129400eda792f3bec5c71bb28af5e5d37 (patch) | |
| tree | 0f36258b6f3a69a2b2e731ad95a7eec6cdabae7c /tests | |
| parent | ed13a58bf63df94508c8a0fe779da0b6a2bc26bb (diff) | |
Fixed #37095 -- Checked maximum redirect lengths against percent-encoded URLs.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/httpwrappers/tests.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py index b990e9f816..151088909c 100644 --- a/tests/httpwrappers/tests.py +++ b/tests/httpwrappers/tests.py @@ -24,6 +24,7 @@ from django.http import ( parse_cookie, ) from django.test import SimpleTestCase +from django.utils.encoding import iri_to_uri from django.utils.functional import lazystr from django.utils.http import MAX_URL_REDIRECT_LENGTH @@ -498,6 +499,18 @@ class HttpResponseTests(SimpleTestCase): response = response_class(long_url) self.assertEqual(response.url, long_url) + def test_redirect_url_max_length_checks_encoded_location(self): + long_url = "/" + "é" * (MAX_URL_REDIRECT_LENGTH - 1) + self.assertLessEqual(len(long_url), MAX_URL_REDIRECT_LENGTH) + self.assertGreater(len(iri_to_uri(long_url)), MAX_URL_REDIRECT_LENGTH) + for response_class in (HttpResponseRedirect, HttpResponsePermanentRedirect): + msg = f"Unsafe redirect exceeding {MAX_URL_REDIRECT_LENGTH} characters" + with ( + self.subTest(response_class=response_class), + self.assertRaisesMessage(DisallowedRedirect, msg), + ): + response_class(long_url) + def test_redirect_url_max_length_override_via_param(self): base_url = "https://example.com/" for (max_length, length), response_class in itertools.product( |
