Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you are attacking it from the wrong angle by trying to encode all posted data.</p> <p>Note that a "<code>&lt;</code>" could also come from other outside sources, like a database field, a configuration, a file, a feed and so on. </p> <p>Furthermore, "<code>&lt;</code>" is not inherently dangerous. It's only dangerous in a specific context: when writing strings that haven't been encoded to HTML output (because of XSS).</p> <p>In other contexts different sub-strings are dangerous, for example, if you write an user-provided URL into a link, the sub-string "<code>javascript:</code>" may be dangerous. The single quote character on the other hand is dangerous when interpolating strings in SQL queries, but perfectly safe if it is a part of a name submitted from a form or read from a database field.</p> <p>The bottom line is: you can't filter random input for dangerous characters, because any character may be dangerous under the right circumstances. You should encode at the point where some specific characters may become dangerous because they cross into a different sub-language where they have special meaning. When you write a string to HTML, you should encode characters that have special meaning in HTML, using Server.HtmlEncode. If you pass a string to a dynamic SQL statement, you should encode different characters (or better, let the framework do it for you by using prepared statements or the like)..</p> <p><em>When</em> you are sure you HTML-encode everywhere you pass strings to HTML, then set <code>validateRequest="false"</code> in the <code>&lt;%@ Page ... %&gt;</code> directive in your <code>.aspx</code> file(s).</p> <p>In .NET 4 you may need to do a little more. Sometimes it's necessary to also add <code>&lt;httpRuntime requestValidationMode="2.0" /&gt;</code> to web.config (<a href="http://www.asp.net/%28S%28ywiyuluxr3qb2dfva1z5lgeg%29%29/learn/whitepapers/aspnet4/breaking-changes/" rel="noreferrer">reference</a>).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload