From 6463519a6c05e614158d00d59df906433e869da3 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Sun, 24 Jan 2021 23:13:26 +0100 Subject: [PATCH] Prevent access to .template_object when in security mode to prevent PHP code injection vulnerability --- CHANGELOG.md | 3 +++ .../smarty_internal_compile_private_special_variable.php | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06b89822..c26136bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Prevent access to `$smarty.template_object` in Security mode + ## [3.1.38] - 2021-01-08 ### Fixed diff --git a/libs/sysplugins/smarty_internal_compile_private_special_variable.php b/libs/sysplugins/smarty_internal_compile_private_special_variable.php index de7d4a22..d53ef51f 100644 --- a/libs/sysplugins/smarty_internal_compile_private_special_variable.php +++ b/libs/sysplugins/smarty_internal_compile_private_special_variable.php @@ -81,6 +81,10 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C case 'template': return 'basename($_smarty_tpl->source->filepath)'; case 'template_object': + if (isset($compiler->smarty->security_policy)) { + $compiler->trigger_template_error("(secure mode) template_object not permitted"); + break; + } return '$_smarty_tpl'; case 'current_dir': return 'dirname($_smarty_tpl->source->filepath)';