Skip to content

Use HtmlAgilityPack parser to sanitize html text against unrecognized tags and attributes.

License

Notifications You must be signed in to change notification settings

johnkevincheng/MarkupSanity

Repository files navigation

MarkupSanity

Use Html Agility Pack parser to sanitize html text against unrecognized tags and attributes.

As with any input processing, Markup Sanity adds performance degradations to the process, and in this case, quite significant due to the dependence on parsing from Html Agility Pack.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

At its simplest usage, MarkupSanity is an extension method for Strings and validates the value against a pre-defined set of default whitelisted tags and attrbutes.

As an example,

String inputValue = "<a href=\"javascript:alert('Gotcha again!');\" onclick=\"javascript:alert('Gotcha!');\">Click Me</a>";
String cleanValue = inputValue.SanitizeHtml();
Console.Writeline(cleanValue);

The output shall be:

<a>Click Me</a>

The onclick attribute is removed due to its use for scripting. But while href is a valid attribute, its usage to trigger a Javascript alert is considered dangerous and thus removed.

You may refer to the wiki for more advanced usage information.

Prerequisites

Installing

Add the MarkupSanity project to your .NET solution, and have your relevant projects reference this class library to be able to access the classes and extension methods needed to process html texts.

Alternatively, you may download the dll package directly from Nuget here.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

Use HtmlAgilityPack parser to sanitize html text against unrecognized tags and attributes.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published