check file in main and sub templates

This commit is contained in:
Manuel Raynaud
2014-04-18 15:09:47 +02:00
parent 29c2901e5d
commit 80ad3068b3

View File

@@ -239,11 +239,27 @@ class SmartyParser extends Smarty implements ParserInterface
*/
public function render($realTemplateName, array $parameters = array())
{
if (false === $this->templateExists($realTemplateName)) {
if (false === $this->templateExists($realTemplateName) || false === $this->checkTemplate($realTemplateName)) {
throw new ResourceNotFoundException(Translator::getInstance()->trans("Template file %file cannot be found.", array('%file' => $realTemplateName)));
}
return $this->internalRenderer('file', $realTemplateName, $parameters);
}
private function checkTemplate($fileName)
{
$templates = $this->getTemplateDir();
$found = true;
foreach ($templates as $key => $value) {
$absolutePath = rtrim(realpath(dirname($value.$fileName)), "/");
$templateDir = rtrim(realpath($value), "/");
if (!empty($absolutePath) && strpos($absolutePath, $templateDir) !== 0) {
$found = false;
}
}
return $found;
}
/**