| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * Smarty plugin | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * @subpackage Security | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @author     Uwe Tews | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-01 18:10:48 +00:00
										 |  |  | /* | 
					
						
							|  |  |  |  * FIXME: Smarty_Security API | 
					
						
							|  |  |  |  *      - getter and setter instead of public properties would allow cultivating an internal cache properly | 
					
						
							|  |  |  |  *      - current implementation of isTrustedResourceDir() assumes that Smarty::$template_dir and Smarty::$config_dir are immutable | 
					
						
							|  |  |  |  *        the cache is killed every time either of the variables change. That means that two distinct Smarty objects with differing | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |  *        $template_dir or $config_dir should NOT share the same Smarty_Security instance, | 
					
						
							|  |  |  |  *        as this would lead to (severe) performance penalty! how should this be handled? | 
					
						
							| 
									
										
										
										
											2011-10-01 18:10:48 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * This class does contain the security settings | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | class Smarty_Security | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      * This determines how Smarty handles "<?php ... ?>" tags in templates. | 
					
						
							|  |  |  |      * possible values: | 
					
						
							|  |  |  |      * <ul> | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      *   <li>Smarty::PHP_PASSTHRU -> echo PHP tags as they are</li> | 
					
						
							|  |  |  |      *   <li>Smarty::PHP_QUOTE    -> escape tags as entities</li> | 
					
						
							|  |  |  |      *   <li>Smarty::PHP_REMOVE   -> remove php tags</li> | 
					
						
							|  |  |  |      *   <li>Smarty::PHP_ALLOW    -> execute php tags</li> | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      * </ul> | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @var integer | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     public $php_handling = Smarty::PHP_PASSTHRU; | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      * This is the list of template directories that are considered secure. | 
					
						
							|  |  |  |      * $template_dir is in this list implicitly. | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     public $secure_dir = array(); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      * This is an array of directories where trusted php scripts reside. | 
					
						
							|  |  |  |      * {@link $security} is disabled during their inclusion/execution. | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     public $trusted_dir = array(); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 22:21:49 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * List of regular expressions (PCRE) that include trusted URIs | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $trusted_uri = array(); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-28 03:58:08 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * List of trusted constants names | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $trusted_constants = array(); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-24 18:01:03 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      * This is an array of trusted static classes. | 
					
						
							|  |  |  |      * If empty access to all static classes is allowed. | 
					
						
							|  |  |  |      * If set to 'none' none is allowed. | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @var array | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-02-24 18:01:03 +00:00
										 |  |  |     public $static_classes = array(); | 
					
						
							| 
									
										
										
										
											2015-01-22 03:53:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * This is an nested array of trusted classes and static methods. | 
					
						
							|  |  |  |      * If empty access to all static classes and methods is allowed. | 
					
						
							|  |  |  |      * Format: | 
					
						
							|  |  |  |      * array ( | 
					
						
							|  |  |  |      *         'class_1' => array('method_1', 'method_2'), // allowed methods listed
 | 
					
						
							|  |  |  |      *         'class_2' => array(),                       // all methods of class allowed
 | 
					
						
							|  |  |  |      *       ) | 
					
						
							|  |  |  |      * If set to null none is allowed. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $trusted_static_methods = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * This is an array of trusted static properties. | 
					
						
							|  |  |  |      * If empty access to all static classes and properties is allowed. | 
					
						
							|  |  |  |      * Format: | 
					
						
							|  |  |  |      * array ( | 
					
						
							|  |  |  |      *         'class_1' => array('prop_1', 'prop_2'), // allowed properties listed
 | 
					
						
							|  |  |  |      *         'class_2' => array(),                   // all properties of class allowed
 | 
					
						
							|  |  |  |      *       ) | 
					
						
							|  |  |  |      * If set to null none is allowed. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $trusted_static_properties = array(); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      * This is an array of trusted PHP functions. | 
					
						
							|  |  |  |      * If empty all functions are allowed. | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      * To disable all PHP functions set $php_functions = null. | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @var array | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  |     public $php_functions = array('isset', 'empty', 'count', 'sizeof', 'in_array', 'is_array', 'time',); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2013-06-17 12:34:10 +00:00
										 |  |  |      * This is an array of trusted PHP modifiers. | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      * If empty all modifiers are allowed. | 
					
						
							| 
									
										
										
										
											2014-10-01 17:15:24 +00:00
										 |  |  |      * To disable all modifier set $php_modifiers = null. | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @var array | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  |     public $php_modifiers = array('escape', 'count', 'nl2br',); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * This is an array of allowed tags. | 
					
						
							|  |  |  |      * If empty no restriction by allowed_tags. | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $allowed_tags = array(); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * This is an array of disabled tags. | 
					
						
							|  |  |  |      * If empty no restriction by disabled_tags. | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $disabled_tags = array(); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * This is an array of allowed modifier plugins. | 
					
						
							|  |  |  |      * If empty no restriction by allowed_modifiers. | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $allowed_modifiers = array(); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * This is an array of disabled modifier plugins. | 
					
						
							|  |  |  |      * If empty no restriction by disabled_modifiers. | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $disabled_modifiers = array(); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-29 21:59:23 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * This is an array of disabled special $smarty variables. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $disabled_special_smarty_vars = array(); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      * This is an array of trusted streams. | 
					
						
							|  |  |  |      * If empty all streams are allowed. | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      * To disable all streams set $streams = null. | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @var array | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     public $streams = array('file'); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      * + flag if constants can be accessed from template | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @var boolean | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     public $allow_constants = true; | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      * + flag if super globals can be accessed from template | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @var boolean | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2009-12-04 15:44:47 +00:00
										 |  |  |     public $allow_super_globals = true; | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 12:57:43 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * max template nesting level | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var int | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $max_template_nesting = 0; | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 12:57:43 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * current template nesting level | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var int | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private $_current_template_nesting = 0; | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-04 15:44:47 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * Cache for $resource_dir lookup | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-10-01 18:10:48 +00:00
										 |  |  |      * @var array | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-06-28 02:37:41 +02:00
										 |  |  |     protected $_resource_dir = array(); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * Cache for $template_dir lookup | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-10-01 18:10:48 +00:00
										 |  |  |      * @var array | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-06-28 02:37:41 +02:00
										 |  |  |     protected $_template_dir = array(); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * Cache for $config_dir lookup | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-10-01 18:10:48 +00:00
										 |  |  |      * @var array | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-06-28 02:37:41 +02:00
										 |  |  |     protected $_config_dir = array(); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * Cache for $secure_dir lookup | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-10-01 18:10:48 +00:00
										 |  |  |      * @var array | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-06-28 02:37:41 +02:00
										 |  |  |     protected $_secure_dir = array(); | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * Cache for $php_resource_dir lookup | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-10-01 18:10:48 +00:00
										 |  |  |      * @var array | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      */ | 
					
						
							|  |  |  |     protected $_php_resource_dir = null; | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * Cache for $trusted_dir lookup | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-10-01 18:10:48 +00:00
										 |  |  |      * @var array | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      */ | 
					
						
							|  |  |  |     protected $_trusted_dir = null; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-07 17:55:45 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |      * Cache for include path status | 
					
						
							| 
									
										
										
										
											2015-07-07 17:55:45 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |      * @var bool | 
					
						
							| 
									
										
										
										
											2015-07-07 17:55:45 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |     protected $_include_path_status = false; | 
					
						
							| 
									
										
										
										
											2015-07-07 17:55:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Cache for $_include_array lookup | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected $_include_dir = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-01 18:10:48 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param Smarty $smarty | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function __construct($smarty) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->smarty = $smarty; | 
					
						
							| 
									
										
										
										
											2016-07-12 02:30:14 +02:00
										 |  |  |         $this->smarty->_cache[ 'template_dir_new' ] = true; | 
					
						
							|  |  |  |         $this->smarty->_cache[ 'config_dir_new' ] = true; | 
					
						
							| 
									
										
										
										
											2011-10-01 18:10:48 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Check if PHP function is trusted. | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * @param  string $function_name | 
					
						
							|  |  |  |      * @param  object $compiler compiler object | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @return boolean                 true if function is trusted | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @throws SmartyCompilerException if php function is not trusted | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     public function isTrustedPhpFunction($function_name, $compiler) | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |         if (isset($this->php_functions) && | 
					
						
							|  |  |  |             (empty($this->php_functions) || in_array($function_name, $this->php_functions)) | 
					
						
							|  |  |  |         ) { | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |             return true; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $compiler->trigger_template_error("PHP function '{$function_name}' not allowed by security setting"); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         return false; // should not, but who knows what happens to the compiler in the future?
 | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Check if static class is trusted. | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * @param  string $class_name | 
					
						
							|  |  |  |      * @param  object $compiler compiler object | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @return boolean                 true if class is trusted | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @throws SmartyCompilerException if static class is not trusted | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     public function isTrustedStaticClass($class_name, $compiler) | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |         if (isset($this->static_classes) && | 
					
						
							|  |  |  |             (empty($this->static_classes) || in_array($class_name, $this->static_classes)) | 
					
						
							|  |  |  |         ) { | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |             return true; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $compiler->trigger_template_error("access to static class '{$class_name}' not allowed by security setting"); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         return false; // should not, but who knows what happens to the compiler in the future?
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 03:53:01 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Check if static class method/property is trusted. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string $class_name | 
					
						
							|  |  |  |      * @param  string $params | 
					
						
							|  |  |  |      * @param  object $compiler compiler object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return boolean                 true if class method is trusted | 
					
						
							|  |  |  |      * @throws SmartyCompilerException if static class method is not trusted | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function isTrustedStaticClassAccess($class_name, $params, $compiler) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         if (!isset($params[ 2 ])) { | 
					
						
							| 
									
										
										
										
											2015-01-22 03:53:01 +01:00
										 |  |  |             // fall back
 | 
					
						
							|  |  |  |             return $this->isTrustedStaticClass($class_name, $compiler); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |         if ($params[ 2 ] === 'method') { | 
					
						
							| 
									
										
										
										
											2015-01-22 03:53:01 +01:00
										 |  |  |             $allowed = $this->trusted_static_methods; | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             $name = substr($params[ 0 ], 0, strpos($params[ 0 ], '(')); | 
					
						
							| 
									
										
										
										
											2015-01-22 03:53:01 +01:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             $allowed = $this->trusted_static_properties; | 
					
						
							|  |  |  |             // strip '$'
 | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             $name = substr($params[ 0 ], 1); | 
					
						
							| 
									
										
										
										
											2015-01-22 03:53:01 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (isset($allowed)) { | 
					
						
							|  |  |  |             if (empty($allowed)) { | 
					
						
							|  |  |  |                 // fall back
 | 
					
						
							|  |  |  |                 return $this->isTrustedStaticClass($class_name, $compiler); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             if (isset($allowed[ $class_name ]) && | 
					
						
							|  |  |  |                 (empty($allowed[ $class_name ]) || in_array($name, $allowed[ $class_name ])) | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |             ) { | 
					
						
							| 
									
										
										
										
											2015-01-22 03:53:01 +01:00
										 |  |  |                 return true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $compiler->trigger_template_error("access to static class '{$class_name}' {$params[2]} '{$name}' not allowed by security setting"); | 
					
						
							|  |  |  |         return false; // should not, but who knows what happens to the compiler in the future?
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Check if PHP modifier is trusted. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * @param  string $modifier_name | 
					
						
							|  |  |  |      * @param  object $compiler compiler object | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @return boolean                 true if modifier is trusted | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @throws SmartyCompilerException if modifier is not trusted | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     public function isTrustedPhpModifier($modifier_name, $compiler) | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |         if (isset($this->php_modifiers) && | 
					
						
							|  |  |  |             (empty($this->php_modifiers) || in_array($modifier_name, $this->php_modifiers)) | 
					
						
							|  |  |  |         ) { | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |             return true; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $compiler->trigger_template_error("modifier '{$modifier_name}' not allowed by security setting"); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         return false; // should not, but who knows what happens to the compiler in the future?
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Check if tag is trusted. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * @param  string $tag_name | 
					
						
							|  |  |  |      * @param  object $compiler compiler object | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @return boolean                 true if tag is trusted | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @throws SmartyCompilerException if modifier is not trusted | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function isTrustedTag($tag_name, $compiler) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // check for internal always required tags
 | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         if (in_array($tag_name, | 
					
						
							|  |  |  |                      array('assign', 'call', 'private_filter', 'private_block_plugin', 'private_function_plugin', | 
					
						
							|  |  |  |                            'private_object_block_function', 'private_object_function', 'private_registered_function', | 
					
						
							|  |  |  |                            'private_registered_block', 'private_special_variable', 'private_print_expression', | 
					
						
							|  |  |  |                            'private_modifier'))) { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // check security settings
 | 
					
						
							|  |  |  |         if (empty($this->allowed_tags)) { | 
					
						
							|  |  |  |             if (empty($this->disabled_tags) || !in_array($tag_name, $this->disabled_tags)) { | 
					
						
							|  |  |  |                 return true; | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |                 $compiler->trigger_template_error("tag '{$tag_name}' disabled by security setting", null, true); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |         } elseif (in_array($tag_name, $this->allowed_tags) && !in_array($tag_name, $this->disabled_tags)) { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             return true; | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |             $compiler->trigger_template_error("tag '{$tag_name}' not allowed by security setting", null, true); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         return false; // should not, but who knows what happens to the compiler in the future?
 | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 03:53:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-29 21:59:23 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Check if special $smarty variable is trusted. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string $var_name | 
					
						
							|  |  |  |      * @param  object $compiler compiler object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return boolean                 true if tag is trusted | 
					
						
							|  |  |  |      * @throws SmartyCompilerException if modifier is not trusted | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function isTrustedSpecialSmartyVar($var_name, $compiler) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (!in_array($var_name, $this->disabled_special_smarty_vars)) { | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             $compiler->trigger_template_error("special variable '\$smarty.{$var_name}' not allowed by security setting", | 
					
						
							|  |  |  |                                               null, true); | 
					
						
							| 
									
										
										
										
											2014-12-29 21:59:23 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return false; // should not, but who knows what happens to the compiler in the future?
 | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * Check if modifier plugin is trusted. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * @param  string $modifier_name | 
					
						
							|  |  |  |      * @param  object $compiler compiler object | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @return boolean                 true if tag is trusted | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @throws SmartyCompilerException if modifier is not trusted | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function isTrustedModifier($modifier_name, $compiler) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // check for internal always allowed modifier
 | 
					
						
							|  |  |  |         if (in_array($modifier_name, array('default'))) { | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // check security settings
 | 
					
						
							|  |  |  |         if (empty($this->allowed_modifiers)) { | 
					
						
							|  |  |  |             if (empty($this->disabled_modifiers) || !in_array($modifier_name, $this->disabled_modifiers)) { | 
					
						
							|  |  |  |                 return true; | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                 $compiler->trigger_template_error("modifier '{$modifier_name}' disabled by security setting", null, | 
					
						
							|  |  |  |                                                   true); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |         } elseif (in_array($modifier_name, $this->allowed_modifiers) && | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                   !in_array($modifier_name, $this->disabled_modifiers) | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |         ) { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             return true; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             $compiler->trigger_template_error("modifier '{$modifier_name}' not allowed by security setting", null, | 
					
						
							|  |  |  |                                               true); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         return false; // should not, but who knows what happens to the compiler in the future?
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-28 03:58:08 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Check if constants are enabled or trusted | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  |      * @param  string $const    constant name | 
					
						
							| 
									
										
										
										
											2015-03-28 03:58:08 +01:00
										 |  |  |      * @param  object $compiler compiler object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function isTrustedConstant($const, $compiler) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (in_array($const, array('true', 'false', 'null'))) { | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!empty($this->trusted_constants)) { | 
					
						
							| 
									
										
										
										
											2016-09-07 00:15:44 +02:00
										 |  |  |             if (!in_array(strtolower($const), $this->trusted_constants)) { | 
					
						
							| 
									
										
										
										
											2015-03-28 03:58:08 +01:00
										 |  |  |                 $compiler->trigger_template_error("Security: access to constant '{$const}' not permitted"); | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if ($this->allow_constants) { | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $compiler->trigger_template_error("Security: access to constants not permitted"); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Check if stream is trusted. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * @param  string $stream_name | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @return boolean         true if stream is trusted | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @throws SmartyException if stream is not trusted | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     public function isTrustedStream($stream_name) | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         if (isset($this->streams) && (empty($this->streams) || in_array($stream_name, $this->streams))) { | 
					
						
							|  |  |  |             return true; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         throw new SmartyException("stream '{$stream_name}' not allowed by security setting"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Check if directory of file resource is trusted. | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-06-28 02:37:41 +02:00
										 |  |  |      * @param  string   $filepath | 
					
						
							|  |  |  |      * @param null|bool $isConfig | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-06-28 02:37:41 +02:00
										 |  |  |      * @return bool true if directory is trusted | 
					
						
							|  |  |  |      * @throws \SmartyException if directory is not trusted | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-06-28 02:37:41 +02:00
										 |  |  |     public function isTrustedResourceDir($filepath, $isConfig = null) | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |         if ($this->_include_path_status !== $this->smarty->use_include_path) { | 
					
						
							| 
									
										
										
										
											2018-04-24 10:38:18 +02:00
										 |  |  |             $_dir = $this->smarty->use_include_path ? $this->smarty->ext->_getIncludePath->getIncludePathDirs($this->smarty) : array(); | 
					
						
							|  |  |  |             if ($this->_include_dir !== $_dir) { | 
					
						
							|  |  |  |                 $this->_updateResourceDir($this->_include_dir, $_dir); | 
					
						
							|  |  |  |                 $this->_include_dir = $_dir; | 
					
						
							| 
									
										
										
										
											2015-07-07 17:55:45 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |             $this->_include_path_status = $this->smarty->use_include_path; | 
					
						
							| 
									
										
										
										
											2015-07-07 17:55:45 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-24 10:38:18 +02:00
										 |  |  |         if ($isConfig !== true) { | 
					
						
							| 
									
										
										
										
											2015-06-28 02:37:41 +02:00
										 |  |  |             $_dir = $this->smarty->getTemplateDir(); | 
					
						
							|  |  |  |             if ($this->_template_dir !== $_dir) { | 
					
						
							| 
									
										
										
										
											2018-04-24 10:38:18 +02:00
										 |  |  |                 $this->_updateResourceDir($this->_template_dir, $_dir); | 
					
						
							| 
									
										
										
										
											2015-06-28 02:37:41 +02:00
										 |  |  |                 $this->_template_dir = $_dir; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-24 10:38:18 +02:00
										 |  |  |         if ($isConfig !== false) { | 
					
						
							| 
									
										
										
										
											2015-06-28 02:37:41 +02:00
										 |  |  |             $_dir = $this->smarty->getConfigDir(); | 
					
						
							|  |  |  |             if ($this->_config_dir !== $_dir) { | 
					
						
							| 
									
										
										
										
											2018-04-24 10:38:18 +02:00
										 |  |  |                 $this->_updateResourceDir($this->_config_dir, $_dir); | 
					
						
							| 
									
										
										
										
											2015-06-28 02:37:41 +02:00
										 |  |  |                 $this->_config_dir = $_dir; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-24 10:38:18 +02:00
										 |  |  |         if ($this->_secure_dir !== $this->secure_dir) { | 
					
						
							|  |  |  |             $this->secure_dir = (array)$this->secure_dir; | 
					
						
							|  |  |  |             foreach($this->secure_dir as $k => $d) { | 
					
						
							|  |  |  |                 $this->secure_dir[$k] = $this->smarty->_realpath($d.DIRECTORY_SEPARATOR,true); | 
					
						
							| 
									
										
										
										
											2015-06-28 02:37:41 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-04-24 10:38:18 +02:00
										 |  |  |             $this->_updateResourceDir($this->_secure_dir, $this->secure_dir); | 
					
						
							|  |  |  |             $this->_secure_dir = $this->secure_dir; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $addPath =  $this->_checkDir($filepath, $this->_resource_dir); | 
					
						
							|  |  |  |         if ($addPath !== false) { | 
					
						
							|  |  |  |            $this->_resource_dir = array_merge($this->_resource_dir, $addPath); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 22:21:49 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Check if URI (e.g. {fetch} or {html_image}) is trusted | 
					
						
							|  |  |  |      * To simplify things, isTrustedUri() resolves all input to "{$PROTOCOL}://{$HOSTNAME}". | 
					
						
							|  |  |  |      * So "http://username:password@hello.world.example.org:8080/some-path?some=query-string" | 
					
						
							|  |  |  |      * is reduced to "http://hello.world.example.org" prior to applying the patters from {@link $trusted_uri}. | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param  string $uri | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @return boolean         true if URI is trusted | 
					
						
							| 
									
										
										
										
											2011-12-18 22:21:49 +00:00
										 |  |  |      * @throws SmartyException if URI is not trusted | 
					
						
							|  |  |  |      * @uses $trusted_uri for list of patterns to match against $uri | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function isTrustedUri($uri) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $_uri = parse_url($uri); | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         if (!empty($_uri[ 'scheme' ]) && !empty($_uri[ 'host' ])) { | 
					
						
							|  |  |  |             $_uri = $_uri[ 'scheme' ] . '://' . $_uri[ 'host' ]; | 
					
						
							| 
									
										
										
										
											2011-12-18 22:21:49 +00:00
										 |  |  |             foreach ($this->trusted_uri as $pattern) { | 
					
						
							|  |  |  |                 if (preg_match($pattern, $_uri)) { | 
					
						
							|  |  |  |                     return true; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 22:21:49 +00:00
										 |  |  |         throw new SmartyException("URI '{$uri}' not allowed by security setting"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Check if directory of file resource is trusted. | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * @param  string $filepath | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @return boolean         true if directory is trusted | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @throws SmartyException if PHP directory is not trusted | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     public function isTrustedPHPDir($filepath) | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         if (empty($this->trusted_dir)) { | 
					
						
							|  |  |  |             throw new SmartyException("directory '{$filepath}' not allowed by security setting (no trusted_dir specified)"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // check if index is outdated
 | 
					
						
							|  |  |  |         if (!$this->_trusted_dir || $this->_trusted_dir !== $this->trusted_dir) { | 
					
						
							|  |  |  |             $this->_php_resource_dir = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $this->_trusted_dir = $this->trusted_dir; | 
					
						
							|  |  |  |             foreach ((array) $this->trusted_dir as $directory) { | 
					
						
							| 
									
										
										
										
											2016-08-23 08:03:39 +02:00
										 |  |  |                 $directory = $this->smarty->_realpath($directory . DIRECTORY_SEPARATOR, true); | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                 $this->_php_resource_dir[ $directory ] = true; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-24 10:38:18 +02:00
										 |  |  |         $addPath =  $this->_checkDir($filepath, $this->_php_resource_dir); | 
					
						
							|  |  |  |         if ($addPath !== false) { | 
					
						
							|  |  |  |            $this->_php_resource_dir = array_merge($this->_php_resource_dir, $addPath); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          return true; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 10:38:18 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Remove old directories and its sub folders, add new directories | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param array $oldDir | 
					
						
							|  |  |  |      * @param array $newDir | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function _updateResourceDir($oldDir, $newDir) { | 
					
						
							|  |  |  |         foreach ($oldDir as $directory) { | 
					
						
							|  |  |  |             $directory = $this->smarty->_realpath($directory, true); | 
					
						
							|  |  |  |             $length = strlen($directory); | 
					
						
							|  |  |  |             foreach ($this->_resource_dir as $dir) { | 
					
						
							|  |  |  |                 if (substr($dir, 0,$length) === $directory) { | 
					
						
							|  |  |  |                     unset($this->_resource_dir[ $dir ]); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         foreach ($newDir as $directory) { | 
					
						
							|  |  |  |             $directory = $this->smarty->_realpath($directory, true); | 
					
						
							|  |  |  |             $this->_resource_dir[ $directory ] = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Check if file is inside a valid directory | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $filepath | 
					
						
							|  |  |  |      * @param array  $dirs valid directories | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2018-04-24 10:38:18 +02:00
										 |  |  |      * @return array|bool | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |      * @throws \SmartyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function _checkDir($filepath, $dirs) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-24 10:38:18 +02:00
										 |  |  |         $directory = dirname($filepath) . DIRECTORY_SEPARATOR; | 
					
						
							|  |  |  |         if (isset($dirs[ $directory ])) { | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $filepath = $this->smarty->_realpath($filepath, true); | 
					
						
							| 
									
										
										
										
											2016-08-23 08:03:39 +02:00
										 |  |  |         $directory = dirname($filepath) . DIRECTORY_SEPARATOR; | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |         $_directory = array(); | 
					
						
							|  |  |  |         while (true) { | 
					
						
							| 
									
										
										
										
											2018-04-24 10:38:18 +02:00
										 |  |  |              // test if the directory is trusted
 | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             if (isset($dirs[ $directory ])) { | 
					
						
							| 
									
										
										
										
											2018-04-24 10:38:18 +02:00
										 |  |  |                return $_directory; | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |             // abort if we've reached root
 | 
					
						
							|  |  |  |             if (!preg_match('#[\\\/][^\\\/]+[\\\/]$#', $directory)) { | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-04-24 10:38:18 +02:00
										 |  |  |             // remember the directory to add it to _resource_dir in case we're successful
 | 
					
						
							|  |  |  |             $_directory[ $directory ] = true; | 
					
						
							|  |  |  |            // bubble up one level
 | 
					
						
							| 
									
										
										
										
											2016-08-23 08:03:39 +02:00
										 |  |  |             $directory = preg_replace('#[\\\/][^\\\/]+[\\\/]$#', DIRECTORY_SEPARATOR, $directory); | 
					
						
							| 
									
										
										
										
											2015-07-12 07:03:55 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // give up
 | 
					
						
							|  |  |  |         throw new SmartyException("directory '{$filepath}' not allowed by security setting"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Loads security class and enables security | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param \Smarty                 $smarty | 
					
						
							|  |  |  |      * @param  string|Smarty_Security $security_class if a string is used, it must be class-name | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return \Smarty current Smarty instance for chaining | 
					
						
							|  |  |  |      * @throws \SmartyException when an invalid class name is provided | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public static function enableSecurity(Smarty $smarty, $security_class) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if ($security_class instanceof Smarty_Security) { | 
					
						
							|  |  |  |             $smarty->security_policy = $security_class; | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |             return $smarty; | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  |         } elseif (is_object($security_class)) { | 
					
						
							|  |  |  |             throw new SmartyException("Class '" . get_class($security_class) . "' must extend Smarty_Security."); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |         if ($security_class === null) { | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  |             $security_class = $smarty->security_class; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!class_exists($security_class)) { | 
					
						
							|  |  |  |             throw new SmartyException("Security class '$security_class' is not defined"); | 
					
						
							|  |  |  |         } elseif ($security_class !== 'Smarty_Security' && !is_subclass_of($security_class, 'Smarty_Security')) { | 
					
						
							|  |  |  |             throw new SmartyException("Class '$security_class' must extend Smarty_Security."); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $smarty->security_policy = new $security_class($smarty); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |         return $smarty; | 
					
						
							| 
									
										
										
										
											2015-06-28 01:38:52 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-03-11 02:55:55 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Start template processing | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param $template | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @throws SmartyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function startTemplate($template) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if ($this->max_template_nesting > 0 && $this->_current_template_nesting ++ >= $this->max_template_nesting) { | 
					
						
							|  |  |  |             throw new SmartyException("maximum template nesting level of '{$this->max_template_nesting}' exceeded when calling '{$template->template_resource}'"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Exit template processing | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function endTemplate() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if ($this->max_template_nesting > 0) { | 
					
						
							|  |  |  |             $this->_current_template_nesting --; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Register callback functions call at start/end of template rendering | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param \Smarty_Internal_Template $template | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function registerCallBacks(Smarty_Internal_Template $template) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $template->startRenderCallbacks[] = array($this, 'startTemplate'); | 
					
						
							|  |  |  |         $template->endRenderCallbacks[] = array($this, 'endTemplate'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | } |