Skip to content

Commit 732f671

Browse files
committed
Fix entry creation by restoring smarty access to PHP modifiers
Also removes unused code from the smarty security wrapper
1 parent 36696bd commit 732f671

File tree

2 files changed

+55
-32
lines changed

2 files changed

+55
-32
lines changed

include/functions_smarty.inc.php

+55-10
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,49 @@ function serendipity_smarty_count($value, $mode = COUNT_NORMAL) {
919919
return count($value, $mode);
920920
}
921921

922+
function serendipity_smarty_sizeof($value, $mode = COUNT_NORMAL) {
923+
return count($value, $mode);
924+
}
925+
926+
function serendipity_smarty_isset($var, $vars) {
927+
return isset($var, $vars);
928+
}
929+
930+
function serendipity_smarty_empty($var) {
931+
return empty($var);
932+
}
933+
934+
function serendipity_smarty_in_array(mixed $needle, array $haystack, bool $strict = false) {
935+
return in_array($needle, $haystack, $strict);
936+
}
937+
938+
function serendipity_smarty_is_array($var) {
939+
return is_array($var);
940+
}
941+
942+
function serendipity_smarty_time() {
943+
return time();
944+
}
945+
946+
function serendipity_smarty_nl2br(string $string, bool $use_xhtml = true) {
947+
return nl2br($string, $use_xhtml);
948+
}
949+
950+
function serendipity_smarty_class_exists(string $class, bool $autoload = true) {
951+
return class_exists($class, $autoload);
952+
}
953+
954+
function serendipity_smarty_rand($min = 0, $max = null) {
955+
return rand($min, $max ?? getrandmax());
956+
}
957+
958+
function serendipity_smarty_str_repeat($string, $times) {
959+
return str_repeat($string, $times);
960+
}
961+
962+
963+
964+
922965
/**
923966
* Initialize the Smarty framework for use in Serendipity
924967
*
@@ -989,16 +1032,6 @@ function serendipity_smarty_init($vars = array()) {
9891032
// enable security policy by instance of the Smarty_Security class
9901033
$serendipity['smarty']->enableSecurity('Serendipity_Smarty_Security_Policy');
9911034

992-
// debugging...
993-
#echo '<pre>';print_r($serendipity['smarty']);echo '</pre>';#exit;
994-
#$serendipity['smarty']->testInstall();exit;
995-
// extreme debugging with undocumented internal flag which enables a trace output from the parser during debugging
996-
#$serendipity['smarty']->_parserdebug = true; // be careful!
997-
998-
/**
999-
* ToDo: Check for possible API changes in Smarty 3.2 [smarty_modifier_foobar, --> [smarty_modifier_foobar, smarty_function_foobar, smarty_block_foobar] (in class)]
1000-
* smarty_modifier_foobar(Smarty $smarty, $string, ...) vs. smarty_modifier_foobar($string, ...)
1001-
**/
10021035
$serendipity['smarty']->registerPlugin('modifier', 'makeFilename', 'serendipity_makeFilename');
10031036
$serendipity['smarty']->registerPlugin('modifier', 'xhtml_target', 'serendipity_xhtml_target');
10041037
$serendipity['smarty']->registerPlugin('modifier', 'emptyPrefix', 'serendipity_emptyPrefix');
@@ -1030,6 +1063,18 @@ function serendipity_smarty_init($vars = array()) {
10301063
$serendipity['smarty']->registerPlugin('function', 'serendipity_getConfigVar', 'serendipity_smarty_getConfigVar');
10311064
$serendipity['smarty']->registerPlugin('function', 'serendipity_setFormToken', 'serendipity_smarty_setFormToken');
10321065

1066+
1067+
// Backwards compatibility fix for Smarty v5: Allow these these php functions and modifiers
1068+
$php_functions = array('isset', 'empty', 'sizeof', 'count', 'in_array', 'is_array', 'time', 'nl2br');
1069+
$php_modifiers = array('rand', 'str_repeat', 'nl2br', 'class_exists');
1070+
1071+
foreach ($php_functions as $php_function) {
1072+
$serendipity['smarty']->registerPlugin('function', $php_function, "serendipity_smarty_$php_function");
1073+
}
1074+
foreach ($php_modifiers as $php_modifier) {
1075+
$serendipity['smarty']->registerPlugin('modifier', $php_modifier, "serendipity_smarty_$php_modifier");
1076+
}
1077+
10331078
$serendipity['smarty']->registerFilter('pre', 'serendipity_replaceSmartyVars');
10341079

10351080
}

include/serendipity_smarty_class.inc.php

-22
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,6 @@
1212
// Create a wrapper class extended from Smarty_Security - which allows access to S9Y-plugin and S9Y-template dirs
1313
class Serendipity_Smarty_Security_Policy extends \Smarty\Security
1414
{
15-
// these are the allowed functions only. - default as is
16-
public $php_functions = array('isset', 'empty', 'sizeof', 'count', 'in_array', 'is_array', 'time', 'nl2br', 'class_exists');
17-
// to disable all PHP functions
18-
#public $php_functions = null;
19-
20-
// set allowed modifiers only. (default = array( 'escape', 'count' );)
21-
public $php_modifiers = array('escape', 'rand', 'str_repeat', 'nl2br');
22-
23-
public $allow_constants = true;
24-
25-
public $allow_super_globals = true;
26-
27-
// array of template directories that are considered secure. No need, as ...TemplateDir concidered secure implicitly. (unproofed)
28-
public $secure_dir = array(S9Y_TEMPLATE_SECUREDIR); // do we need this then?
29-
30-
// actually no need, as template dirs are explicit defined as trusted_dirs. (unproofed)
31-
public $trusted_dir = array(S9Y_TEMPLATE_USERDEFAULT, S9Y_TEMPLATE_USERDEFAULT_BACKEND, S9Y_TEMPLATE_FALLBACK); // do we need this then?
32-
33-
#public $modifiers = array(); // can be omitted, when all allowed
34-
35-
// to test this - overwrites Serendipity_Smarty::default_modifiers and Serendipity_Smarty_Security_Policy::php_modifiers - modifier 'escape' not allowed by security setting
36-
#public $allowed_modifiers = array('escape:"htmlall"');
3715

3816
// This allows the fetch() and include calls to pull .tpl files from any directory,
3917
// so that symlinked plugin directories outside the s9y path can be included properly.

0 commit comments

Comments
 (0)