Complex authorization methods implementation - Create a db_post_request Hook for Dynamic Data Masking in Supabase #31314
Unanswered
vargasjona
asked this question in
Feature Requests
Replies: 1 comment 1 reply
|
You probably can also use rpc postgres security definer function calls to a table without RLS enabled. Then you provide back the exact data you want for each scenario while also looking at the user role in the function. A single return function seems like it might be a mess if it has to deal with individual tables and roles to sort what data to return. Using a table returning function can still allow filters on the client side while limiting data based a formula you desire. The global db_post_request also might have merit but just seems dealing with individual tables and their return values would be better handled on each table (or view) with rpc being the gateway. IMO. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
Currently, there is no mechanism in Supabase to dynamically mask or manipulate output data before it is sent to the client. While Row-Level Security (RLS) and Column-Level Security (CLS) provide robust access control, certain complex authorization scenarios remain challenging to implement securely without resorting to external middleware or duplicating logic.
For example, when fetching a list of users, the desired behavior might be:
customer:emailfield only if theuser_idmatches the authenticated user.NULLin theemailfield.admin:emailfields without restriction.Achieving this securely is challenging due to:
A feature that allows for dynamic data masking or manipulation at the SQL level—just before the response is returned to the client—would enable more powerful authorization models, such as Attribute-Based Access Control (ABAC), without relying on external systems.
Solution
Introduce a
db_post_requesthook function that executes after a query is processed but before the response is sent to the client. This function could be utilized to:Benefits
This function would allow for dynamic masking and transformation of output data directly within the database, seamlessly integrating with Supabase's existing RLS and CLS mechanisms.
I have opened a related feature request in the PostgREST repository: [Add db_post_request Hook for Dynamic Data Masking in PostgREST](PostgREST/postgrest#3830).
If there are other approaches to implementing complex authorization methods like ABAC in Supabase without relying on dedicated middleware or Edge Functions, I would appreciate any guidance or suggestions.
All reactions