티스토리 수익 글 보기

티스토리 수익 글 보기

[1.11.x] Fixed #30070, CVE-2019-3498 — Fixed content spoofing possib… · django/django@1cd00fc · GitHub
Skip to content

Commit 1cd00fc

Browse files
tasntimgraham
andcommitted
[1.11.x] Fixed #30070, CVE-2019-3498 — Fixed content spoofing possiblity in the default 404 page.
Co-Authored-By: Tim Graham <timograham@gmail.com> Backport of 1ecc0a3 from master.
1 parent b683bb0 commit 1cd00fc

4 files changed

Lines changed: 32 additions & 7 deletions

File tree

django/views/defaults.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.template import Context, Engine, TemplateDoesNotExist, loader
33
from django.utils import six
44
from django.utils.encoding import force_text
5+
from django.utils.http import urlquote
56
from django.views.decorators.csrf import requires_csrf_token
67

78
ERROR_404_TEMPLATE_NAME = '404.html'
@@ -21,7 +22,8 @@ def page_not_found(request, exception, template_name=ERROR_404_TEMPLATE_NAME):
2122
Templates: :template:`404.html`
2223
Context:
2324
request_path
24-
The path of the requested URL (e.g., '/app/pages/bad_page/')
25+
The path of the requested URL (e.g., '/app/pages/bad_page/'). It's
26+
quoted to prevent a content injection attack.
2527
exception
2628
The message from the exception which triggered the 404 (if one was
2729
supplied), or the exception class name
@@ -37,7 +39,7 @@ def page_not_found(request, exception, template_name=ERROR_404_TEMPLATE_NAME):
3739
if isinstance(message, six.text_type):
3840
exception_repr = message
3941
context = {
40-
'request_path': request.path,
42+
'request_path': urlquote(request.path),
4143
'exception': exception_repr,
4244
}
4345
try:
@@ -50,7 +52,7 @@ def page_not_found(request, exception, template_name=ERROR_404_TEMPLATE_NAME):
5052
raise
5153
template = Engine().from_string(
5254
'<h1>Not Found</h1>'
53-
'<p>The requested URL {{ request_path }} was not found on this server.</p>')
55+
'<p>The requested resource was not found on this server.</p>')
5456
body = template.render(Context(context))
5557
content_type = 'text/html'
5658
return http.HttpResponseNotFound(body, content_type=content_type)

docs/releases/1.11.18.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
============================
2+
Django 1.11.18 release notes
3+
============================
4+
5+
*January 4, 2019*
6+
7+
Django 1.11.18 fixes a security issue in 1.11.17.
8+
9+
CVE-2019-3498: Content spoofing possibility in the default 404 page
10+
-------------------------------------------------------------------
11+
12+
An attacker could craft a malicious URL that could make spoofed content appear
13+
on the default page generated by the ``django.views.defaults.page_not_found()``
14+
view.
15+
16+
The URL path is no longer displayed in the default 404 template and the
17+
``request_path`` context variable is now quoted to fix the issue for custom
18+
templates that use the path.

docs/releases/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ versions of the documentation contain the release notes for any later releases.
2626
.. toctree::
2727
:maxdepth: 1
2828

29+
1.11.18
2930
1.11.17
3031
1.11.16
3132
1.11.15

tests/handlers/tests.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import unicode_literals
44

5+
import sys
56
import unittest
67

78
from django.core.exceptions import ImproperlyConfigured
@@ -19,6 +20,8 @@
1920
except ImportError: # Python < 3.5
2021
HTTPStatus = None
2122

23+
PY37 = sys.version_info >= (3, 7, 0)
24+
2225

2326
class HandlerTests(SimpleTestCase):
2427

@@ -184,16 +187,17 @@ def test_suspiciousop_in_view_returns_400(self):
184187

185188
def test_invalid_urls(self):
186189
response = self.client.get('~%A9helloworld')
187-
self.assertContains(response, '~%A9helloworld', status_code=404)
190+
self.assertEqual(response.status_code, 404)
191+
self.assertEqual(response.context['request_path'], '/~%25A9helloworld' if PY37 else '/%7E%25A9helloworld')
188192

189193
response = self.client.get('d%aao%aaw%aan%aal%aao%aaa%aad%aa/')
190-
self.assertContains(response, 'd%AAo%AAw%AAn%AAl%AAo%AAa%AAd%AA', status_code=404)
194+
self.assertEqual(response.context['request_path'], '/d%25AAo%25AAw%25AAn%25AAl%25AAo%25AAa%25AAd%25AA')
191195

192196
response = self.client.get('/%E2%99%E2%99%A5/')
193-
self.assertContains(response, '%E2%99\u2665', status_code=404)
197+
self.assertEqual(response.context['request_path'], '/%25E2%2599%E2%99%A5/')
194198

195199
response = self.client.get('/%E2%98%8E%E2%A9%E2%99%A5/')
196-
self.assertContains(response, '\u260e%E2%A9\u2665', status_code=404)
200+
self.assertEqual(response.context['request_path'], '/%E2%98%8E%25E2%25A9%E2%99%A5/')
197201

198202
def test_environ_path_info_type(self):
199203
environ = RequestFactory().get('/%E2%A8%87%87%A5%E2%A8%A0').environ

0 commit comments

Comments
 (0)