mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Deprecated ALLOWED_INCLUDE_ROOTS.
This commit is contained in:
parent
84d7c93feb
commit
3dc01aaaaf
6 changed files with 26 additions and 18 deletions
|
@ -470,28 +470,27 @@ class SSITests(SimpleTestCase):
|
|||
def setUp(self):
|
||||
self.this_dir = os.path.dirname(os.path.abspath(upath(__file__)))
|
||||
self.ssi_dir = os.path.join(self.this_dir, "templates", "first")
|
||||
self.engine = Engine(allowed_include_roots=(self.ssi_dir,))
|
||||
|
||||
def render_ssi(self, path):
|
||||
# the path must exist for the test to be reliable
|
||||
self.assertTrue(os.path.exists(path))
|
||||
return template.Template('{%% ssi "%s" %%}' % path).render(Context())
|
||||
return self.engine.from_string('{%% ssi "%s" %%}' % path).render(Context({}))
|
||||
|
||||
def test_allowed_paths(self):
|
||||
acceptable_path = os.path.join(self.ssi_dir, "..", "first", "test.html")
|
||||
with override_settings(ALLOWED_INCLUDE_ROOTS=(self.ssi_dir,)):
|
||||
self.assertEqual(self.render_ssi(acceptable_path), 'First template\n')
|
||||
self.assertEqual(self.render_ssi(acceptable_path), 'First template\n')
|
||||
|
||||
def test_relative_include_exploit(self):
|
||||
"""
|
||||
May not bypass ALLOWED_INCLUDE_ROOTS with relative paths
|
||||
May not bypass allowed_include_roots with relative paths
|
||||
|
||||
e.g. if ALLOWED_INCLUDE_ROOTS = ("/var/www",), it should not be
|
||||
e.g. if allowed_include_roots = ("/var/www",), it should not be
|
||||
possible to do {% ssi "/var/www/../../etc/passwd" %}
|
||||
"""
|
||||
disallowed_paths = [
|
||||
os.path.join(self.ssi_dir, "..", "ssi_include.html"),
|
||||
os.path.join(self.ssi_dir, "..", "second", "test.html"),
|
||||
]
|
||||
with override_settings(ALLOWED_INCLUDE_ROOTS=(self.ssi_dir,)):
|
||||
for path in disallowed_paths:
|
||||
self.assertEqual(self.render_ssi(path), '')
|
||||
for disallowed_path in disallowed_paths:
|
||||
self.assertEqual(self.render_ssi(disallowed_path), '')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue