티스토리 수익 글 보기

티스토리 수익 글 보기

[1.11.x] Fixed CVE-2017-12794 — Fixed XSS possibility in traceback s… · django/django@e35a0c5 · GitHub
Skip to content
/ django Public

Commit e35a0c5

Browse files
committed
[1.11.x] Fixed CVE-2017-12794 — Fixed XSS possibility in traceback section of technical 500 debug page.
This is a security fix.
1 parent 56c4452 commit e35a0c5

File tree

4 files changed

+34
17
lines changed

4 files changed

+34
17
lines changed

django/views/debug.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -774,38 +774,37 @@ def default_urlconf(request):
774774
<h2>Traceback <span class="commands">{% if not is_email %}<a href="#" onclick="return switchPastebinFriendly(this);">
775775
Switch to copy-and-paste view</a></span>{% endif %}
776776
</h2>
777-
{% autoescape off %}
778777
<div id="browserTraceback">
779778
<ul class="traceback">
780779
{% for frame in frames %}
781780
{% ifchanged frame.exc_cause %}{% if frame.exc_cause %}
782781
<li><h3>
783782
{% if frame.exc_cause_explicit %}
784-
The above exception ({{ frame.exc_cause }}) was the direct cause of the following exception:
783+
The above exception ({{ frame.exc_cause|force_escape }}) was the direct cause of the following exception:
785784
{% else %}
786-
During handling of the above exception ({{ frame.exc_cause }}), another exception occurred:
785+
During handling of the above exception ({{ frame.exc_cause|force_escape }}), another exception occurred:
787786
{% endif %}
788787
</h3></li>
789788
{% endif %}{% endifchanged %}
790789
<li class="frame {{ frame.type }}">
791-
<code>{{ frame.filename|escape }}</code> in <code>{{ frame.function|escape }}</code>
790+
<code>{{ frame.filename }}</code> in <code>{{ frame.function }}</code>
792791
793792
{% if frame.context_line %}
794793
<div class="context" id="c{{ frame.id }}">
795794
{% if frame.pre_context and not is_email %}
796795
<ol start="{{ frame.pre_context_lineno }}" class="pre-context" id="pre{{ frame.id }}">
797796
{% for line in frame.pre_context %}
798-
<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')"><pre>{{ line|escape }}</pre></li>
797+
<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')"><pre>{{ line }}</pre></li>
799798
{% endfor %}
800799
</ol>
801800
{% endif %}
802801
<ol start="{{ frame.lineno }}" class="context-line">
803802
<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')"><pre>
804-
""" """{{ frame.context_line|escape }}</pre>{% if not is_email %} <span>...</span>{% endif %}</li></ol>
803+
""" """{{ frame.context_line }}</pre>{% if not is_email %} <span>...</span>{% endif %}</li></ol>
805804
{% if frame.post_context and not is_email %}
806805
<ol start='{{ frame.lineno|add:"1" }}' class="post-context" id="post{{ frame.id }}">
807806
{% for line in frame.post_context %}
808-
<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')"><pre>{{ line|escape }}</pre></li>
807+
<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')"><pre>{{ line }}</pre></li>
809808
{% endfor %}
810809
</ol>
811810
{% endif %}
@@ -830,7 +829,7 @@ def default_urlconf(request):
830829
<tbody>
831830
{% for var in frame.vars|dictsort:0 %}
832831
<tr>
833-
<td>{{ var.0|force_escape }}</td>
832+
<td>{{ var.0 }}</td>
834833
<td class="code"><pre>{{ var.1 }}</pre></td>
835834
</tr>
836835
{% endfor %}
@@ -841,7 +840,6 @@ def default_urlconf(request):
841840
{% endfor %}
842841
</ul>
843842
</div>
844-
{% endautoescape %}
845843
<form action="http://dpaste.com/" name="pasteform" id="pasteform" method="post">
846844
{% if not is_email %}
847845
<div id="pastebinTraceback" class="pastebin">
@@ -887,9 +885,9 @@ def default_urlconf(request):
887885
888886
Traceback:{% for frame in frames %}
889887
{% ifchanged frame.exc_cause %}{% if frame.exc_cause %}{% if frame.exc_cause_explicit %}
890-
The above exception ({{ frame.exc_cause }}) was the direct cause of the following exception:
888+
The above exception ({{ frame.exc_cause|force_escape }}) was the direct cause of the following exception:
891889
{% else %}
892-
During handling of the above exception ({{ frame.exc_cause }}), another exception occurred:
890+
During handling of the above exception ({{ frame.exc_cause|force_escape }}), another exception occurred:
893891
{% endif %}{% endif %}{% endifchanged %}
894892
File "{{ frame.filename|escape }}" in {{ frame.function|escape }}
895893
{% if frame.context_line %} {{ frame.lineno }}. {{ frame.context_line|escape }}{% endif %}{% endfor %}

