It seems to me that breeze/odata queries present a significant risk for security access to data. For example, consider that I have an unrestricted entity (U) that is related to a restricted entity (R). I won't expose an endpoint to query for R and I'll write my client to query for U without including related Rs. But, a malicious client could request related Rs.
How do I prevent this?
I have a couple ideas. But, I have not been able to implement them yet to be able to say whether they work or not. None-the-less, here are my ideas:
1) Inspect each resulting entity -- after the query has been executed but before the result is sent to the client. But, I don't know how to insert my checking code (via callback or something) at the point between execution and sending to the client :(
2) Add smarts to the POCO to check for restricted entities and properties based on the user role. For example, instead of:
class MyThing{
public string P {get;set;}
}
I'd have something like this:
private string _p;
public string P
{
get
{
if (UserRoles.HasAny("role-a","role-b"))
return _p;
return null;
}
set { _p = value; }
}
That seems icky since a POCO is supposed to be dumb. The POCO would need to be able to read the user roles from somewhere ... maybe the HTTP session. I don't quite know how that will work.
I've read the following questions/answers, but they are not helping me: roles based security in breezejs and EF6, How is breeze.js handling security and avoiding exposing business logic, How to handle authorization with Breeze JS?