cross site scripting prevent Archives - Anuj Varma, Hands-On Technology Architect, Clean Air Activist https://www.anujvarma.com/tag/cross-site-scripting-prevent/ Production Grade Technical Solutions | Data Encryption and Public Cloud Expert Tue, 15 Jul 2014 02:24:54 +0000 en-US hourly 1 https://wordpress.org/?v=7.0.2 https://www.anujvarma.com/wp-content/uploads/anujtech.png cross site scripting prevent Archives - Anuj Varma, Hands-On Technology Architect, Clean Air Activist https://www.anujvarma.com/tag/cross-site-scripting-prevent/ 32 32 Prevent URI (XSS) rewrites in asp.net https://www.anujvarma.com/prevent-uri-xss-rewrites-in-asp-net/ https://www.anujvarma.com/prevent-uri-xss-rewrites-in-asp-net/#respond Tue, 15 Jul 2014 02:24:54 +0000 http://www.anujvarma.com/?p=2627 The Uri.IsWellFormedUriString method is well suited to check for any malformed URLs. It can be used to  validate the address and the entire query string. var newUrl = Request.QueryString["Url"]; if […]

The post Prevent URI (XSS) rewrites in asp.net appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
The Uri.IsWellFormedUriString method is well suited to check for any malformed URLs. It can be used to  validate the address and the entire query string.

var newUrl = Request.QueryString["Url"];
if (!Uri.IsWellFormedUriString(newUrl, UriKind.Absolute))
{
  litLeavingTag.Text = "An invalid URL has been specified.";
  return;
}

Request Validation

At a page level, one can turn on RequestValidation (set to false by default)
<%@ Page Language=”C#” MasterPageFile=”~/Site.Master” AutoEventWireup=”true” CodeBehind=”GoingToPage.aspx.cs” Title=”Leaving Site” ValidateRequest=”true” %>

Summary

Each of these techniques provide a quick and effective way to prevent XSS rewrites from making it through the ASP.NET pipeline.

The post Prevent URI (XSS) rewrites in asp.net appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/prevent-uri-xss-rewrites-in-asp-net/feed/ 0