SgmlSanitizer 1.0.0
See the version list below for details.
dotnet add package SgmlSanitizer --version 1.0.0
NuGet\Install-Package SgmlSanitizer -Version 1.0.0
<PackageReference Include="SgmlSanitizer" Version="1.0.0" />
paket add SgmlSanitizer --version 1.0.0
#r "nuget: SgmlSanitizer, 1.0.0"
// Install SgmlSanitizer as a Cake Addin #addin nuget:?package=SgmlSanitizer&version=1.0.0 // Install SgmlSanitizer as a Cake Tool #tool nuget:?package=SgmlSanitizer&version=1.0.0
SgmlSanitizer
A sanitizer to remove elements and attributes from SGML based text files, such as HTML and XML. Note that this is a very simple implementation, but by using whitelists and a naïve URL detection implementation XSS may be prevented. Use at your own risk though.
Usage
To sanitize some simple HTML to remove all attributes and only keep the original HTML tag (this is inserted if not provided) and A tags:
string html = "<html><a href=\"https://url\">Keep me</a><p><a>Don't keep me</a></p></html>";
ListSanitiationHandler list = new ListSanitationHandler();
list.Elements.Add("html");
list.Elements.Add("a");
Sanitizer sanitizer = new Sanitizer();
sanitizer.Handlers.Add(list);
string cleanHtml = sanitizer.Sanitize(html);
Console.WriteLine(cleanHtml);
This outputs:
<html><a href="https://url">Keep me</a></html>
The list sanitation handler can be used to whitelist or blacklist elements, attributes and element specific attributes. The UrlAttributeHandler
will remove attributes which contain '.' or '/', as the definition of an url is very broad.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- Microsoft.Xml.SgmlReader (>= 1.8.21)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.