Skip to content

Commit

Permalink
Fix potential security vector in emptiness check
Browse files Browse the repository at this point in the history
- Fixes a similar security vector to those fixed in previous commits,
  instead caused by scalar strings used in sections, typically used
  to check for emptiness.
  - Now validates the callback to determine if it is valid; if not,
    processes it as a boolean check
  • Loading branch information
andytson authored and weierophinney committed Mar 14, 2012
1 parent 12f50a1 commit c83086d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/Phly/Mustache/Renderer.php
Expand Up @@ -141,7 +141,7 @@ public function render(array $tokens, $view, array $partials = null)
$rendered .= $renderedSection;
break;
}
} elseif (is_callable($section)) {
} elseif (is_callable($section) && $this->isValidCallback($section)) {
// Higher order section
// Execute the callback, passing it the section's template
// string, as well as a renderer lambda.
Expand Down
11 changes: 11 additions & 0 deletions tests/PhlyTest/Mustache/MustacheTest.php
Expand Up @@ -586,6 +586,17 @@ public function testArrayValuesThatReferToStaticMethodsShouldNotCallThem()
$this->assertEquals('DateTime::createFromFormat', trim($test));
}

/**
* @group injection-issues
*/
public function testStringValuesThatReferToFunctionsShouldNotCallThem()
{
$model = array('message' => 'time');
$this->mustache->getRenderer()->addPragma(new ImplicitIterator());
$test = $this->mustache->render('template-referencing-static-function-notempty', $model);
$this->assertEquals('time', trim($test));
}

/**
* @group injection-issues
*/
Expand Down
@@ -0,0 +1,3 @@
{{#message}}
{{message}}
{{/message}}

0 comments on commit c83086d

Please sign in to comment.