HtmlSanitizer is a .NET library for cleaning HTML fragments and documents from constructs that can lead to XSS attacks. It uses AngleSharp to parse, manipulate, and render HTML and CSS. Because HtmlSanitizer is based on a robust HTML parser it can also shield you from deliberate or accidental "tag poisoning" where invalid HTML in one fragment can corrupt the whole document leading to broken layout or style. In order to facilitate different use cases, HtmlSanitizer can be customized at several levels. Configure allowed HTML tags through the property AllowedTags. All other tags will be stripped. Configure allowed HTML attributes through the property AllowedAttributes. All other attributes will be stripped. Configure allowed CSS property names through the property AllowedCssProperties. All other styles will be stripped. Configure allowed CSS at-rules through the property AllowedAtRules. All other at-rules will be stripped.

Features

  • Configure allowed HTML tags through the property AllowedTags. All other tags will be stripped
  • Cancelable events are raised before a tag, attribute, or style is removed
  • Configure HTML attributes that contain URIs (such as "src", "href" etc.) through the property UriAttributes
  • Configure allowed URI schemes through the property AllowedSchemes
  • Configure allowed CSS property names through the property AllowedCssProperties
  • Provide a base URI that will be used to resolve relative URIs against

Project Samples

Project Activity

See All Activity >

Categories

HTML/XHTML

License

MIT License

Follow HtmlSanitizer

HtmlSanitizer Web Site

Other Useful Business Software
Build AI Apps with Gemini 3 on Vertex AI Icon
Build AI Apps with Gemini 3 on Vertex AI

Access Google’s most capable multimodal models. Train, test, and deploy AI with 200+ foundation models on one platform.

Vertex AI gives developers access to Gemini 3—Google’s most advanced reasoning and coding model—plus 200+ foundation models including Claude, Llama, and Gemma. Build generative AI apps with Vertex AI Studio, customize with fine-tuning, and deploy to production with enterprise-grade MLOps. New customers get $300 in free credits.
Try Vertex AI Free
Rate This Project
Login To Rate This Project

User Reviews

Be the first to post a review of HtmlSanitizer!

Additional Project Details

Operating Systems

Windows

Programming Language

C#

Related Categories

C# HTML XHTML

Registered

2023-04-27