Giter Site home page Giter Site logo

johnkevincheng / markupsanity Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 70 KB

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

License: MIT License

C# 98.76% ASP.NET 1.24%
sanitize-html cleanup xss-filter xss-poc cross-site-scripting cross-site htmlagilitypack

markupsanity's Introduction

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

markupsanity's People

Contributors

johnkevincheng avatar

Watchers

 avatar  avatar

Forkers

rafaelsc

markupsanity's Issues

Bug - Cant set a empty list of Attributes

When you set an empty list of white list tags, attributes or scriptable the Sanitizer don't respect the empty list and use the default white list.

That made impossible to remove all attributes.

.net standard

We like this project, but its dependency on .net framework is a hindrance to those of us that have migrated on to .net core. We'd like to use it as a nuget package, but we're unable to use it as-is. This project is certainly able to utilize .net standard rather than .net 3.5, but I understand why you wouldn't upgrade if you have internal projects that are still running on framework 3.5 - there is no .net standard compatibility for that version of the framework. Is that the case? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.