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.
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).
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. &
-> &
, <
-> <
, >
-> >
and so on).
Different goals.
Does it save you from XSS issues? Yes, but make sure you have correctly configured your character encoding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With