Re: [SMARTY] Serious security hole
| From: | Monte Ohrt | Date: | Sun, 02 Feb 2003 05:59:53 +0000 |
| Subject: | Re: [SMARTY] Serious security hole | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7451@lists.php.net to get a copy of this message | ||
Thanks for the heads up. The parser in the CVS version is much more thorough, it only allows what is explicitly permitted, whereas in 2.3.1 it is possible for things to slip through that are not explicitly denied. I tried your example and it fails with errors, as it should. Let me know if you see any problems with CVS.
CVS also seems pretty stable, I don't know anything not working. The next release is only waiting on documentation updates, I'll get that out ASAP.
Monte
Ferdinand Beyer wrote:
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...