OWASP / json-sanitizer

Given JSON-like content, The JSON Sanitizer converts it to valid JSON.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Json Sanitization for C#

neerajknextgen opened this issue · comments

Do you have C# version for this ?

The new (3.x) netcore JsonSerializer comes with an optional JavaScriptEncoder that you could use.
In my case, I set it at the controller level when configuring the services and it does the job. I tested it using various ways of injecting HTML/JS and it seemed to work well.

Just an example:

services.AddControllers().AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Default;
            });

Anyway, you may find it useful.

Cheers!

commented

Hi, Can anyone help me to sanitize my json in Asp.Net Core

Hi guys, we wrapped this package into NuGet package and published. JsonSanitizer is now available on C#.