> e.g. it won't protect you from XSS if you ever place user-controlled data
in HTML attributes.
As I've found, such an XSS can have a place in the code like this:
$xss = "');your_code_here();//";
<div onmouseover="alert('<?php echo htmlspecialchars($xss, ENT_QUOTES,
'UTF-8') ?>')">
I think this is more architectural problem, not an escaping problem. This
is very special case when we really need it.
> If you are in a HTML context you need different escaping than you need in
a CSS or JS block.
For JS it's better to use json_encode(). And I've never met CSS+PHP output,
this is some special case.
> would be misleading people into thinking this operator is generic and can
be used in all contexts safely.
I don't think that many programmers can think so. Anyway, this can be
menthioned in documentation.
> The escaping should also be aware of the content encoding.
For special cases - e.g. when we use one encoding and need to output a
value in another encoding - htmlspecialchars() still can be used.
> Sure you can implement that in userland, but people don't do it or make
it too complicated,
> so you get every day code with unescaped stuff.
Yes. This is the main problem.
Almost each echo operator is an output of data from database, usually this
is an entity property if the ORM is used or an array key if isn't. I'm not
talking about fully functional escaping operator for all cases, just for
most often case - output a value into HTML document. If we have a shorcut
for "<?php echo $value; ?>" then we also need a shortcut for "<?php echo
htmlspecialchars($value, ENT_QUOTES); ?>", because PHP is a web-programming
language. I think this operator can make many projects more safer.
2016-06-18 3:32 GMT+05:00 Thomas Bley <mails@thomasbley.de>: