Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is $this->escape() in the Zend view enough for xss

I do a lot of $this->escape() in the zend view. Is this enough to prevent XSS?

There's HTMLPurifier outside the Zend Framework. I wonder how zend's $this->escape() compares to HTMLPurifier.

like image 771
silow Avatar asked Nov 21 '10 00:11

silow


2 Answers

escape is an alias of htmlspecialchars. It allows you to output plain text, while HTMLPurifier allows you to output safe HTML.

You can't have XSS with plain text.

You have to use HTMLPurifier instead of strip_tags if you want to output safe HTML coming from an user input (rich text editor for example).

like image 149
Maxence Avatar answered Oct 17 '22 02:10

Maxence


HTMLPurifier is serving different purpose. HTMLPurifier does not escape HTML... well, not exactly. It takes a configuration you give it that defines what is permitted in the HTML and what's not, and it cleans based on that. The result is actually still HTML, with certain things removed/sanitized.

escape() on that other hand is turning HTML-like characters into HTML entities so that they render the same characters in the browser instead of being interpreted as HTML (e.g. & -> &amp;, < -> &lt;, > -> &gt; and so on).

Different goals.

Does it save you from XSS issues? Yes, but make sure you have correctly configured your character encoding.

like image 37
d11wtq Avatar answered Oct 17 '22 04:10

d11wtq