Sanitize 400 error messages in GlobalExceptionHandler and validation filters to use static strings. This change improves consistency and prevents leaking internal exception details. Updated tests to reflect new error messages for JSON parsing and bad request scenarios.
ci/woodpecker/push/01-test Pipeline failed
ci/woodpecker/push/02-build-push unknown status

This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-06-25 19:02:25 +03:00
parent 7ed780b063
commit 01d7e7d584
12 changed files with 209 additions and 38 deletions
@@ -6,6 +6,9 @@ namespace SatelliteProvider.Api;
public sealed class GlobalExceptionHandler : IExceptionHandler
{
private const string JsonFieldErrorMessage = "The field value is invalid.";
private const string BadRequestDetailMessage = "The request could not be processed.";
private readonly ILogger<GlobalExceptionHandler> _logger;
public GlobalExceptionHandler(ILogger<GlobalExceptionHandler> logger)
@@ -89,7 +92,7 @@ public sealed class GlobalExceptionHandler : IExceptionHandler
{
Status = badRequest.StatusCode,
Title = "Bad Request",
Detail = badRequest.Message,
Detail = BadRequestDetailMessage,
};
await httpContext.Response.WriteAsJsonAsync(
@@ -107,13 +110,10 @@ public sealed class GlobalExceptionHandler : IExceptionHandler
if (current is JsonException jsonEx)
{
var path = NormalizeJsonPath(jsonEx.Path);
var message = string.IsNullOrEmpty(jsonEx.Message)
? "Invalid JSON."
: jsonEx.Message;
return new Dictionary<string, string[]>
{
[path] = new[] { message }
[path] = new[] { JsonFieldErrorMessage }
};
}