Skip to content

Commit

Permalink
fixed sandbox security issue
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Aug 12, 2015
1 parent 7b6c0e9 commit 30be077
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Twig/Template.php
Expand Up @@ -154,6 +154,11 @@ public function displayBlock($name, array $context, array $blocks = array(), $us
}

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) {
Expand Down
9 changes: 9 additions & 0 deletions test/Twig/Tests/TemplateTest.php
Expand Up @@ -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
*/
Expand Down

0 comments on commit 30be077

Please sign in to comment.