Model binding fails due to try parse whitespaced string to decimal property and exposing sensitive info to client.
Steps to reproduce the behavior:
[ApiController]
public class ProductsController
{
[HttpPost]
public IActionResult Post([FromBody]CreateProductDto model)
{
model.Id = await service.CreateProduct(model);
return CreatedAtRoute(
routeName: "GetProduct",
routeValues: new { id = model.Id },
value: model
);
}
}
public class CreateProductDto
{
[Required(ErrorMessage = "Invalid value")]
public decimal totalPrice { get; set;}
public int count { get; set; }
}
And posting json:
{
"totalPrice": " ",
"count": " "
}
And the following model state error is returned:
totalPrice: ["Could not convert string to decimal: . Path 'totalPrice', line 1, position 71."]
0: "Could not convert string to decimal: . Path 'totalPrice', line 1, position 71."
Expected more user friendly message which can be exposed to api client when validating input.
NET Core SDK (reflecting any global.json):
Version: 2.1.701
Commit: 8cf7278aa1
Runtime Environment:
OS Name: fedora
OS Version: 30
OS Platform: Linux
RID: fedora.30-x64
Base Path: /usr/share/dotnet/sdk/2.1.701/
Host (useful for support):
Version: 2.1.12
Commit: ccea2e606d
.NET Core SDKs installed:
2.1.701 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.12 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.12 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.12 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Thanks for contacting us, @gmarokov.
We'll look into providing a mechanism for sanitizing these exceptions after 3.0 release.
@mkArtakMSFT Is there any current workaround for this issue?
Thanks for contacting us, @gmarokov.
We'll look into providing a mechanism for sanitizing these exceptions after 3.0 release.
Any update now?
Any update now?
@mkArtakMSFT Any update now?
Still no fix for this?
Most helpful comment
Thanks for contacting us, @gmarokov.
We'll look into providing a mechanism for sanitizing these exceptions after 3.0 release.