What is the difference between AntiXss.HtmlEncode and HttpUtility.HtmlEncode?

I don’t have an answer specifically to your question, but I would like to point out that the white list vs black list approach not just “nice”. It’s important. Very important. When it comes to security, every little thing is important. Remember that with cross-site scripting and cross-site request forgery , even if your site … Read more

htmlspecialchars vs htmlentities when concerned with XSS

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: <?php $_GET[‘password’] = ‘asdf&ddddd”fancy˝quotes˝’; echo htmlspecialchars($_GET[‘password’], ENT_COMPAT | ENT_HTML401, ‘UTF-8’) . “\n”; // Output: asdf&amp;ddddd&quot;fancyË echo htmlentities($_GET[‘password’], ENT_COMPAT | ENT_HTML401, ‘UTF-8’) . “\n”; // Output: asdf&amp;ddddd&quot;fancy&Euml;quotes You should always use htmlentities and very rarely … Read more

Allow All Content Security Policy?

For people who still want an even more permissive posts, because the other answers were just not permissive enough, and they must work with google chrome for which * is just not enough: default-src * data: blob: filesystem: about: ws: wss: ‘unsafe-inline’ ‘unsafe-eval’ ‘unsafe-dynamic’; script-src * data: blob: ‘unsafe-inline’ ‘unsafe-eval’; connect-src * data: blob: ‘unsafe-inline’; … Read more

What is the http-header “X-XSS-Protection”?

X-XSS-Protection is a HTTP header understood by Internet Explorer 8 (and newer versions). This header lets domains toggle on and off the “XSS Filter” of IE8, which prevents some categories of XSS attacks. IE8 has the filter activated by default, but servers can switch if off by setting X-XSS-Protection: 0 See also http://blogs.msdn.com/b/ieinternals/archive/2011/01/31/controlling-the-internet-explorer-xss-filter-with-the-x-xss-protection-http-header.aspx

XSS filtering function in PHP

Simple way? Use strip_tags(): $str = strip_tags($input); You can also use filter_var() for that: $str = filter_var($input, FILTER_SANITIZE_STRING); The advantage of filter_var() is that you can control the behaviour by, for example, stripping or encoding low and high characters. Here is a list of sanitizing filters.

Prevent XSS with strip_tags()?

I strongly disagree it’s “academically better”. It breaks user input (imagine how useless StackOverflow would be for this discussion if they “cleaned” posts from all tags). Text inserted in HTML with only tags stripped will be invalid. HTML requires & to be escaped as well. It’s not even safe in HTML! strip_tags() is not enough … Read more