Resource embedding in the query instead of in the URL #3174
-
I am wondering if it would be possible to make a nested API response (i.e. embedded resource) by specifying the nesting in the SQL query itself rather than in the endpoint URL. So rather than:
would it be possible to make something like this:
So the URL can simply be Formulating a wide variety of queries through the URL also has limitations which don't exist if we can structure the API response within the SQL query itself. As another point, not everybody wants to make their tables open to being queried directly and in various ways. I would much rather formulate the SQL queries myself and give the user access to the view or function, instead of letting the user modify the URL to make many different kinds of queries against my database. With open source software, this ability to add and execute all sorts of functions and joins and operators and so on can open up the doors to finding potential exploitations. It seems very difficult to foresee what combination of functions and operators might lead to a vulnerability in some situation. Since I am making an app template which I'd like other devs to use for making their apps, keeping things more simple and secure, and using already known and widely used standards, seems far more preferable to me than creating new kinds of syntax, new learning curves and potential (and very difficult to predict) vulnerabilities. Does anyone have any thoughts on this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
I am not an expert with PostgREST, but can't you already do this? Create stored procedures which do the queries and filter as you like and only expose those. I don't see any reason that you would be forced to expose more than exactly what you want. |
Beta Was this translation helpful? Give feedback.
-
That's what we call Schema Isolation.
That's not a problem. You can return json from RPCs. You can return json column in your views. Arbitrarily nested, no problem...
... but you don't need to do the json part yourself. You can also just return composite type columns, arrays of composite types, Maybe I just misunderstand what you want to do, though. |
Beta Was this translation helpful? Give feedback.
You are creating more problems than you are solving when doing this. You wanted to write your own queries, because of security concerns:
This is just not how it works. Once you write dynamic SQL, you are far more likely to make a…