Repository navigation
PowerCSharo - Sanitization Feature v1.0.0 — Log Injection, Path Traversal, Sensitive Data & Regex Injection Protection
LatestOverview
This release introduces the Sanitization pluggable feature family: a framework-agnostic sanitization
engine plus Features Framework wiring, covering four security concerns in untrusted input handling:
- Log injection (CWE-117)
- File-path traversal (CWE-22)
- Sensitive-data exposure (CWE-200)
- Regex-injection / ReDoS (CWE-400 / CWE-730)
The engine was migrated and de-branded from an internal reference implementation, then refactored
from a single 1800+ line class into concern-based files for maintainability. This is a new,
independently versioned package family (PowerCSharpFeatureSanitizationVersion), alongside the
existing Core, Compatibility, Features, and Cache families.
No breaking changes. Nothing in this release modifies existing shipped packages' public APIs.
New Packages
PowerCSharp.Feature.Sanitization.Abstractions v1.0.0
Framework-agnostic engine, contracts, and safe-off NoOp implementation. Targets netstandard2.0
and net8.0, so it can be used standalone with no dependency injection or configuration required
— including from .NET Framework consumers via a hot-path logging call site.
SanitizationEngine— static engine, split by concern:SanitizationEngine.LogInjection.cs— control-character removal/replacement/encoding strategiesSanitizationEngine.FilePath.cs— allowlist validation (recommended) and legacy pattern-stripping modesSanitizationEngine.SensitiveData.cs— pattern-based detection and masking of tokens, secrets, credentials, URLs, and file pathsSanitizationEngine.RegexInjection.cs— pattern-safety validation: length, compile-with-timeout, complexity scoring, and configurable rejection of catastrophic-backtracking shapes
SanitizationExtensions— string extension methods (SanitizeForLog,SanitizeForFilePath,SanitizeForSensitiveData,SanitizeForRegexInjection,*WithDetailsvariants,Mask)SanitizationSettings— full configurable surface, secure defaults throughoutSanitizationResult/SensitiveDataResult— immutable result types withUnchanged/Modified/RejectedfactoriesISanitizationService/ISanitizationSettingsProvider— DI-facing contractsNoOpSanitizationService— safe-off floor
PowerCSharp.Feature.Sanitization v1.0.0
Features Framework module, options, and DI/ASP.NET Core wiring.
SanitizationFeatureModule— auto-discoverable; registers the real service when enabled, NoOp when disabled. Unlike the Cache family, there is no separate provider package, so this module decides active-vs-NoOp directly.SanitizationFeatureOptions— bound fromPowerFeatures:Sanitization, mirroring the full settings surfaceSanitizationService/SanitizationSettingsProvider— DI implementation, bridging bound options into the engineAddSanitizationFeature()— explicit registration extensionConfigureSanitizationEngine()— bridges DI-resolved settings into the static engine, so extension-method call sites reflect host configuration too
Testing
New PowerCSharp.Feature.Sanitization.Tests project (xUnit) covering:
- Log injection: control-character strategies, tab preservation, disabled-flag passthrough, length limiting
- File-path traversal: strict allowlist validation (traversal, absolute paths, reserved device names, extension/base-directory allowlists), legacy pattern-stripping mode, correlation-id sanitization
- Sensitive-data masking: key-value pairs, bearer tokens, API keys, file paths, strictness levels, custom mask characters
- Regex injection: safe-pattern acceptance, syntax rejection, nested-quantifier rejection (and explicit opt-in), pattern-length limits, individually disallowed constructs
- Extension methods and result-type value equality
- Feature DI wiring: explicit registration, options binding, NoOp behavior, static-engine bridging
Fixed
Found while writing the test suite: MaskKeyBasedValues's handling of the generic
password/token/secret/etc. key-value pattern referenced a regex capture group that didn't
exist, which always evaluated to an empty mask and silently left the raw secret value in the
sanitized output (with the key name dropped). The same defect exists in the original reference
implementation this was migrated from. Fixed by reconstructing the key prefix the same way the
other key-based heuristics in the same method already do — masking now works correctly for this
pattern class.
Sample Application
WebSample now references the Features Framework for the first time and demonstrates both shipped
feature families:
GET /demo/cache— cache miss followed by a set/hit round-trip via the BitFaster providerGET /demo/sanitization— all four sanitization concerns against representative malicious input
Installation
dotnet add package PowerCSharp.Feature.Sanitization.Abstractions
dotnet add package PowerCSharp.Feature.SanitizationConfiguration
{
"PowerFeatures": {
"Sanitization": {
"Enabled": true,
"EnableLogSanitization": true,
"EnableFilePathSanitization": true,
"EnableSensitiveDataDetection": true,
"EnableRegexSanitization": true
}
}
}Documentation
- Package readmes:
PowerCSharp.Feature.Sanitization.Abstractions,PowerCSharp.Feature.Sanitization - API reference:
docs/PowerCSharp.Feature.Sanitization.md - CHANGELOG: see the
Sanitization 1.0.0section
Versioning
This release establishes PowerCSharpFeatureSanitizationVersion (starting at 1.0.0) as a new
independent version family, alongside a sanitization package-family option in the release
workflow. Future Sanitization-only changes will bump this family independently of Core, Features,
and Cache.