I am creating a RESTful service using ASP.NET web API.
My problem is with HttpErrors, which the web API returns to the user when something goes wrong (e.g. 400 Bad Request or 404 Not Found).
The problem is that I don't want to receive a serialized HttpError in the response content, as it sometimes provides too much information, therefore it violates the OWASP security rules, for example:
Request:
http:
As an answer, of course, I get 400, but with the following content information:
{ "$id": "1", "Message": "The request is invalid.", "MessageDetail": "The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'MyNamespaceAndMethodHere(Int32)' in 'Service.Controllers.MyController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter." }
Something like this not only indicates that my WebService is based on ASP.NET WebAPI technology (which is not so bad), but also gives some information about my namespaces, method names, parameters, etc.
I tried setting IncludeErrorDetailPolicy to Global.asax
GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Never;
Yes, this is somehow good, now the result does not contain a MessageDetail section, but still I do not want to receive this HttpError at all.
I also created my own DelegatingHandler, but it also affects the 400 and 404 that I myself generate in controllers that I don't want.
My question is: Is there a convenient way to get rid of a serialized HttpError from the content of the answer? All I want the user to return to their bad queries is the response code.