mirror of
https://github.com/smarty-php/smarty.git
synced 2026-08-10 23:41:23 +02:00
Compare commits
38
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f3a11b374 | ||
|
|
b2630915d6 | ||
|
|
273f7e00fe | ||
|
|
ce1ff003d7 | ||
|
|
28519ca00f | ||
|
|
b674cba13d | ||
|
|
a52a5b72ba | ||
|
|
7ad97ad030 | ||
|
|
d8fa8c982f | ||
|
|
de7e15d423 | ||
|
|
1b6919da85 | ||
|
|
457284283a | ||
|
|
9ffca4a093 | ||
|
|
0c8a549603 | ||
|
|
9d4f8309ed | ||
|
|
7c4354e7b8 | ||
|
|
770bc4aae2 | ||
|
|
0ff7ba5ab6 | ||
|
|
3b0fd82849 | ||
|
|
1a68b79b6c | ||
|
|
e3eabe0b96 | ||
|
|
4698dd9fb0 | ||
|
|
039043e5a2 | ||
|
|
9cde36e3bc | ||
|
|
290aee6db3 | ||
|
|
e2485fa45e | ||
|
|
e27da524f7 | ||
|
|
a21f59663c | ||
|
|
3148d406a0 | ||
|
|
4f634c0097 | ||
|
|
c9272058d9 | ||
|
|
e66e293a8a | ||
|
|
74cab5a56b | ||
|
|
8fc66e27a7 | ||
|
|
2543174460 | ||
|
|
288a54f6b0 | ||
|
|
165f1bd4d2 | ||
|
|
6463519a6c |
@@ -6,6 +6,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fixed illegal characters bug in math function security check [#702](https://github.com/smarty-php/smarty/issues/702)
|
||||||
|
|
||||||
|
## [3.1.43] - 2022-01-10
|
||||||
|
|
||||||
|
### Security
|
||||||
|
- Prevent evasion of the `static_classes` security policy. This addresses CVE-2021-21408
|
||||||
|
|
||||||
|
## [3.1.42] - 2022-01-10
|
||||||
|
|
||||||
|
### Security
|
||||||
|
- Prevent arbitrary PHP code execution through maliciously crafted expression for the math function. This addresses CVE-2021-29454
|
||||||
|
|
||||||
|
## [3.1.41] - 2022-01-09
|
||||||
|
|
||||||
|
### Security
|
||||||
|
- Rewrote the mailto function to not use `eval` when encoding with javascript
|
||||||
|
|
||||||
|
## [3.1.40] - 2021-10-13
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- modifier escape now triggers a E_USER_NOTICE when an unsupported escape type is used https://github.com/smarty-php/smarty/pull/649
|
||||||
|
|
||||||
|
### Security
|
||||||
|
- More advanced javascript escaping to handle https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements thanks to m-haritonov
|
||||||
|
|
||||||
|
## [3.1.39] - 2021-02-17
|
||||||
|
|
||||||
|
### Security
|
||||||
|
- Prevent access to `$smarty.template_object` in sandbox mode. This addresses CVE-2021-26119.
|
||||||
|
- Fixed code injection vulnerability by using illegal function names in `{function name='blah'}{/function}`. This addresses CVE-2021-26120.
|
||||||
|
|
||||||
## [3.1.38] - 2021-01-08
|
## [3.1.38] - 2021-01-08
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ Smarty can be run with PHP 5.2 to PHP 7.4.
|
|||||||
|
|
||||||
> Read the NEW_FEATURES and INHERITANCE_RELEASE_NOTES file for recent extensions to Smarty 3.1 functionality
|
> Read the NEW_FEATURES and INHERITANCE_RELEASE_NOTES file for recent extensions to Smarty 3.1 functionality
|
||||||
|
|
||||||
Smarty versions 3.1.11 or later are now on github and can be installed with Composer.
|
Smarty versions 3.1.11 or later are now on GitHub and can be installed with Composer.
|
||||||
|
|
||||||
|
|
||||||
The "smarty/smarty" package will start at libs/.... subfolder.
|
The "smarty/smarty" package will start at libs/.... subfolder.
|
||||||
|
|||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
Smarty currently supports the latest minor version of Smarty 3 and Smarty 4. (Smarty 4 has not been released yet.)
|
||||||
|
|
||||||
|
| Version | Supported |
|
||||||
|
| ------- | ------------------ |
|
||||||
|
| 4.0.x | :white_check_mark: |
|
||||||
|
| 3.1.x | :white_check_mark: |
|
||||||
|
| < 3.1 | :x: |
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
If you have discovered a security issue with Smarty, please contact us at mail [at] simonwisselink.nl. Do not
|
||||||
|
disclose your findings publicly and PLEASE PLEASE do not file an Issue.
|
||||||
|
|
||||||
|
We will try to confirm the vulnerability and develop a fix if appropriate. When we release the fix, we will publish
|
||||||
|
a security release. Please let us know if you want to be credited.
|
||||||
@@ -758,6 +758,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']).';?>');
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.38';
|
const SMARTY_VERSION = '3.1.43';
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -94,22 +94,19 @@ function smarty_function_mailto($params)
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// FIXME: (rodneyrehm) document.write() excues me what? 1998 has passed!
|
|
||||||
if ($encode === 'javascript') {
|
if ($encode === 'javascript') {
|
||||||
$string = 'document.write(\'<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>\');';
|
$string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
|
||||||
$js_encode = '';
|
$js_encode = '';
|
||||||
for ($x = 0, $_length = strlen($string); $x < $_length; $x++) {
|
for ($x = 0, $_length = strlen($string); $x < $_length; $x++) {
|
||||||
$js_encode .= '%' . bin2hex($string[ $x ]);
|
$js_encode .= '%' . bin2hex($string[ $x ]);
|
||||||
}
|
}
|
||||||
return '<script type="text/javascript">eval(unescape(\'' . $js_encode . '\'))</script>';
|
return '<script type="text/javascript">document.write(unescape(\'' . $js_encode . '\'))</script>';
|
||||||
} elseif ($encode === 'javascript_charcode') {
|
} elseif ($encode === 'javascript_charcode') {
|
||||||
$string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
|
$string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
|
||||||
for ($x = 0, $y = strlen($string); $x < $y; $x++) {
|
for ($x = 0, $_length = strlen($string); $x < $_length; $x++) {
|
||||||
$ord[] = ord($string[ $x ]);
|
$ord[] = ord($string[ $x ]);
|
||||||
}
|
}
|
||||||
$_ret = "<script type=\"text/javascript\" language=\"javascript\">\n" . "{document.write(String.fromCharCode(" .
|
return '<script type="text/javascript">document.write(String.fromCharCode(' . implode(',', $ord) . '))</script>';
|
||||||
implode(',', $ord) . "))" . "}\n" . "</script>\n";
|
|
||||||
return $_ret;
|
|
||||||
} elseif ($encode === 'hex') {
|
} elseif ($encode === 'hex') {
|
||||||
preg_match('!^(.*)(\?.*)$!', $address, $match);
|
preg_match('!^(.*)(\?.*)$!', $address, $match);
|
||||||
if (!empty($match[ 2 ])) {
|
if (!empty($match[ 2 ])) {
|
||||||
|
|||||||
@@ -28,7 +28,12 @@ function smarty_function_math($params, $template)
|
|||||||
'int' => true,
|
'int' => true,
|
||||||
'abs' => true,
|
'abs' => true,
|
||||||
'ceil' => true,
|
'ceil' => true,
|
||||||
|
'acos' => true,
|
||||||
|
'acosh' => true,
|
||||||
'cos' => true,
|
'cos' => true,
|
||||||
|
'cosh' => true,
|
||||||
|
'deg2rad' => true,
|
||||||
|
'rad2deg' => true,
|
||||||
'exp' => true,
|
'exp' => true,
|
||||||
'floor' => true,
|
'floor' => true,
|
||||||
'log' => true,
|
'log' => true,
|
||||||
@@ -39,27 +44,51 @@ function smarty_function_math($params, $template)
|
|||||||
'pow' => true,
|
'pow' => true,
|
||||||
'rand' => true,
|
'rand' => true,
|
||||||
'round' => true,
|
'round' => true,
|
||||||
|
'asin' => true,
|
||||||
|
'asinh' => true,
|
||||||
'sin' => true,
|
'sin' => true,
|
||||||
|
'sinh' => true,
|
||||||
'sqrt' => true,
|
'sqrt' => true,
|
||||||
'srand' => true,
|
'srand' => true,
|
||||||
'tan' => true
|
'atan' => true,
|
||||||
|
'atanh' => true,
|
||||||
|
'tan' => true,
|
||||||
|
'tanh' => true
|
||||||
);
|
);
|
||||||
|
|
||||||
// be sure equation parameter is present
|
// be sure equation parameter is present
|
||||||
if (empty($params[ 'equation' ])) {
|
if (empty($params[ 'equation' ])) {
|
||||||
trigger_error("math: missing equation parameter", E_USER_WARNING);
|
trigger_error("math: missing equation parameter", E_USER_WARNING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$equation = $params[ 'equation' ];
|
$equation = $params[ 'equation' ];
|
||||||
|
|
||||||
|
// Remove whitespaces
|
||||||
|
$equation = preg_replace('/\s+/', '', $equation);
|
||||||
|
|
||||||
|
// Adapted from https://www.php.net/manual/en/function.eval.php#107377
|
||||||
|
$number = '(?:\d+(?:[,.]\d+)?|pi|π)'; // What is a number
|
||||||
|
$functionsOrVars = '((?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*))';
|
||||||
|
$operators = '[+\/*\^%-]'; // Allowed math operators
|
||||||
|
$regexp = '/^(('.$number.'|'.$functionsOrVars.'|('.$functionsOrVars.'\s*\((?1)+\)|\((?1)+\)))(?:'.$operators.'(?1))?)+$/';
|
||||||
|
|
||||||
|
if (!preg_match($regexp, $equation)) {
|
||||||
|
trigger_error("math: illegal characters", E_USER_WARNING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// make sure parenthesis are balanced
|
// make sure parenthesis are balanced
|
||||||
if (substr_count($equation, '(') !== substr_count($equation, ')')) {
|
if (substr_count($equation, '(') !== substr_count($equation, ')')) {
|
||||||
trigger_error("math: unbalanced parenthesis", E_USER_WARNING);
|
trigger_error("math: unbalanced parenthesis", E_USER_WARNING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// disallow backticks
|
// disallow backticks
|
||||||
if (strpos($equation, '`') !== false) {
|
if (strpos($equation, '`') !== false) {
|
||||||
trigger_error("math: backtick character not allowed in equation", E_USER_WARNING);
|
trigger_error("math: backtick character not allowed in equation", E_USER_WARNING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// also disallow dollar signs
|
// also disallow dollar signs
|
||||||
if (strpos($equation, '$') !== false) {
|
if (strpos($equation, '$') !== false) {
|
||||||
trigger_error("math: dollar signs not allowed in equation", E_USER_WARNING);
|
trigger_error("math: dollar signs not allowed in equation", E_USER_WARNING);
|
||||||
@@ -96,6 +125,7 @@ function smarty_function_math($params, $template)
|
|||||||
}
|
}
|
||||||
$smarty_math_result = null;
|
$smarty_math_result = null;
|
||||||
eval("\$smarty_math_result = " . $equation . ";");
|
eval("\$smarty_math_result = " . $equation . ";");
|
||||||
|
|
||||||
if (empty($params[ 'format' ])) {
|
if (empty($params[ 'format' ])) {
|
||||||
if (empty($params[ 'assign' ])) {
|
if (empty($params[ 'assign' ])) {
|
||||||
return $smarty_math_result;
|
return $smarty_math_result;
|
||||||
|
|||||||
@@ -184,7 +184,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
|||||||
'"' => '\\"',
|
'"' => '\\"',
|
||||||
"\r" => '\\r',
|
"\r" => '\\r',
|
||||||
"\n" => '\\n',
|
"\n" => '\\n',
|
||||||
'</' => '<\/'
|
'</' => '<\/',
|
||||||
|
// see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
|
||||||
|
'<!--' => '<\!--',
|
||||||
|
'<s' => '<\s',
|
||||||
|
'<S' => '<\S'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
case 'mail':
|
case 'mail':
|
||||||
@@ -250,6 +254,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
|||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
default:
|
default:
|
||||||
|
trigger_error("escape: unsupported type: $esc_type - returning unmodified string", E_USER_NOTICE);
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,9 +89,10 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
|
|||||||
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[ 0 ] . ')';
|
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[ 0 ] . ')';
|
||||||
case 'javascript':
|
case 'javascript':
|
||||||
// escape quotes and backslashes, newlines, etc.
|
// escape quotes and backslashes, newlines, etc.
|
||||||
|
// see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
|
||||||
return 'strtr(' .
|
return 'strtr(' .
|
||||||
$params[ 0 ] .
|
$params[ 0 ] .
|
||||||
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))';
|
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S" ))';
|
||||||
}
|
}
|
||||||
} catch (SmartyException $e) {
|
} catch (SmartyException $e) {
|
||||||
// pass through to regular plugin fallback
|
// pass through to regular plugin fallback
|
||||||
|
|||||||
@@ -58,6 +58,11 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
|||||||
}
|
}
|
||||||
unset($_attr[ 'nocache' ]);
|
unset($_attr[ 'nocache' ]);
|
||||||
$_name = trim($_attr[ 'name' ], '\'"');
|
$_name = trim($_attr[ 'name' ], '\'"');
|
||||||
|
|
||||||
|
if (!preg_match('/^[a-zA-Z0-9_\x80-\xff]+$/', $_name)) {
|
||||||
|
$compiler->trigger_template_error("Function name contains invalid characters: {$_name}", null, true);
|
||||||
|
}
|
||||||
|
|
||||||
$compiler->parent_compiler->tpl_function[ $_name ] = array();
|
$compiler->parent_compiler->tpl_function[ $_name ] = array();
|
||||||
$save = array(
|
$save = array(
|
||||||
$_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
|
$_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
|
||||||
|
|||||||
@@ -81,6 +81,10 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
|
|||||||
case 'template':
|
case 'template':
|
||||||
return 'basename($_smarty_tpl->source->filepath)';
|
return 'basename($_smarty_tpl->source->filepath)';
|
||||||
case 'template_object':
|
case 'template_object':
|
||||||
|
if (isset($compiler->smarty->security_policy)) {
|
||||||
|
$compiler->trigger_template_error("(secure mode) template_object not permitted");
|
||||||
|
break;
|
||||||
|
}
|
||||||
return '$_smarty_tpl';
|
return '$_smarty_tpl';
|
||||||
case 'current_dir':
|
case 'current_dir':
|
||||||
return 'dirname($_smarty_tpl->source->filepath)';
|
return 'dirname($_smarty_tpl->source->filepath)';
|
||||||
|
|||||||
@@ -2837,6 +2837,10 @@ class Smarty_Internal_Templateparser
|
|||||||
// line 765 "../smarty/lexer/smarty_internal_templateparser.y"
|
// line 765 "../smarty/lexer/smarty_internal_templateparser.y"
|
||||||
public function yy_r95()
|
public function yy_r95()
|
||||||
{
|
{
|
||||||
|
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->appendPrefixCode("<?php {$prefixVar} = " .
|
||||||
|
|||||||
+10
-3
@@ -1,6 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
printf 'Creating release %s\n' "$1"
|
if [[ "$1" =~ ^3\.[0-9\.-rc]+$ ]]; then
|
||||||
|
printf 'Creating release %s\n' "$1"
|
||||||
|
else
|
||||||
|
echo "Invalid version number: $1. This script can only make v3.x.x releases."
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
git checkout -b "release/$1"
|
git checkout -b "release/$1"
|
||||||
sed -i "s/## \\[Unreleased\\]/## \\[Unreleased\\]\\n\\n## \\[$1\\] - $(date +%Y-%m-%d)/" CHANGELOG.md
|
sed -i "s/## \\[Unreleased\\]/## \\[Unreleased\\]\\n\\n## \\[$1\\] - $(date +%Y-%m-%d)/" CHANGELOG.md
|
||||||
@@ -9,11 +14,13 @@ sed -i "s/const SMARTY_VERSION = '[^']\+';/const SMARTY_VERSION = '$1';/" libs/S
|
|||||||
git add CHANGELOG.md libs/Smarty.class.php
|
git add CHANGELOG.md libs/Smarty.class.php
|
||||||
git commit -m "version bump"
|
git commit -m "version bump"
|
||||||
|
|
||||||
git checkout master
|
git checkout support/3.1
|
||||||
git pull
|
git pull
|
||||||
git merge --no-ff "release/$1"
|
git merge --no-ff "release/$1"
|
||||||
git branch -d "release/$1"
|
git branch -d "release/$1"
|
||||||
git tag -a "v$1" -m "Release $1"
|
git tag -a "v$1" -m "Release $1"
|
||||||
git push --follow-tags
|
|
||||||
|
|
||||||
printf 'Done creating release %s\n' "$1"
|
printf 'Done creating release %s\n' "$1"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
printf 'Run `git push --follow-tags origin` to publish it.\n'
|
||||||
|
|||||||
@@ -298,18 +298,38 @@ 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
|
||||||
* @expectedException SmartyException
|
* @expectedException SmartyException
|
||||||
* @expectedExceptionMessage access to static class 'mysecuritystaticclass' not allowed by security setting
|
* @expectedExceptionMessage access to static class 'mysecuritystaticclass' not allowed by security setting
|
||||||
* @runInSeparateProcess
|
*/
|
||||||
* @preserveGlobalState disabled
|
public function testNotTrustedStaticClass()
|
||||||
*/
|
{
|
||||||
public function testNotTrustedStaticClass()
|
$this->smarty->security_policy->static_classes = array('null');
|
||||||
{
|
$this->smarty->fetch('string:{mysecuritystaticclass::square(5)}');
|
||||||
$this->smarty->security_policy->static_classes = array('null');
|
}
|
||||||
$this->smarty->fetch('string:{mysecuritystaticclass::square(5)}');
|
|
||||||
}
|
/**
|
||||||
|
* test not trusted PHP function
|
||||||
|
* @expectedException SmartyException
|
||||||
|
* @expectedExceptionMessage dynamic static class not allowed by security setting
|
||||||
|
*/
|
||||||
|
public function testNotTrustedStaticClassEval()
|
||||||
|
{
|
||||||
|
$this->smarty->security_policy->static_classes = array('null');
|
||||||
|
$this->smarty->fetch('string:{$test = "mysecuritystaticclass"}{$test::square(5)}');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test not trusted PHP function
|
||||||
|
* @expectedException SmartyException
|
||||||
|
* @expectedExceptionMessage dynamic static class not allowed by security setting
|
||||||
|
*/
|
||||||
|
public function testNotTrustedStaticClassSmartyVar()
|
||||||
|
{
|
||||||
|
$this->smarty->security_policy->static_classes = array('null');
|
||||||
|
$this->smarty->fetch('string:{$smarty.template_object::square(5)}');
|
||||||
|
}
|
||||||
|
|
||||||
public function testChangedTrustedDirectory()
|
public function testChangedTrustedDirectory()
|
||||||
{
|
{
|
||||||
@@ -382,6 +402,15 @@ class SecurityTest extends PHPUnit_Smarty
|
|||||||
$this->smarty->security_policy->trusted_uri = array();
|
$this->smarty->security_policy->trusted_uri = array();
|
||||||
$this->assertContains('<title>Preface | Smarty</title>', $this->smarty->fetch('string:{fetch file="https://www.smarty.net/docs/en/preface.tpl"}'));
|
$this->assertContains('<title>Preface | Smarty</title>', $this->smarty->fetch('string:{fetch file="https://www.smarty.net/docs/en/preface.tpl"}'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In security mode, accessing $smarty.template_object should be illegal.
|
||||||
|
* @expectedException SmartyCompilerException
|
||||||
|
*/
|
||||||
|
public function testSmartyTemplateObject() {
|
||||||
|
$this->smarty->display('string:{$smarty.template_object}');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class mysecuritystaticclass
|
class mysecuritystaticclass
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class PluginFunctionMailtoTest extends PHPUnit_Smarty
|
|||||||
|
|
||||||
public function testEncodeJavascript()
|
public function testEncodeJavascript()
|
||||||
{
|
{
|
||||||
$result = '<script type="text/javascript">eval(unescape(\'%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%22%20%3e%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%3c%2f%61%3e%27%29%3b\'))</script>';
|
$result = '<script type="text/javascript">document.write(unescape(\'%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%22%20%3e%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%3c%2f%61%3e\'))</script>';
|
||||||
$tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" encode="javascript"}');
|
$tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" encode="javascript"}');
|
||||||
$this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl));
|
$this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ class PluginFunctionMailtoTest extends PHPUnit_Smarty
|
|||||||
public function testEncodeJavascriptWithoutMbstring()
|
public function testEncodeJavascriptWithoutMbstring()
|
||||||
{
|
{
|
||||||
Smarty::$_MBSTRING = false;
|
Smarty::$_MBSTRING = false;
|
||||||
$result = '<script type="text/javascript">eval(unescape(\'%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%22%20%3e%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%3c%2f%61%3e%27%29%3b\'))</script>';
|
$result = '<script type="text/javascript">document.write(unescape(\'%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%22%20%3e%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%3c%2f%61%3e\'))</script>';
|
||||||
$tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" encode="javascript"}');
|
$tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" encode="javascript"}');
|
||||||
$this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl));
|
$this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl));
|
||||||
Smarty::$_MBSTRING = true;
|
Smarty::$_MBSTRING = true;
|
||||||
@@ -70,7 +70,7 @@ class PluginFunctionMailtoTest extends PHPUnit_Smarty
|
|||||||
|
|
||||||
public function testEncodeJavascriptCharcode()
|
public function testEncodeJavascriptCharcode()
|
||||||
{
|
{
|
||||||
$result = "<script type=\"text/javascript\" language=\"javascript\">\n{document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,109,101,64,101,120,97,109,112,108,101,46,99,111,109,34,32,62,109,101,64,101,120,97,109,112,108,101,46,99,111,109,60,47,97,62))}\n</script>\n";
|
$result = '<script type="text/javascript">document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,109,101,64,101,120,97,109,112,108,101,46,99,111,109,34,32,62,109,101,64,101,120,97,109,112,108,101,46,99,111,109,60,47,97,62))</script>';
|
||||||
$tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" encode="javascript_charcode"}');
|
$tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" encode="javascript_charcode"}');
|
||||||
$this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl));
|
$this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ class PluginFunctionMailtoTest extends PHPUnit_Smarty
|
|||||||
public function testEncodeJavascriptCharcodeWithoutMbstring()
|
public function testEncodeJavascriptCharcodeWithoutMbstring()
|
||||||
{
|
{
|
||||||
Smarty::$_MBSTRING = false;
|
Smarty::$_MBSTRING = false;
|
||||||
$result = "<script type=\"text/javascript\" language=\"javascript\">\n{document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,109,101,64,101,120,97,109,112,108,101,46,99,111,109,34,32,62,109,101,64,101,120,97,109,112,108,101,46,99,111,109,60,47,97,62))}\n</script>\n";
|
$result = '<script type="text/javascript">document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,109,101,64,101,120,97,109,112,108,101,46,99,111,109,34,32,62,109,101,64,101,120,97,109,112,108,101,46,99,111,109,60,47,97,62))</script>';
|
||||||
$tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" encode="javascript_charcode"}');
|
$tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" encode="javascript_charcode"}');
|
||||||
$this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl));
|
$this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl));
|
||||||
Smarty::$_MBSTRING = true;
|
Smarty::$_MBSTRING = true;
|
||||||
|
|||||||
@@ -431,5 +431,14 @@ class CompileFunctionTest extends PHPUnit_Smarty
|
|||||||
array("{function name=simple}A{\$foo}\nC{/function}{call name='simple'}", "Abar\nC", 'T14', $i++),
|
array("{function name=simple}A{\$foo}\nC{/function}{call name='simple'}", "Abar\nC", 'T14', $i++),
|
||||||
array("{function name=simple}A\n{\$foo}\nC{/function}{call name='simple'}", "A\nbar\nC", 'T15', $i++),
|
array("{function name=simple}A\n{\$foo}\nC{/function}{call name='simple'}", "A\nbar\nC", 'T15', $i++),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test handling of function names that are a security risk
|
||||||
|
* @expectedException SmartyCompilerException
|
||||||
|
*/
|
||||||
|
public function testIllegalFunctionName() {
|
||||||
|
$this->smarty->fetch('string:{function name=\'rce(){};echo "hi";function \'}{/function}');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,14 @@ class MathTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMultipleOperators()
|
||||||
|
{
|
||||||
|
$this->smarty->disableSecurity();
|
||||||
|
$expected = "2 -- 2";
|
||||||
|
$tpl = $this->smarty->createTemplate('eval:{$x = 5}{$y = 4}{math equation="x - y + 1" x=$x y=$y} -- {math equation="5 - 4 + 1"}');
|
||||||
|
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||||
|
}
|
||||||
|
|
||||||
public function testSyntaxSin()
|
public function testSyntaxSin()
|
||||||
{
|
{
|
||||||
$this->smarty->disableSecurity();
|
$this->smarty->disableSecurity();
|
||||||
@@ -107,4 +115,35 @@ class MathTest extends PHPUnit_Smarty
|
|||||||
$tpl = $this->smarty->createTemplate('eval:{$x = "4"}{$y = "5.5"}{math equation="x * y" x=$x y=$y format="%0.2f"} -- {math equation="20.5 / 5" format="%0.2f"}');
|
$tpl = $this->smarty->createTemplate('eval:{$x = "4"}{$y = "5.5"}{math equation="x * y" x=$x y=$y format="%0.2f"} -- {math equation="20.5 / 5" format="%0.2f"}');
|
||||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException PHPUnit_Framework_Error_Warning
|
||||||
|
*/
|
||||||
|
public function testBackticksIllegal()
|
||||||
|
{
|
||||||
|
$expected = "22.00";
|
||||||
|
$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));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException PHPUnit_Framework_Error_Warning
|
||||||
|
*/
|
||||||
|
public function testDollarSignsIllegal()
|
||||||
|
{
|
||||||
|
$expected = "22.00";
|
||||||
|
$tpl = $this->smarty->createTemplate('eval:{$x = "4"}{$y = "5.5"}{math equation="$" x=$x y=$y}');
|
||||||
|
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException PHPUnit_Framework_Error_Warning
|
||||||
|
*/
|
||||||
|
public function testBracketsIllegal()
|
||||||
|
{
|
||||||
|
$expected = "I";
|
||||||
|
$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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user