mirror of
https://github.com/django/django.git
synced 2025-07-23 05:05:17 +00:00
[4.0.x] Fixed CVE-2022-22818 -- Fixed possible XSS via {% debug %} template tag.
Thanks Keryn Knight for the report.
Backport of 394517f078
from main.
Co-authored-by: Adam Johnson <me@adamj.eu>
This commit is contained in:
parent
6928227dff
commit
0142204606
7 changed files with 87 additions and 16 deletions
46
tests/template_tests/syntax_tests/test_debug.py
Normal file
46
tests/template_tests/syntax_tests/test_debug.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
from django.contrib.auth.models import Group
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
|
||||
from ..utils import setup
|
||||
|
||||
|
||||
@override_settings(DEBUG=True)
|
||||
class DebugTests(SimpleTestCase):
|
||||
|
||||
@override_settings(DEBUG=False)
|
||||
@setup({'non_debug': '{% debug %}'})
|
||||
def test_non_debug(self):
|
||||
output = self.engine.render_to_string('non_debug', {})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
@setup({'modules': '{% debug %}'})
|
||||
def test_modules(self):
|
||||
output = self.engine.render_to_string('modules', {})
|
||||
self.assertIn(
|
||||
''django': <module 'django' ',
|
||||
output,
|
||||
)
|
||||
|
||||
@setup({'plain': '{% debug %}'})
|
||||
def test_plain(self):
|
||||
output = self.engine.render_to_string('plain', {'a': 1})
|
||||
self.assertTrue(output.startswith(
|
||||
'{'a': 1}'
|
||||
'{'False': False, 'None': None, '
|
||||
''True': True}\n\n{'
|
||||
))
|
||||
|
||||
@setup({'non_ascii': '{% debug %}'})
|
||||
def test_non_ascii(self):
|
||||
group = Group(name="清風")
|
||||
output = self.engine.render_to_string('non_ascii', {'group': group})
|
||||
self.assertTrue(output.startswith(
|
||||
'{'group': <Group: 清風>}'
|
||||
))
|
||||
|
||||
@setup({'script': '{% debug %}'})
|
||||
def test_script(self):
|
||||
output = self.engine.render_to_string('script', {'frag': '<script>'})
|
||||
self.assertTrue(output.startswith(
|
||||
'{'frag': '<script>'}'
|
||||
))
|
Loading…
Add table
Add a link
Reference in a new issue