summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-06-26 12:11:54 +0200
committerNatalia <124304+nessita@users.noreply.github.com>2024-07-09 09:42:58 -0300
commite99ccc43429160828814a72067acf47f5fca9c94 (patch)
treef1db7e77c189de1ceb7e2202d6131bb9ce58643a /tests
parent6d36203648a7e14abc89b9aeb8ae9678535b51fb (diff)
[5.1.x] Fixed CVE-2024-39614 -- Mitigated potential DoS in get_supported_language_variant().
Language codes are now parsed with a maximum length limit of 500 chars. Thanks to MProgrammer for the report.
Diffstat (limited to 'tests')
-rw-r--r--tests/i18n/tests.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
index 355505a10d..1bd1dadf93 100644
--- a/tests/i18n/tests.py
+++ b/tests/i18n/tests.py
@@ -58,6 +58,7 @@ from django.utils.translation.reloader import (
translation_file_changed,
watch_for_translation_changes,
)
+from django.utils.translation.trans_real import LANGUAGE_CODE_MAX_LENGTH
from .forms import CompanyForm, I18nForm, SelectDateForm
from .models import Company, TestModel
@@ -1672,6 +1673,16 @@ class MiscTests(SimpleTestCase):
g("xyz")
with self.assertRaises(LookupError):
g("xy-zz")
+ msg = "'lang_code' exceeds the maximum accepted length"
+ with self.assertRaises(LookupError):
+ g("x" * LANGUAGE_CODE_MAX_LENGTH)
+ with self.assertRaisesMessage(ValueError, msg):
+ g("x" * (LANGUAGE_CODE_MAX_LENGTH + 1))
+ # 167 * 3 = 501 which is LANGUAGE_CODE_MAX_LENGTH + 1.
+ self.assertEqual(g("en-" * 167), "en")
+ with self.assertRaisesMessage(ValueError, msg):
+ g("en-" * 167, strict=True)
+ self.assertEqual(g("en-" * 30000), "en") # catastrophic test
def test_get_supported_language_variant_null(self):
g = trans_null.get_supported_language_variant