ASP.NET Anti Cross-Site Scripting Attack Library Released by Dan Wahlin

Home > Blogs > Developer Visual Studio / ASP.NET > ASP.NET Anti Cross-Site Scripting Attack Library Released by Dan Wahlin

ASP.NET Anti Cross-Site Scripting Attack Library Released by Dan Wahlin

Like This Blog 0 Dan Wahlin
Added by November 20, 2010

Cross-Site Scripting (XSS) attacks can led to many different problems depending upon what type of data a user is allowed to enter and what type of data is displayed in a Web page.  By using XSS attacks hackers can steal user data stored in cookies, potentially hi-jack a user's session, plus trigger data to be sent to another site behind the scenes with some simple JavaScript code.

If you're collecting user input in a Web application (who isn't…that's one of the biggest uses of the Web) you definitely need to worry about XSS attacks especially if you allow users to input data which is then displayed somewhere in a page at some point after it is submitted.  Examples would be forums, registration confirmation pages that show what the user entered, blogs, plus many others.  These days its safe to say that all user data should be treated as untrusted especially since bots and other programs can act like a human and submit fake data to try to find holes in an application.

Microsoft recently released a new XSS attack library that makes it really simple to prevent different types of XSS attacks with a minimal amount of code.  The library's main class is called AntiXss and is capable of encoding many different formats from HTML input to QueryString input to XML input.  A complete list of the different types of encodings it handles is shown below:

  • Html Encoding
  • Html Attribute Encoding
  • JavaScript Encoding
  • URL Encoding
  • Visual Basic Script Encoding
  • XML Encoding
  • XML Attribute Encoding

While you can certainly use built-in ASP.NET classes to handle XSS attacks and deal with the different encoding issues shown above, the AntiXss class makes it extremely simple to handle encoding user input without having to know about various .NET classes and methods.  The methods available in the class are shown next:

namespace Microsoft.Application.Security

public class AntiXss {

public static string HtmlEncode(string s);
public static string 
HtmlAttributeEncode(string s);
public static string 
JavaScriptEncode(string s);
public static string 
UrlEncode(string s);
public static string 
VisualBasicScriptEncode(string s);
public static string 
XmlEncode(string s);
public static string 
XmlAttributeEncode(string s);

The ASP.NET XSS library can be downloaded from the following URL:

An article discussing the fundamentals of threat modeling as well as how to use the AntiXss class in an ASP.NET page can be found here:


Videos You May Like

Agile Methodology in Project Management

0 184 0

In this video, you will gain an understanding of Agile and Scrum Master Certification terminologies and concepts to help you make better decisions in your Project Management capabilities. Whether you’re a developer looking to obtain an Agile or Scrum Master Certification, or you’re a Project Manager/Product Owner who is attempting to get your product or … Continue reading Agile Methodology in Project Management

Creating Users and Managing Passwords in Microsoft Office 365

0 795 4

In this Office 365 training video, instructor Spike Xavier demonstrates how to create users and manage passwords in Office 365.   For instructor-led Office 365 training classes, see our course schedulle: Spike Xavier SharePoint Instructor – Interface Technical Training Phoenix, AZ 20347: Enabling and Managing Office 365    

Using Navigation Controls in a Collaboration Site in SharePoint

0 361 1

In this SharePoint training video, I want to talk about the Navigation Controls in SharePoint. They tend to fall into two kind of different categories; one with the navigation controls in a typical Collaboration Site such as a Team Site or a Project Site. These are Sites that are based on the Team Site Template … Continue reading Using Navigation Controls in a Collaboration Site in SharePoint

Write a Comment

Share your thoughts...

Please fill out the comment form below to post a reply.