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

Cable Testers and How to Use them in Network Environments

0 627 1

This content is from our CompTIA Network + Video Certification Training Course. Start training today! In this video, CompTIA Network + instructor Rick Trader demonstrates how to use cable testers in network environments. Let’s look at some tools that we can use to test our different cables in our environment. Cable Testers Properly Wired Connectivity … Continue reading Cable Testers and How to Use them in Network Environments

Agile Methodology in Project Management

0 187 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 Lists and Libraries in SharePoint

0 1433 4

In this SharePoint training video, we’re going to cover creating Lists and Libraries. Wherever you create your List or Library, wherever you want to create it, you want to be there. You want to be in a particular Site that’s in a Site Collection. If I wanted to add a List or Library to this … Continue reading Creating Lists and Libraries in SharePoint

Write a Comment

Share your thoughts...

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