Skip to content
KitploitKITPLOIT
OutilsExploitsBlog
Log in
Soumettre
OutilsExploitsBlog
Soumettre

Outils de Hacking, PenTest et Cybersécurité pour votre Arsenal de Sécurité !

Kitploit est un répertoire d'outils de hacking, de cybersécurité et de pentesting. Découvrez les dernières mises à jour des projets pour trouver des vulnérabilités, analyser des systèmes, automatiser les tests et renforcer votre sécurité.

FluxContactConfidentialité© 2026 Kitploit

Répertoire d'outils

Catégories

Voir toutes les catégories
Loading categories
HtmlSanitizer — .NET library that sanitizes HTML fragments and documents using AngleSharp, stripping XSS vectors via configurable allowlists for tags, attributes, CSS properties, and URI schemes. | Kitploit
Outils/GitHubGitHub/mganss/htmlsanitizer
Defensive ToolsCode AnalysisWeb Application ExploitationWeb Security
GitHubmganss/htmlsanitizer

HtmlSanitizer

.NET library that sanitizes HTML fragments and documents using AngleSharp, stripping XSS vectors via configurable allowlists for tags, attributes, CSS properties, and URI schemes.

Voir le dépôt
1.7k23227 nov. 2026Vérifié par Kitploit
Partager
Contenu non disponible dans la langue demandée. Affichage de la version anglaise.

HtmlSanitizer

NuGet version Build status Coverage Sonarcloud Quality Gate

netstandard2.0 net46 net8.0

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.
  • Configure allowed URI schemes through the property AllowedSchemes. All other URIs will be stripped.
  • Configure HTML attributes that contain URIs (such as "src", "href" etc.) through the property UriAttributes.
  • Configure HTML attributes that contain a list of URIs (such as "srcset", "ping") through the property UriListAttributes. Every entry is checked separately.
  • Provide a base URI that will be used to resolve relative URIs against.
  • Sanitize a fragment for the element it will be inserted into, rather than for <body>, through SanitizeFragment(). This keeps markup such as a lone <th> that is only valid deeper in the tree.
  • Cancelable events are raised before a tag, attribute, or style is removed.
  • All of the above can be set in one go by passing an HtmlSanitizerOptions object to the constructor. new HtmlSanitizerOptions() starts pre-populated with the same defaults as new HtmlSanitizer(), so you only need to set what you want to change; use HtmlSanitizerOptions.Empty() instead if you want a blank slate, see Configuring with HtmlSanitizerOptions.

Usage

Install the HtmlSanitizer NuGet package. Then:

using Ganss.Xss;
var sanitizer = new HtmlSanitizer();
var html = @"<script>alert('xss')</script><div onload=""alert('xss')"""
    + @"style=""background-color: rgba(0, 0, 0, 1)"">Test<img src=""test.png"""
    + @"style=""background-image: url(javascript:alert('xss')); margin: 10px""></div>";
var sanitized = sanitizer.Sanitize(html, "https://www.example.com");
var expected = @"<div style=""background-color: rgba(0, 0, 0, 1)"">"
    + @"Test<img src=""https://www.example.com/test.png"" style=""margin: 10px""></div>";
Assert.Equal(expected, sanitized);

There's an online demo, plus there's also a .NET Fiddle you can play with.

More example code and a description of possible options can be found in the Wiki.

Configuring with HtmlSanitizerOptions

A sanitizer can also be configured in one go by passing an HtmlSanitizerOptions object to the constructor. Every collection on HtmlSanitizerOptions starts out pre-populated from HtmlSanitizerDefaults, the same defaults new HtmlSanitizer() uses, so you only need to set what you want to change:

var options = new HtmlSanitizerOptions();
options.AllowedTags.Clear();
options.AllowedTags.Add("a");
options.AllowedTags.Add("img");
// AllowedAttributes, UriAttributes, AllowedSchemes, etc. remain at their defaults
var sanitizer = new HtmlSanitizer(options);

Reassigning a collection outright, rather than mutating the pre-populated one, still replaces the default for that property alone - the other properties are unaffected:

var sanitizer = new HtmlSanitizer(new HtmlSanitizerOptions
{
    AllowedTags = new HashSet<string> { "a", "img" },
    AllowedAttributes = new HashSet<string> { "href", "src" },
    // UriAttributes and AllowedSchemes are not reassigned here, so they keep their defaults
});

