Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's a few things to consider here. Firstly, you've got <a href="http://www.troyhunt.com/2010/03/request-validation-dotnetnuke-and.html" rel="nofollow">ASP.NET Request Validation</a> which will catch many of the common XSS patterns. Don't rely exclusively on this, but it's a nice little value add.</p> <p>Next up you want to validate the input against a white-list and in this case, your white-list is all about conforming to the expected structure of a URL. Try using <a href="http://msdn.microsoft.com/en-us/library/system.uri.iswellformeduristring.aspx" rel="nofollow">Uri.IsWellFormedUriString</a> for compliance against RFC 2396 and RFC 273:</p> <pre><code>var sourceUri = UriTextBox.Text; if (!Uri.IsWellFormedUriString(sourceUri, UriKind.Absolute)) { // Not a valid URI - bail out here } </code></pre> <p>AntiXSS has Encoder.UrlEncode which is great for encoding string to be appended to a URL, i.e. in a query string. Problem is that you want to take the original string and <em>not</em> escape characters such as the forward slashes otherwise <code>http://troyhunt.com</code> ends up as <code>http%3a%2f%2ftroyhunt.com</code> and you've got a problem.</p> <p>As the context you're encoding for is an HTML attribute (it's the "href" attribute you're setting), you want to use Encoder.HtmlAttributeEncode:</p> <pre><code>MyHyperlink.NavigateUrl = Encoder.HtmlAttributeEncode(sourceUri); </code></pre> <p>What this means is that a string like <code>http://troyhunt.com/&lt;script&gt;</code> will get escaped to <code>http://troyhunt.com/&amp;lt;script&gt;</code> - but of course Request Validation would catch that one first anyway.</p> <p>Also take a look at the OWASP Top 10 <a href="https://www.owasp.org/index.php/Top_10_2010-A10-Unvalidated_Redirects_and_Forwards" rel="nofollow">Unvalidated Redirects and Forwards</a>.</p>
    singulars
    1. This table or related slice is empty.
    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. 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.
 

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