From 9e9792228a6bb5d6402a5d645bc3be4cf364aefb Mon Sep 17 00:00:00 2001 From: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> Date: Wed, 26 Jun 2024 12:11:54 +0200 Subject: 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. --- tests/i18n/tests.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') 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 -- cgit v1.3