Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The golden rule to prevent XSS is to HTML encode everything that you are outputting to a view.</p> <p>Hopefully the <code>@</code> Razor function already does that automatically for you. </p> <p>So when you write one of the following you are pretty safe:</p> <pre><code>@Model.SomeProperty @Html.DisplayFor(x =&gt; x.SomeProperty) </code></pre> <p>You should be careful with the <code>@Html.Raw</code> helper:</p> <pre><code>@Html.Raw(Model.SomeProperty) </code></pre> <p>If you use that the output will not be HTML encoded. This doesn't mean that your site is vulnerable to XSS injection. For example if you have total control of the property and is not coming from an user input you should be pretty safe.</p> <p>If you are using the WebForms view engine then you should be more careful because the <code>&lt;%=</code> function doesn't HTML encode the output.</p> <p>So the following is not safe:</p> <pre><code>&lt;%= Model.SomeProperty %&gt; </code></pre> <p>You should use one of the following:</p> <pre><code>&lt;%= Html.DisplayFor(x =&gt; x.SomeProperty) %&gt; &lt;%: Model.SomeProperty %&gt; </code></pre> <p>If on the other hand you need to output some user input without HTML encoding it I would recommend you using the <a href="http://wpl.codeplex.com/" rel="nofollow"><code>AntiXSS</code></a> library from Microsoft. It will filter out all dangerous tags from the input and you are safe to output it. For example it will remove the <code>&lt;script&gt;</code> tags from the input. There's also an <a href="http://msdn.microsoft.com/en-us/library/aa973813.aspx" rel="nofollow"><code>article on MSDN</code></a> about this library that you might checkout.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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