mirror of
https://github.com/smarty-php/smarty.git
synced 2026-08-12 00:11:22 +02:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f707dadecb | ||
|
|
ace1c8e90f | ||
|
|
19ae410bf5 | ||
|
|
baad3115cd |
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [4.0.3] - 2022-01-10
|
||||||
|
|
||||||
|
### Security
|
||||||
|
- Prevent evasion of the `static_classes` security policy. This addresses CVE-2021-21408
|
||||||
|
|
||||||
## [4.0.2] - 2022-01-10
|
## [4.0.2] - 2022-01-10
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|||||||
@@ -747,6 +747,9 @@ value(res) ::= doublequoted_with_quotes(s). {
|
|||||||
|
|
||||||
|
|
||||||
value(res) ::= varindexed(vi) DOUBLECOLON static_class_access(r). {
|
value(res) ::= varindexed(vi) DOUBLECOLON static_class_access(r). {
|
||||||
|
if ($this->security && $this->security->static_classes !== array()) {
|
||||||
|
$this->compiler->trigger_template_error('dynamic static class not allowed by security setting');
|
||||||
|
}
|
||||||
$prefixVar = $this->compiler->getNewPrefixVariable();
|
$prefixVar = $this->compiler->getNewPrefixVariable();
|
||||||
if (vi['var'] === '\'smarty\'') {
|
if (vi['var'] === '\'smarty\'') {
|
||||||
$this->compiler->appendPrefixCode("<?php {$prefixVar} = ". $this->compiler->compileTag('private_special_variable',array(),vi['smarty_internal_index']).';?>');
|
$this->compiler->appendPrefixCode("<?php {$prefixVar} = ". $this->compiler->compileTag('private_special_variable',array(),vi['smarty_internal_index']).';?>');
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '4.0.2';
|
const SMARTY_VERSION = '4.0.3';
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2397,6 +2397,9 @@ public static $yy_action = array(
|
|||||||
}
|
}
|
||||||
// line 749 "../smarty/lexer/smarty_internal_templateparser.y"
|
// line 749 "../smarty/lexer/smarty_internal_templateparser.y"
|
||||||
public function yy_r94(){
|
public function yy_r94(){
|
||||||
|
if ($this->security && $this->security->static_classes !== array()) {
|
||||||
|
$this->compiler->trigger_template_error('dynamic static class not allowed by security setting');
|
||||||
|
}
|
||||||
$prefixVar = $this->compiler->getNewPrefixVariable();
|
$prefixVar = $this->compiler->getNewPrefixVariable();
|
||||||
if ($this->yystack[$this->yyidx + -2]->minor['var'] === '\'smarty\'') {
|
if ($this->yystack[$this->yyidx + -2]->minor['var'] === '\'smarty\'') {
|
||||||
$this->compiler->appendPrefixCode("<?php {$prefixVar} = ". $this->compiler->compileTag('private_special_variable',array(),$this->yystack[$this->yyidx + -2]->minor['smarty_internal_index']).';?>');
|
$this->compiler->appendPrefixCode("<?php {$prefixVar} = ". $this->compiler->compileTag('private_special_variable',array(),$this->yystack[$this->yyidx + -2]->minor['smarty_internal_index']).';?>');
|
||||||
|
|||||||
@@ -257,19 +257,41 @@ class SecurityTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals('25', $this->smarty->fetch($tpl));
|
$this->assertEquals('25', $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test not trusted PHP function
|
* test not trusted PHP function
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
*/
|
*/
|
||||||
public function testNotTrustedStaticClass()
|
public function testNotTrustedStaticClass()
|
||||||
{
|
{
|
||||||
$this->expectException('SmartyException');
|
$this->expectException('SmartyException');
|
||||||
$this->expectExceptionMessage('access to static class \'mysecuritystaticclass\' not allowed by security setting');
|
$this->expectExceptionMessage('access to static class \'mysecuritystaticclass\' not allowed by security setting');
|
||||||
$this->smarty->security_policy->static_classes = array('null');
|
$this->smarty->security_policy->static_classes = array('null');
|
||||||
$this->smarty->fetch('string:{mysecuritystaticclass::square(5)}');
|
$this->smarty->fetch('string:{mysecuritystaticclass::square(5)}');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test not trusted PHP function
|
||||||
|
*/
|
||||||
|
public function testNotTrustedStaticClassEval()
|
||||||
|
{
|
||||||
|
$this->expectException('SmartyException');
|
||||||
|
$this->expectExceptionMessage('dynamic static class not allowed by security setting');
|
||||||
|
$this->smarty->security_policy->static_classes = array('null');
|
||||||
|
$this->smarty->fetch('string:{$test = "mysecuritystaticclass"}{$test::square(5)}');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test not trusted PHP function
|
||||||
|
*/
|
||||||
|
public function testNotTrustedStaticClassSmartyVar()
|
||||||
|
{
|
||||||
|
$this->expectException('SmartyException');
|
||||||
|
$this->expectExceptionMessage('dynamic static class not allowed by security setting');
|
||||||
|
$this->smarty->security_policy->static_classes = array('null');
|
||||||
|
$this->smarty->fetch('string:{$smarty.template_object::square(5)}');
|
||||||
|
}
|
||||||
|
|
||||||
public function testChangedTrustedDirectory()
|
public function testChangedTrustedDirectory()
|
||||||
{
|
{
|
||||||
$this->smarty->security_policy->secure_dir = array(
|
$this->smarty->security_policy->secure_dir = array(
|
||||||
|
|||||||
@@ -108,31 +108,25 @@ class MathTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException PHPUnit_Framework_Error_Warning
|
|
||||||
*/
|
|
||||||
public function testBackticksIllegal()
|
public function testBackticksIllegal()
|
||||||
{
|
{
|
||||||
|
$this->expectException(PHPUnit\Framework\Error\Warning::class);
|
||||||
$expected = "22.00";
|
$expected = "22.00";
|
||||||
$tpl = $this->smarty->createTemplate('eval:{$x = "4"}{$y = "5.5"}{math equation="`ls` x * y" x=$x y=$y}');
|
$tpl = $this->smarty->createTemplate('eval:{$x = "4"}{$y = "5.5"}{math equation="`ls` x * y" x=$x y=$y}');
|
||||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException PHPUnit_Framework_Error_Warning
|
|
||||||
*/
|
|
||||||
public function testDollarSignsIllegal()
|
public function testDollarSignsIllegal()
|
||||||
{
|
{
|
||||||
|
$this->expectException(PHPUnit\Framework\Error\Warning::class);
|
||||||
$expected = "22.00";
|
$expected = "22.00";
|
||||||
$tpl = $this->smarty->createTemplate('eval:{$x = "4"}{$y = "5.5"}{math equation="$" x=$x y=$y}');
|
$tpl = $this->smarty->createTemplate('eval:{$x = "4"}{$y = "5.5"}{math equation="$" x=$x y=$y}');
|
||||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException PHPUnit_Framework_Error_Warning
|
|
||||||
*/
|
|
||||||
public function testBracketsIllegal()
|
public function testBracketsIllegal()
|
||||||
{
|
{
|
||||||
|
$this->expectException(PHPUnit\Framework\Error\Warning::class);
|
||||||
$expected = "I";
|
$expected = "I";
|
||||||
$tpl = $this->smarty->createTemplate('eval:{$x = "0"}{$y = "1"}{math equation="((y/x).(x))[x]" x=$x y=$y}');
|
$tpl = $this->smarty->createTemplate('eval:{$x = "0"}{$y = "1"}{math equation="((y/x).(x))[x]" x=$x y=$y}');
|
||||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||||
|
|||||||
Reference in New Issue
Block a user