Search code examples
phphtmlxhtmlxsshtmlpurifier

HTML Purifier - what to purify?


I am using HTML Purifier to protect my application from XSS attacks. Currently I am purifying content from WYSIWYG editors because that is the only place where users are allowed to use XHTML markup.

My question is, should I use HTML Purifier also on username and password in a login authentication system (or on input fields of sign up page such as email, name, address etc)? Is there a chance of XSS attack there?


Solution

  • You should Purify anything that will ever possibly be displayed on a page. Because with XSS attacks, hackers put in <script> tags or other malicious tags that can link to other sites.

    Passwords and emails should be fine. Passwords should never be shown and emails should have their own validator to make sure that they are in the proper format.

    Finally, always remember to put in htmlentities() on content.

    Oh .. and look at filter_var aswell. Very nice way of filtering variables.