Serious security hole

From: Date: Sat, 01 Feb 2003 17:05:50 +0000
Subject: Serious security hole
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-7449@lists.php.net to get a copy of this message
Hi, I've played a bit with Smarty's sloppy regexp-played parser and found out that it is possible for template designers to executive _any_ PHP code even if strict $security settings are used! The problem is that Smarty currently does not check tag content strictly enough and alwas tries to treat unknown content as plugins even if the tag name contains illegal special characters. Here is the example I used: {assign' . substr('', print("This is a test.") ) . ' var="name" value="Bob"} This gets compiled to: <?php $this->_plugins['function']['assign' . substr('', print("This is a test.") ) . ''][0](array('var' => "name",'value' => "Bob"), $this); if($this- >_extract) { extract($this->_tpl_vars); $this->_extract=false; } ?> The template is executed without any notice or error message and prints 'This is a test'. print() returns true and php would convert it to 1 so that Smarty fails loading an assign1 plugin -- that's why I used the substr() workaround above. If the print() call is replaced with an include statement, there is absolutely no limit for bad consequences - especially if the included file is on a different server (via http)! And the programmer wouldn't even notice anything as the template output looks alright! A solution would be a more strictly parsing routine. Perhaps some day Smarty needs a real parser instead of using regular expressions... -- Ferdinand Beyer <fbeyer@clickhand.de>

« previous php.smarty.general (#7449) next »