If you want a blank slate instead - nothing allowed until you add it - start from HtmlSanitizerOptions.Empty():

var options = HtmlSanitizerOptions.Empty();
options.AllowedTags.Add("a");
options.AllowedAttributes.Add("href");
var sanitizer = new HtmlSanitizer(options);
// UriAttributes is empty, so href is *not* screened against AllowedSchemes
// <a href="javascript:alert(1)">click</a> is preserved as-is

UriAttributes is a screening list rather than an allow list: an attribute not in it is not treated as carrying a URI at all, so its value is never checked against AllowedSchemes. This matters most when building an allowlist from Empty(), where it's easy to allow href without also adding it to UriAttributes. And UriAttributes and AllowedSchemes need to be set together - screening an attribute against an empty scheme set drops every absolute URI, valid https ones included:

var options = HtmlSanitizerOptions.Empty();
options.AllowedTags.Add("a");
options.AllowedAttributes.Add("href");
options.UriAttributes.Add("href");
// AllowedSchemes left empty - every absolute URI is dropped
var sanitizer = new HtmlSanitizer(options);
// <a href="https://example.com">ok</a> becomes <a>ok</a>

Tags allowed by default

a, abbr, acronym, address, area, article, aside, b, bdi, big, blockquote, body, br, button, caption, center, cite, code, col, colgroup, data, datalist, dd, del, details, dfn, dir, div, dl, dt, em, fieldset, figcaption, figure, font, footer, form, h1, h2, h3, h4, h5, h6, head, header, hr, html, i, img, input, ins, kbd, keygen, label, legend, li, main, map, mark, menu, menuitem, meter, nav, ol, optgroup, option, output, p, pre, progress, q, rp, rt, ruby, s, samp, section, select, small, span, strike, strong, sub, summary, sup, table, tbody, td, textarea, tfoot, th, thead, time, tr, tt, u, ul, var, wbr

Télécharger l’outil

Outils similaires

  • wazuh

    Plateforme XDR et SIEM open-source pour la détection des menaces, l'analyse des journaux, la surveillance de l'intégrité des fichiers, l'évaluation des vulnérabilités et la gestion de la conformité sur les points de terminaison et les charges de travail cloud.

  • suricata

    Moteur open-source IDS/IPS/NSM réseau pour l'inspection du trafic en temps réel, la détection et la prévention d'intrusions, l'analyse des protocoles et la chasse aux menaces basée sur des règles.

  • zeek

    Zeek est un puissant framework d'analyse réseau qui est très différent du système IDS typique que vous connaissez peut-être.

Populaires

Voir tout →

Découvrez les outils les plus utilisés par notre communauté.

  • 1

    Callisto

    jetp1ane/callisto

    Outil automatisé d'analyse de vulnérabilités binaires qui décompile des exécutables via Ghidra, analyse du pseudo-code C avec Semgrep, et valide les résultats en utilisant GPT-3.5-Turbo pour réduire les faux positifs.

    2.2k
  • 2

    ghostlock-app

    yukonga/ghostlock-app

    # Application d'exécution en un clic GhostLock (CVE-2026-43499)

    840
  • 3

    DFRoot

    a2333c/dfroot

    Outil de root Android pour Samsung Galaxy S25 Ultra (SM-S938B) qui enchaîne DirtyFrag CVE-2026-43284 et CVE-2026-43499 pour obtenir le root automatiquement au démarrage via KernelSU.

    451
  • 4

    ARTEX

    baarai/artex

    Plateforme autonome de tests d'intrusion multi-agents basée sur des LLM, avec agents planificateur/ouvrier, graphes d'actifs et d'exploration, enregistrement du trafic MITM et retest des vulnérabilités.

    378
  • 5

    OsintHunter

    letox4/osinthunter

    🎯 La boîte à outils OSINT ultime : graphe d'enquête, notation de confiance, familles d'alias, carte, chronologie et rapports. 49 modules, plus de 400 sites, aucune clé API requise.

    352
  • 6

    wifit3

    derv82/wifit3

    Wifite mais uniquement USB et multiplateforme.

    333

Explorer tous les outils

Parcourez notre collection d'outils

Voir tous les outils →