Re: A better XSS trap (Feedback wanted)



Hej Egbert,

In my eyes it is
better to always be forced to choose the right filter depending on the
context and for example html, urls or javascript are different contexts
that require different filters.

I think you're right there. Maybe I'll have to change some of that.

I think it is partly a question of taste. I am following the
perfectionists path here. But automatically applying htmlentities to
everything by default (but with a by-pass option) also has an advantage.
It makes template code shorter, which is also nice.

About template lanugages:

Mostly because of control structures. [...] Wrapping them
into curly or angular braces makes the whole thing a much nicer read,
and easier to understand for non-programmers (doing the HTML design).
To my experience, it is a big difference for some.

But it's really a matter of taste;

I agree, in the end it comes down to a question of taste and psychology.
I personally stick to PHP only, because the I gain of a template engine
is smaller than the effort for setup, compilation and learning a new
language. And I disagree with your statement on the mplate website,
compared to plain PHP, mplate IS another language and a new way of
working, even if it is closer to PHP.

However, I also use Smarty in one project for quite some years now.
Mainly because of it's security feature. The project is sort of a web
service, where the clients can provide arbitrary presentation logic
using smarty templates. It started before the common web service
standards became really popular or at least known to me. I was a lot
less experienced at that time. Our biggest Problem throughout all time
was that people didn't know the Smarty syntax and having to learn it was
a barrier. So another reason why I like PHP only templates is that PHP
is well known and well documented.

After some thought: does your approach also allow objects to be
filtered? this would possibly be a whole bit more complicated, with
method call return values and magic/non-magic properties, etc..

Yes, objects are also wrapped dynamically and recursively using magic
methods. So are arrays using the ArrayAccess interface. Accessing
anything inside them returns a decorated value. Read the examples in the
SVN, it's all in there :). Browse the SVN from the google code page if
you want. (And yes it was a "whole bit more complicated" to implement
;), but I wanted a comprehensive solution and SPL helped a lot).

One oddity for objects is, that since they are wrapped by decorating
objects, using methods or operators like "instanceof" on the outer
objects does not work as expected, at least if you expect equivalent
results. I didn't like that at first. But in a way it makes sense, as
the wrapping object controls all access to the wrapped object, even to
the type information. So as with strings, anytime the REAL value is
needed, ->raw() is the answer.

/Christopher
.



Relevant Pages

  • Re: How do we get there from here?
    ... > then sub the whole of that generated markup into the template? ... layed out on the fly, a simple IMG tag, or even an entire HTML document. ... PHP scripting provides 10 times the features of both of these ... idea as tokens can eliminate a huge amount of maintance, ...
    (comp.databases.pick)
  • Re: nested conditional that can identify parent page?
    ... and specify the files in the array including ... try to make as little php and html mix as possible, have a template ...
    (alt.php)
  • Re: Separation of logic, design and data
    ... That is the weakness of using includes for HTML pieces. ... <?php include 'headerstuff.php'; ?> ... and now I'm here at my Template ... I'm sure at some point in the future I'll see the weaknesses in my ...
    (comp.lang.php)
  • Re: best way for PHP page
    ... WYSIWYG html editor and work with other colleagues who have no php ... I can then call the template from a function feeding the title and any ... interactivity and client/server interactivity. ...
    (php.general)
  • Re: [PHP] xss filter
    ... the obvious choice (for PHP) should be HTML Purifier by Edward Yang. ... --Bipin Upadhyay. ... There most be some safe way to filter out xss without filtering out all ...
    (php.general)