docs/releases/1.10.8.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@ Django 1.10.8 release notes
55
*September 5, 2017*
66

77
Django 1.10.8 fixes a security issue in 1.10.7.
8+
9+
CVE-2017-12794: Possible XSS in traceback section of technical 500 debug page
10+
=============================================================================
11+
12+
In older versions, HTML autoescaping was disabled in a portion of the template
13+
for the technical 500 debug page. Given the right circumstances, this allowed
14+
a cross-site scripting attack. This vulnerability shouldn't affect most
15+
production sites since you shouldn't run with ``DEBUG = True`` (which makes
16+
this page accessible) in your production settings.

docs/releases/1.11.5.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ Django 1.11.5 release notes
66

77
Django 1.11.5 fixes a security issue and several bugs in 1.11.4.
88

9+
CVE-2017-12794: Possible XSS in traceback section of technical 500 debug page
10+
=============================================================================
11+
12+
In older versions, HTML autoescaping was disabled in a portion of the template
13+
for the technical 500 debug page. Given the right circumstances, this allowed
14+
a cross-site scripting attack. This vulnerability shouldn't affect most
15+
production sites since you shouldn't run with ``DEBUG = True`` (which makes
16+
this page accessible) in your production settings.
17+
918
Bugfixes
1019
========
1120

tests/view_tests/tests/py3_test_debug.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys
1010

1111
from django.test import RequestFactory, TestCase
12+
from django.utils.safestring import mark_safe
1213
from django.views.debug import ExceptionReporter
1314

1415

@@ -20,10 +21,10 @@ def test_reporting_of_nested_exceptions(self):
2021
request = self.rf.get('/test_view/')
2122
try:
2223
try:
23-
raise AttributeError('Top level')
24+
raise AttributeError(mark_safe('<p>Top level</p>'))
2425
except AttributeError as explicit:
2526
try:
26-
raise ValueError('Second exception') from explicit
27+
raise ValueError('<p>Second exception</p>') from explicit
2728
except ValueError:
2829
raise IndexError('Final exception')
2930
except Exception:
@@ -37,9 +38,9 @@ def test_reporting_of_nested_exceptions(self):
3738
html = reporter.get_traceback_html()
3839
# Both messages are twice on page -- one rendered as html,
3940
# one as plain text (for pastebin)
40-
self.assertEqual(2, html.count(explicit_exc.format("Top level")))
41-
self.assertEqual(2, html.count(implicit_exc.format("Second exception")))
41+
self.assertEqual(2, html.count(explicit_exc.format('&lt;p&gt;Top level&lt;/p&gt;')))
42+
self.assertEqual(2, html.count(implicit_exc.format('&lt;p&gt;Second exception&lt;/p&gt;')))
4243

4344
text = reporter.get_traceback_text()
44-
self.assertIn(explicit_exc.format("Top level"), text)
45-
self.assertIn(implicit_exc.format("Second exception"), text)
45+
self.assertIn(explicit_exc.format('<p>Top level</p>'), text)
46+
self.assertIn(implicit_exc.format('<p>Second exception</p>'), text)

0 commit comments

Comments
 (0)