summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Wisselink <wisskid@users.noreply.github.com>2024-05-28 22:44:30 +0200
committerGitHub <noreply@github.com>2024-05-28 22:44:30 +0200
commit0be92bc8a6fb83e6e0d883946f7e7c09ba4e857a (patch)
tree14d7933f7638a89e431fbde31dd4f64fee15cb91 /tests
parent61db287b8fd58b2f0a714f1007bd71059b9e52a9 (diff)
downloadsmarty-0be92bc8a6fb83e6e0d883946f7e7c09ba4e857a.tar.gz
smarty-0be92bc8a6fb83e6e0d883946f7e7c09ba4e857a.tar.bz2
smarty-0be92bc8a6fb83e6e0d883946f7e7c09ba4e857a.zip
Merge pull request from GHSA-4rmg-292m-wg3w
Diffstat (limited to 'tests')
-rw-r--r--tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php36
-rw-r--r--tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/escaping.tpl1
-rw-r--r--tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/escaping2.tpl1
-rw-r--r--tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/escaping3.tpl1
-rw-r--r--tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php12
-rw-r--r--tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_security.tpl1
-rw-r--r--tests/UnitTests/TemplateSource/_Issues/419/ExtendsIssue419Test.php7
7 files changed, 56 insertions, 3 deletions
diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php b/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php
index 1b0ee50f..6f0a798f 100644
--- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php
+++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php
@@ -1193,8 +1193,38 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
);
}
- public function testBlockWithAssign() {
- $this->assertEquals('Captured content is: Content with lots of html here', $this->smarty->fetch('038_child.tpl'));
- }
+ public function testBlockWithAssign() {
+ $this->assertEquals('Captured content is: Content with lots of html here', $this->smarty->fetch('038_child.tpl'));
+ }
+
+ /**
+ * Test escaping of file parameter
+ */
+ public function testEscaping()
+ {
+ $this->expectException(\Smarty\Exception::class);
+ $this->expectExceptionMessageMatches('/Unable to load.*/');
+ $this->assertEquals('hello world', $this->smarty->fetch('escaping.tpl'));
+ }
+
+ /**
+ * Test escaping of file parameter 2
+ */
+ public function testEscaping2()
+ {
+ $this->expectException(\Smarty\Exception::class);
+ $this->expectExceptionMessageMatches('/Unable to load.*/');
+ $this->assertEquals('hello world', $this->smarty->fetch('escaping2.tpl'));
+ }
+
+ /**
+ * Test escaping of file parameter 3
+ */
+ public function testEscaping3()
+ {
+ $this->expectException(\Smarty\Exception::class);
+ $this->expectExceptionMessageMatches('/Unable to load.*/');
+ $this->assertEquals('hello world', $this->smarty->fetch('escaping3.tpl'));
+ }
}
diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/escaping.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/escaping.tpl
new file mode 100644
index 00000000..79c52e0a
--- /dev/null
+++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/escaping.tpl
@@ -0,0 +1 @@
+{extends "extends:helloworld.tpl', var_dump(shell_exec('ls')), 1, 2, 3);}}?>"} \ No newline at end of file
diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/escaping2.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/escaping2.tpl
new file mode 100644
index 00000000..d72a5718
--- /dev/null
+++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/escaping2.tpl
@@ -0,0 +1 @@
+{extends 'extends:"helloworld.tpl\', var_dump(shell_exec(\'ls\')), 1, 2, 3);}}?>'} \ No newline at end of file
diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/escaping3.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/escaping3.tpl
new file mode 100644
index 00000000..96372c82
--- /dev/null
+++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/escaping3.tpl
@@ -0,0 +1 @@
+{extends file='extends:"helloworld.tpl'|cat:"', var_dump(shell_exec('ls')), 1, 2, 3);}}?>"} \ No newline at end of file
diff --git a/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php b/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php
index 8a7cb78e..bd6eeaf4 100644
--- a/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php
+++ b/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php
@@ -83,6 +83,18 @@ class CompileIncludeTest extends PHPUnit_Smarty
}
/**
+ * test template name escaping
+ */
+ public function testIncludeFilenameEscaping()
+ {
+ $this->expectException(\Smarty\Exception::class);
+ $this->expectExceptionMessageMatches('/Unable to load.*/');
+ $tpl = $this->smarty->createTemplate('test_include_security.tpl');
+ $content = $this->smarty->fetch($tpl);
+ $this->assertEquals("hello world", $content);
+ }
+
+ /**
* test standard output
*
*
diff --git a/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_security.tpl b/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_security.tpl
new file mode 100644
index 00000000..47d83bc1
--- /dev/null
+++ b/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_security.tpl
@@ -0,0 +1 @@
+{include file="helloworld.tpl', var_dump(shell_exec('ls')), 1, 2, 3);}}?>"}
diff --git a/tests/UnitTests/TemplateSource/_Issues/419/ExtendsIssue419Test.php b/tests/UnitTests/TemplateSource/_Issues/419/ExtendsIssue419Test.php
index 2079fc0a..9f6d8164 100644
--- a/tests/UnitTests/TemplateSource/_Issues/419/ExtendsIssue419Test.php
+++ b/tests/UnitTests/TemplateSource/_Issues/419/ExtendsIssue419Test.php
@@ -32,4 +32,11 @@ class ExtendsIssue419Test extends PHPUnit_Smarty
$this->assertEquals('child', $this->smarty->fetch('extends:001_parent.tpl|001_child.tpl'));
}
+ public function testextendsSecurity()
+ {
+ $this->expectException(\Smarty\Exception::class);
+ $this->expectExceptionMessageMatches('/Unable to load.*/');
+ $this->assertEquals('child', $this->smarty->fetch('string:{include "001_parent.tpl\', var_dump(shell_exec(\'ls\')), 1, 2, 3);}}?>"}'));
+ }
+
}