全文转自:http://stackoverflow.com/questions/5337143/codeigniter-why-use-xss-clean
if I'm sanitizing my DB inserts, and also escaping the HTML I write with |
|||
feedback
|
5
|
xss_clean() is extensive, and also silly. 90% of this function does nothing to prevent xss. Such as looking for the word However running
A simple poc is:
This will add the However, quoting from the xss_clean() documentation:
That being said, XSS is an |
||||||||||
feedback
|
2
|
Yes you should still be using it, I generally make it a rule to use it at least on public facing input, meaning any input that anyone can access and submit to. Generally sanitizing the input for DB queries seems like a side-effect as the true purpose of the function is to prevent Cross-site Scripting Attacks. I'm not going to get into the nitty gritty details of every step xss_clean takes, but i will tell you it does more than the few steps you mentioned, I've pastied the source of the xss_clean function so you can look yourself, it is fully commented. |
htmlentities($text, ENT_COMPAT, 'UTF-8')
is not a good method of stopping xss, no one should be using this. – Rook Mar 18 at 5:55htmlentities
is absolutely proof against HTML-injection, thoughENT_QUOTES
is needed instead ofENT_COMPAT
if you ever use single quote attribute delimiters.htmlspecialchars
is generally preferable tohtmlentities
, though, as it has less chance of messing up the charset. CodeIgniter'sxss_clean
is a worthless cargo-cult-programming disaster area full of wrongheaded misunderstandings of what constitutes string handling. – bobince Aug 20 at 10:32