diff options
| author | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-06-26 12:11:54 +0200 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2024-07-09 10:40:50 -0300 |
| commit | 17358fb35fb7217423d4c4877ccb6d1a3a40b1c3 (patch) | |
| tree | e802672709dcf881b3cd1cabb980e396467d6242 /tests/i18n | |
| parent | 2b00edc0151a660d1eb86da4059904a0fc4e095e (diff) | |
[4.2.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/i18n')
| -rw-r--r-- | tests/i18n/tests.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index f517c5eac7..9b029d5992 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -65,6 +65,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 @@ -1888,6 +1889,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 |
