summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2013-08-27 21:06:33 -0400
committerTim Graham <timograham@gmail.com>2013-09-10 21:05:47 -0400
commit87d2750b39f6f2d54b7047225521a44dcd37e896 (patch)
treed5f279386853d9b87f26011770cb0ba65399e28c /tests
parent9ab7ed9b726a2bb0eee1d89327b9bf7ea75bba38 (diff)
[1.4.x] Prevented arbitrary file inclusion with {% ssi %} tag and relative paths.
Thanks Rainer Koirikivi for the report and draft patch. This is a security fix; disclosure to follow shortly. Backport of 7fe5b656c9 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/templates/tests.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index f74aa757e6..6b02c83cb8 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -1764,3 +1764,34 @@ class RequestContextTests(BaseTemplateResponseTest):
template.Template('{% include "child" only %}').render(ctx),
'none'
)
+
+
+class SSITests(unittest.TestCase):
+ def setUp(self):
+ self.this_dir = os.path.dirname(os.path.abspath(__file__))
+ self.ssi_dir = os.path.join(self.this_dir, "templates", "first")
+
+ 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())
+
+ 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')
+
+ def test_relative_include_exploit(self):
+ """
+ May not bypass ALLOWED_INCLUDE_ROOTS with relative paths
+
+ 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), '')