Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Practice: User generated HTML cleaning

I'm coding a WYSIWYG editor width designMode="on" on a iframe. The editor works fine and i store the code as is in the database.

Before outputing the html i need to "clean" with php on the server-side to avoid cross-site-scripting and other scary things. Is there some sort of best practice on how to do this? What tags can be dangerous?

UPDATE: Typo fixed, it's What You See Is What You Get. Nothing new :)

like image 487
Martin Avatar asked May 05 '10 14:05

Martin


1 Answers

The best practice is to allow only certain things you know aren't dangerous, and remove/escape all the rest. See the paper Automated Malicious Code Detection and Removal on the Web (OWASP AntiSamy) for a discussion on this (the library is for Java, but the principles apply for any language).

like image 187
Chris Lercher Avatar answered Sep 29 '22 08:09

Chris Lercher