[4.0.x] Fixed CVE-2022-41323 -- Prevented locales being interpreted as regular expressions.

Thanks to Benjamin Balder Bach for the report.
This commit is contained in:
Adam Johnson 2022-09-02 09:44:05 +01:00 committed by Carlton Gibson
parent 4a30e0db26
commit 23f0093125
4 changed files with 17 additions and 3 deletions

View File

@ -338,7 +338,7 @@ class LocalePrefixPattern:
@property
def regex(self):
# This is only used by reverse() and cached in _reverse_dict.
return re.compile(self.language_prefix)
return re.compile(re.escape(self.language_prefix))
@property
def language_prefix(self):

View File

@ -6,4 +6,8 @@ Django 3.2.16 release notes
Django 3.2.16 fixes a security issue with severity "medium" in 3.2.15.
...
CVE-2022-41323: Potential denial-of-service vulnerability in internationalized URLs
===================================================================================
Internationalized URLs were subject to potential denial of service attack via
the locale parameter.

View File

@ -6,4 +6,8 @@ Django 4.0.8 release notes
Django 4.0.8 fixes a security issue with severity "medium" in 4.0.7.
...
CVE-2022-41323: Potential denial-of-service vulnerability in internationalized URLs
===================================================================================
Internationalized URLs were subject to potential denial of service attack via
the locale parameter.

View File

@ -198,6 +198,12 @@ class URLTranslationTests(URLTestCaseBase):
self.assertEqual(translate_url("/nl/gebruikers/", "en"), "/en/users/")
self.assertEqual(translation.get_language(), "nl")
def test_locale_not_interepreted_as_regex(self):
with translation.override("e("):
# Would previously error:
# re.error: missing ), unterminated subpattern at position 1
reverse("users")
class URLNamespaceTests(URLTestCaseBase):
"""