During a Security review at the company I work for, an issue was raised with a Web.API returning too much information if the user were to change for the example the order by value that is provided.
Example of a legitimate call: https://mysite/controller/myData?$orderby=realcolumn
Example of a malicious call: https://mysite/controller/myData?$orderby=fakecolumn
In the second case, the api is returning:
{
"$id": "1",
"$type": "System.Web.Http.HttpError, System.Web.Http",
"Message": "The query specified in the URI is not valid. Could not find a property named 'fakecolumn' on type 'MyObject.Models.MyData."
}
While I do not see this as being a large security concern and as a developer having this type of response is helpful... I am being asked to make this more generic – basically provide as little information as possible.
I don’t know how to trap this prior to sending the response back to the user. If I walk through the code and stop prior to returning the result, the data is there. In this case the order by doesn’t appear to be evaluated until after the return occurs in the controller. Is there a way to perform the evaluation at the server, trap for errors like this and return a more generic response?
Code snippets below, I appreciate any assistance provided.
From the Controller
RepositoryMyData _repo;
[HttpGet]
public IQueryable<myData> myData()
{
return _repo.myData();
}
From the Repository class – using Entity Framework…
public DbQuery<myData> myData()
{
return (DbQuery<myData>)_contextProvider.Context.myData
}