Configurable sanitizer for XML and JSON through extension method.
- Default sanitizer to replace password value
- Sanitize with options
- Default value replacer
- Add property to sanitize value
- .NET Core 3.1
- Visual Studio or VS Code
- Go to Tools and select Manage Nuget Packages and Search for JSanitizer library
Install-Package JSanitizer -Version 3.0.1
Extension:
.SanitizeJsonValue(configPath)
.SanitizeXmlValue(configPath)
.SanitizeJsonValue(options)
.SanitizeXmlValue(options)
- Create JSON configuration file under your project and follow the object schema below.
{
"DefaultMaskValue": "#",
"ConfigurationValue": [
{
"id": 1,
"XmlMask": {
"MaskValue": "#",
"IsFullMasking": false,
"Sensitivity": [
{
"TargetProperties": [
"Password",
"password",
"PASSWORD"
],
"Positions": {
"Left": 1,
"Center": 1,
"Right": 1
}
}
]
},
"JsonMask": {
"MaskValue": "#",
"IsFullMasking": false,
"Sensitivity": [
{
"TargetProperties": [
"Password",
"password",
"PASSWORD"
],
"Positions": {
"Left": 3,
"Center": 3,
"Right": 3
}
}
]
}
}
]
}
note: It will throw an exception if you use the default json or xml extension methods without providing default json configurations.
remarks: You can add more properties under Sensitivity for value masking.
- Sanitize without options
[HttpGet, Route("GetWithJsonConfiguration")]
public IActionResult Get()
{
string configDir = $"{Directory.GetCurrentDirectory()}\\JSOptions\\SanitizerOptions.json";
Data data = new Data()
{
JsonArrayResult = "[{\"password\":\"password@412\", \"data\": \"sample\" }]".SanitizeJsonValue(configDir),
Name = "{\"name\":\"John\", \"age\":30, \"password\":\"password@123\" }".SanitizeJsonValue(configDir),
XMLResult = _xmlValue.SanitizeXmlValue(configDir)
};
return Ok(data);
}
- Sanitize withoptions
[HttpGet, Route("GetWithClassConfigurations")]
public IActionResult GetWithOptions()
{
Data data = new Data()
{
XMLResult = _xmlValue.SanitizeXmlValue(new XmlMask()
{
MaskValue = "#",
IsFullMasking = false,
Sensitivity = new List<Sensitivity>()
{
new Sensitivity()
{
TargetProperties = new List<string> {
"Password",
"password",
"PASSWROD"
},
Positions = new MaskPosition ()
{
Left = 3,
Center = 2,
Right = 2
}
}
}
})
};
return Ok(data);
}
KBANK QR Code:
Ever tired of getting bugs yet too difficult to solve? Worry no more, create an issue (just make sure it isn’t an existing one) and i will do my best to fix it. Great ideas are welcome too; just make an issue with the Proposal or a PR from your Fork.
See in nuget version history
Copyright (c) 2020 Joever Monceda
Linkedin: Joever Monceda
Medium: Joever Monceda
Twitter @_EthanHunt07
Facebook: Ethan Hunt