htmlspecialchars vs htmlentities when concerned with XSS

前端 未结 3 817
闹比i
闹比i 2020-11-30 02:57

I have seen a lot of conflicting answers about this. Many people love to quote that php functions alone will not protect you from xss.

What XSS exactly can make it t

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 03:54

    htmlspecialchars() will NOT protect you against UTF-7 XSS exploits, that still plague Internet Explorer, even in IE 9: http://securethoughts.com/2009/05/exploiting-ie8-utf-7-xss-vulnerability-using-local-redirection/

    For instance:

    You should always use htmlentities and very rarely use htmlspecialchars when sanitizing user input. ALso, you should always strip tags before. And for really important and secure sites, you should NEVER trust strip_tags(). Use HTMLPurifier for PHP.

提交回复
热议问题