티스토리 수익 글 보기

티스토리 수익 글 보기

Fixed #30530, CVE-2021-44420 — Fixed potential bypass of an upstream… · django/django@d4dcd5b · GitHub
Skip to content
/ django Public

Commit d4dcd5b

Browse files
apollo13felixxm
authored andcommitted
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.
1 parent 628b6a6 commit d4dcd5b

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
@@ -165,7 +165,11 @@ def __init__(self, regex, name=None, is_endpoint=False):
165165
self.converters = {}
166166

167167
def match(self, path):
168-
match = self.regex.search(path)
168+
match = (
169+
self.regex.fullmatch(path)
170+
if self._is_endpoint and self.regex.pattern.endswith('$')
171+
else self.regex.search(path)
172+
)
169173
if match:
170174
# If there are any named groups, use those as kwargs, ignoring
171175
# non-named groups. Otherwise, pass all non-named arguments as
@@ -255,7 +259,7 @@ def _route_to_regex(route, is_endpoint=False):
255259
converters[parameter] = converter
256260
parts.append('(?P<' + parameter + '>' + converter.regex + ')')
257261
if is_endpoint:
258-
parts.append('$')
262+
parts.append(r'\Z')
259263
return ''.join(parts), converters
260264

261265

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
@@ -169,6 +169,19 @@ def test_whitespace_in_route(self):
169169
match = p.resolve('space%s/1/' % string.whitespace)
170170
self.assertEqual(match.kwargs, {'num': 1})
171171

172+
def test_path_trailing_newlines(self):
173+
tests = [
174+
'/articles/2003/\n',
175+
'/articles/2010/\n',
176+
'/en/foo/\n',
177+
'/included_urls/extra/\n',
178+
'/regex/1/\n',
179+
'/users/1/\n',
180+
]
181+
for url in tests:
182+
with self.subTest(url=url), self.assertRaises(Resolver404):
183+
resolve(url)
184+
172185

173186
@override_settings(ROOT_URLCONF='urlpatterns.converter_urls')
174187
class ConverterTests(SimpleTestCase):

0 commit comments

Comments
 (0)