Xabaril / AspNetCore.Diagnostics.HealthChecks

Enterprise HealthChecks for ASP.NET Core Diagnostics Package
Apache License 2.0
4.11k stars 800 forks source link

HealthChecker fails to deserialize a valid JSON string #2287

Open kikaragyozov opened 3 months ago

kikaragyozov commented 3 months ago

If you have written the following json string:

"{ \"msg\": \"Hello World!\\n\"}"

For a webhook's payload in your appsettings.json configuration file, the library will fail to deserialize it, whereas if you pass the above string to System.Text.Json.JsonSerializer, it will successfully parse it.

After debugging, the issue occurs here: https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/blob/76c1ad21552f65e8d8dfdd6a2107a2c6eaf25794/src/HealthChecks.UI/Middleware/UIWebHooksApiMiddleware.cs#L34

The Regex.Unescape call turns the above into an invalid json string. Why are we escaping exactly?

Currently it's impossible to define a new line in the JSON webhook payload object, until the above is somehow addressed.

The exception is thrown when you go to the "Webhooks" section in the UI.