fixed sandbox security issue

This commit is contained in:
Fabien Potencier
2015-08-11 16:20:28 +02:00
parent 7b6c0e971f
commit 30be07759a
2 changed files with 14 additions and 0 deletions
+5
View File
@@ -154,6 +154,11 @@ abstract class Twig_Template implements Twig_TemplateInterface
}
if (null !== $template) {
// avoid RCEs when sandbox is enabled
if (!$template instanceof Twig_Template) {
throw new \LogicException('A block must be a method on a Twig_Template instance.');
}
try {
$template->$block($context, $blocks);
} catch (Twig_Error $e) {
+9
View File
@@ -10,6 +10,15 @@
*/
class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
{
/**
* @expectedException LogicException
*/
public function testDisplayBlocksAcceptTemplateOnlyAsBlocks()
{
$template = $this->getMockForAbstractClass('Twig_Template', array(), '', false);
$template->displayBlock('foo', array(), array('foo' => array(new stdClass(), 'foo')));
}
/**
* @dataProvider getAttributeExceptions
*/