databinding.WebSecurity.HtmlSanitizer.AspNetCore
2026.11.18.3
Prefix Reserved
dotnet add package databinding.WebSecurity.HtmlSanitizer.AspNetCore --version 2026.11.18.3
NuGet\Install-Package databinding.WebSecurity.HtmlSanitizer.AspNetCore -Version 2026.11.18.3
<PackageReference Include="databinding.WebSecurity.HtmlSanitizer.AspNetCore" Version="2026.11.18.3" />
<PackageVersion Include="databinding.WebSecurity.HtmlSanitizer.AspNetCore" Version="2026.11.18.3" />
<PackageReference Include="databinding.WebSecurity.HtmlSanitizer.AspNetCore" />
paket add databinding.WebSecurity.HtmlSanitizer.AspNetCore --version 2026.11.18.3
#r "nuget: databinding.WebSecurity.HtmlSanitizer.AspNetCore, 2026.11.18.3"
#:package databinding.WebSecurity.HtmlSanitizer.AspNetCore@2026.11.18.3
#addin nuget:?package=databinding.WebSecurity.HtmlSanitizer.AspNetCore&version=2026.11.18.3
#tool nuget:?package=databinding.WebSecurity.HtmlSanitizer.AspNetCore&version=2026.11.18.3
databinding.WebSecurity.HtmlSanitizer.AspNetCore
This library provides ActionFilter for MVC and API controller to detect and remove malicious inputs with databinding.WebSecurity.HtmlSanitizer.
For fields such as passwords, the check can be deactivated with the [SanitizerDisabled] attribute. This guarantees that passwords are not converted, especially special characters such as &, < and >.
Getting started
Prerequisites
- .NET 8 or later
- Visual Studio 2022/Code or later
Installation
To install the library, you can use the NuGet package manager:
dotnet add package databinding.WebSecurity.HtmlSanitizer.AspNetCore
Usage
The package provides the ActionFilter HtmlSanitizerCheckActionFilter and HtmlSanitizerCheckAsyncActionFilter.
Here's a basic example of how to use it:
[HtmlSanitizerCheckActionFilter]
public class HomeController : Controller
{
...
}
The filter can be configured globally for all controllers in Startup.cs or Program.cs.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews(
o => o.Filters.Add<HtmlSanitizerCheckActionFilter>());
Feature flags
In addition to HTML sanitizing, the filters clean up user input that is not visible to the user but can cause harm or problems in downstream processing.
| Flag | Default | Purpose |
|---|---|---|
RemoveInvisibleChars |
true |
Removes invisible characters that can be used to bypass validation, spoof content or break downstream processing (see below). Includes the PDF special characters (former PDF cleanup). |
RemoveEmojis |
false |
Removes emojis including their sequences (skin tones, ZWJ combinations, flags, keycaps), e.g. for fields that are printed, exported or processed by systems without emoji support. |
The existing configuration is unchanged: the constructors and the encodingEnabled parameter remain the same, the flags are optional.
Invisible characters
| Kind | Characters | Purpose |
|---|---|---|
PdfSpecialCharacter |
U+0000–U+0004, U+000F, U+0013, U+0019 | Control characters typically copied from PDF documents, which break PDF generation. |
Control |
other C0/C1 control characters (except \t, \n, \r) |
Not printable, can break processing. |
ZeroWidth |
U+200B, U+2060–U+2064, U+FEFF, U+180E | Hide content, e.g. java\u200Bscript: to bypass filters. |
Joiner |
U+200C, U+200D outside emoji sequences or non-Latin scripts | Hide content between letters. |
Bidi |
U+202A–U+202E, U+2066–U+2069, U+200E, U+200F, U+061C | Reverse the display order of text ("Trojan Source", e.g. invoice\u202Efdp.exe). |
Tag |
U+E0000–U+E007F outside flag emojis | Invisible ASCII text ("ASCII smuggling", e.g. hidden prompts for AI systems). |
VariationSelector |
chained or standalone U+FE00–U+FE0F, U+E0100–U+E01EF | Hidden data attached to a character ("emoji smuggling"). |
Filler |
U+034F, U+115F, U+1160, U+17B4, U+17B5, U+2800, U+3164, U+FFA0 | Look like blanks, used for "empty" names or spoofing. |
SoftHyphen |
U+00AD | Invisible hyphen, disturbs search and comparison. |
LineSeparator |
U+2028, U+2029 | Replaced by \n, break JavaScript/JSON processing. |
Format |
U+206A–U+206F, U+FFF9–U+FFFB, U+1D173–U+1D17A | Deprecated or invisible formatting characters. |
Legitimate usages are preserved: emoji sequences (ZWJ, variation selectors, skin tones, flags), ZWNJ in non-Latin scripts (e.g. Persian, Hindi) and ideographic variation selectors after CJK characters.
The characters are removed before sanitizing, so they cannot be used to bypass the HTML sanitizer.
Configuration
Per controller or action via attribute properties:
[HtmlSanitizerCheckActionFilter(RemoveEmojis = true)]
public class HomeController : Controller
{
...
}
Globally for all filters (also for Filters.Add<HtmlSanitizerCheckActionFilter>()) in Program.cs or Startup.cs:
HtmlSanitizerRichtextDefauls.RemoveInvisibleChars = true;
HtmlSanitizerRichtextDefauls.RemoveEmojis = true;
builder.Services.AddControllersWithViews(
o => o.Filters.Add<HtmlSanitizerCheckActionFilter>());
Or for a filter instance:
builder.Services.AddControllersWithViews(
o => o.Filters.Add(new HtmlSanitizerCheckActionFilter { RemoveEmojis = true }));
Logging
Changes are logged via ILogger<InputSanitizer> if HtmlSanitizerRichtextDefauls.IsLoggingEnabled is true (default):
| Change | Level | Message |
|---|---|---|
Tags or attributes removed (Markup) |
Warning | Sanitizing string from ... to ... |
Text or encoding differences, e.g. \r\n, \r, whitespace, HTML entities (Text) |
Information | Normalizing string from ... to ... |
Invisible characters removed, incl. PDF special characters (InvisibleChars) |
Information | Removing invisible characters (kinds) from ... to ... |
Emojis removed (Emojis) |
Information | Removing emojis (count) from ... to ... |
If several changes occur in one string, removed invisible characters and emojis are logged separately; removed tags or attributes are always logged as warning. Only Markup and Text changes mark the content as sanitized (HttpContext.IsContentSanitized()).
The HtmlSanitizerRichtextDefauls class is available for additional configurations. This enables additional settings for AllowedAtRules, AllowedSchemes, AllowedTags, AllowedAttributes, AllowedCssProperties, UriAttributes and AllowedClasses via static properties.
Configurable via Program.cs or Startup.cs.
HtmlSanitizerRichtextDefauls.AllowedTags.Add("img");
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews(
o => o.Filters.Add<HtmlSanitizerCheckActionFilter>());
To avoid unwanted side effects for special cases such as passwords, the logic can be deactivated with the SanitizerDisabled attribute on a property. The property is then neither checked nor logged, neither on the model nor in the ModelState, so passwords never appear in the log.
public class LoginModel
{
...
[SanitizerDisabled]
public string Password { get; set; }
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
- databinding.WebSecurity.HtmlSanitizer (>= 2026.11.18.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.11.18.3 | 79 | 11/18/2026 |
| 2026.11.18.2 | 76 | 11/18/2026 |
| 2026.11.11.1 | 99 | 11/11/2026 |
| 2026.10.5.2 | 128 | 10/5/2026 |
| 2026.9.1.1 | 138 | 9/1/2026 |
| 2026.7.22.1 | 158 | 7/22/2026 |
| 2025.7.23.2 | 695 | 7/23/2025 |
| 2025.7.23.1 | 661 | 7/23/2025 |
| 2025.7.22.3 | 634 | 7/22/2025 |
| 2025.7.18.3 | 234 | 7/18/2025 |
| 2025.4.28.1 | 280 | 4/28/2025 |
| 2025.4.16.3 | 321 | 4/16/2025 |
| 2025.4.16.1 | 294 | 4/16/2025 |
| 2025.4.14.1 | 316 | 4/14/2025 |
| 2025.4.3.1 | 277 | 4/3/2025 |
| 2025.4.1.1 | 288 | 4/1/2025 |
| 2025.3.26.1 | 563 | 3/26/2025 |
| 2025.3.24.1 | 588 | 3/24/2025 |
| 2025.3.21.1 | 219 | 3/21/2025 |
| 2025.2.18.1 | 220 | 2/18/2025 |