akbkhome

Smoking toooooo much PHP



Not really template engine related
Well this is a good security feature of flexy i don't really see how it works into template engine vs php debate.

First i haven't heard of any other template engine doing what flexy does. And second there is nothing to stop you from adding this same security call to php only templates if your using some kind of controlling class like Savant.

I do think it says its not good to just roll your own simple template setup since there are lots of things you'll forget to do.
#1 - Joshua Eichorn ( Link) on 05 Apr 2005, 00:50 Delete Comment
Ouput Filtering, Not Templates
This seems more a problem of (as Shiflett might say) "failure to escape output." Eichorn is right: this is not a point for or against template systems per se, but about proper programming practice.

With that in mind, a template system can help enforce automatic escaping of output (or at least make it convenient). But technically, you don't need Flexy or Smarty or even Savant to do that; write a quickie function to apply htmlspecialchars (or whatever) to the variable, and use that in place of "echo" or "print" (or echo that function instead of the variable).

And now the shameless self-promotion: Savant3 supports this via its "scrub" plugin, which lets you define default and custom scrubbers for output; the other plugins in Savant3 (e.g. the "form" plugins) call scrub() on all output automatically.


Savant can be found at http://phpsavant.com.
#2 - Paul M. Jones ( Link) on 05 Apr 2005, 01:42 Delete Comment
I Agree
I agree that output filtering is a strong reason to use a template engine.

WACT has automatic output filtering as well. All output values are escaped unless you use the raw designation to override it. The raw designation is special and must be last in any series of filters to operate correctly. The 'html' filter performs output escaping appropriate for an html document and is the default.

{$value} // filtered
{$value|raw} // unfiltered
{$value|capitalize|raw} // unfiltered
{$value|raw|capitalize} // filtered
{$value|html} // filtered
{$value|html|capitalize} // error - double filtered
{$value|html|capitalize|raw} // filtered

#3 - Jeff Moore ( Link) on 05 Apr 2005, 03:26 Delete Comment
not escaping values? That's hardly a template issue
Honestly, the code for pearweb is a horrible example. Using $_* variables directly in a template or in code without any processing is just, well, not intelligent.

Sure it's great to protect you from yourself, but better is to approach design from the standpoint of a hacker

"How can I use this code to gain access to a machine/spread my virus or malicious code/do DoS attacks?"

It doesn't really matter how fancy your template engine is, honestly, as benchmarking should show that only the highest traffic sites will be slowed down by the template engine.

Far more important are considerations such as:

1) Do I have to make a directory world-writeable for my compiled template engine, and if so, is there any way a malicious user can upload their own scripts to replace mine?

2) How slow is my database access in the backend?

3) Should I be using a cache?

To claim PHP as a template language is somehow more vulnerable to attack than any compiling engine doesn't make sense. To be truly secure, you still have to do lots of non-intuitive work (compile the templates at home and upload the compiled copies).
#4 - Greg Beaver ( Link) on 05 Apr 2005, 23:08 Delete Comment


Name
Email
Homepage
Comment Title
Comment
 
Contact me at alan@akbkhome.com