summaryrefslogtreecommitdiff
path: root/tests/i18n
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:21:19 -0300
commit9e9792228a6bb5d6402a5d645bc3be4cf364aefb (patch)
treeea41fef55606e996dac4bd488fce2afe9df99a09 /tests/i18n
parentfe4a0bbe2088d0c2b331216dad21ccd0bb3ee80d (diff)
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/i18n')
-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