Open-source nhtmlfilter helps you filter HTML dangerous scripts to prevent XSS attacks

Source: Internet
Author: User

Have you been worried about how to prevent XSS attacks? Try nhtmlfilter. I think it is what you want ..

Recently, a new small company is very weak in. NET web development. The underlying framework and basic library are not perfect. It is also an Internet application, so security always needs to be considered. One small problem I want to solve today is to filter out the scripts in the HTML text uploaded by the user. I checked on the Internet and found no suitable C #-based processing. In Java projects, I may choose jsoup, htmlfilter to deal with HTML dangerous scripts (in fact, I used to do Java Development). In desperation, I will refer to the htmlfilter of Java version.CodeWrite the C # version.

Usage

 
Nhtmlfilter target = new nhtmlfilter (); string input = "<div> DD </div> <a id = \" testid \ "href = \" http://code.google.com/p/nhtmlfilter\ "> nhtmlfilter </a> "; string expected = "DD <a href = \" http://code.google.com/p/nhtmlfilter\ "> nhtmlfilter </a>"; string actual; actual = target. filter (input );

Applicable labels and tag attributesProgramPreparation and simple encapsulation can be used for your project.

Code browsing address

Https://code.google.com/p/nhtmlfilter/source/browse/trunk/NHtmlFilter/NHtmlFilter.cs

Code project ..
Https://code.google.com/p/nhtmlfilter/downloads/list (Google Code may be walled out ..)

Download from this site

Http://files.cnblogs.com/weirhp/NHtmlFilter1.0.rar

Other versions written by others: Java PHP

Download and use it. It is released based on the MIT protocol .. Just be happy .. If you have any questions, study them together.

This article is original to the author.

Http://www.cnblogs.com/weirhp/archive/2011/10/03/NHtmlFilter.html
Please repost the famous source. Thank you.
Weirhp@gmail.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.