Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 333c656

Browse files
apollo13felixxm
authored andcommitted
[3.2.x] Fixed #30530, CVE-2021-44420 -- Fixed potential bypass of an upstream access control based on URL paths.
Thanks Sjoerd Job Postmus and TengMA(@te3t123) for reports. Backport of d4dcd5b from main.
1 parent 6014b81 commit 333c656

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

django/urls/resolvers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ def __init__(self, regex, name=None, is_endpoint=False):
154154
self.converters = {}
155155

156156
def match(self, path):
157-
match = self.regex.search(path)
157+
match = (
158+
self.regex.fullmatch(path)
159+
if self._is_endpoint and self.regex.pattern.endswith('$')
160+
else self.regex.search(path)
161+
)
158162
if match:
159163
# If there are any named groups, use those as kwargs, ignoring
160164
# non-named groups. Otherwise, pass all non-named arguments as
@@ -244,7 +248,7 @@ def _route_to_regex(route, is_endpoint=False):
244248
converters[parameter] = converter
245249
parts.append('(?P<' + parameter + '>' + converter.regex + ')')
246250
if is_endpoint:
247-
parts.append('$')
251+
parts.append(r'\Z')
248252
return ''.join(parts), converters
249253

250254

docs/releases/2.2.25.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ Django 2.2.25 release notes
66

77
Django 2.2.25 fixes a security issue with severity "low" in 2.2.24.
88

9-
...
9+
CVE-2021-44420: Potential bypass of an upstream access control based on URL paths
10+
=================================================================================
11+
12+
HTTP requests for URLs with trailing newlines could bypass an upstream access
13+
control based on URL paths.

docs/releases/3.1.14.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ Django 3.1.14 release notes
66

77
Django 3.1.14 fixes a security issue with severity "low" in 3.1.13.
88

9-
...
9+
CVE-2021-44420: Potential bypass of an upstream access control based on URL paths
10+
=================================================================================
11+
12+
HTTP requests for URLs with trailing newlines could bypass an upstream access
13+
control based on URL paths.

docs/releases/3.2.10.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ Django 3.2.10 release notes
44

55
*December 7, 2021*
66

7-
Django 3.2.10 fixes a security issue with severity "low" and several bugs in
8-
3.2.9.
7+
Django 3.2.10 fixes a security issue with severity "low" and a bug in 3.2.9.
8+
9+
CVE-2021-44420: Potential bypass of an upstream access control based on URL paths
10+
=================================================================================
11+
12+
HTTP requests for URLs with trailing newlines could bypass an upstream access
13+
control based on URL paths.
914

1015
Bugfixes
1116
========

tests/urlpatterns/tests.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,19 @@ def test_whitespace_in_route(self):
157157
match = p.resolve('space%s/1/' % string.whitespace)
158158
self.assertEqual(match.kwargs, {'num': 1})
159159

160+
def test_path_trailing_newlines(self):
161+
tests = [
162+
'/articles/2003/\n',
163+
'/articles/2010/\n',
164+
'/en/foo/\n',
165+
'/included_urls/extra/\n',
166+
'/regex/1/\n',
167+
'/users/1/\n',
168+
]
169+
for url in tests:
170+
with self.subTest(url=url), self.assertRaises(Resolver404):
171+
resolve(url)
172+
160173

161174
@override_settings(ROOT_URLCONF='urlpatterns.converter_urls')
162175
class ConverterTests(SimpleTestCase):

0 commit comments

Comments
 (0)