Even if you solve the security issue, a query can easily bring down the server if it has a complex join query.
This could be solved by only exposing stored procedures, but that just moves the code to the database server instead of the REST service with the same problems as before.