Search path or grant lockdown mishap
As someone who doesn't claim to be an expert in SQL, I was trying to tighten my security to my entire DB, adding search_paths to the functions and revoking permissions to general users on public. I'm including a log of all the SQL changes I made, the initial changes were made to tighten security and they did that too well: now users who are authenticated and supposed to / previously get missing relations errors when accessing tables (i.e. the tables cannot be queried). It seems the query throwing this error is within the get_user_role function which is used everywhere to determine permissions. I would be happy to share any details necessary! https://hastebin.com/share/vapacetuqe.sql Thanks!
Hastebin
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
17 Replies
You should not mess with grants on the public schema.
You should move tables to private schemas if you don't want global access or use RLS.
You can revoke grants on functions but need to do it individually on each function... https://discord.com/channels/839993398554656828/1431588976598454272/1433932196028354712
Really lost in what all you are doing there as you remove things then seem to add them back.
What is the exact error your function is getting?
This code should restore the default grants...
The remove and readd wasn't an educated move, it was me removing things then trying to figure out what not to remove - I'll add those back, in some research I might've misunderstood but I thought without revoking certain priviledges anon or auth would be able to create functions or tables or things, is that not the case?
They cannot create tables and functions.
They are granted ability to use/execute by default.
Also there is no ability to generate tables and functions from the REST API.
I'm actually suprised that didn't resolve the issue:
Runtime error:
Responsible code: (init useEffect responsible for determining user permissions)
But because it's not an issue w/ client_profiles table, it's likely the issue on this:
Which refers to
That is not a grant error.
Given that we reset the grants, it would seem the only culprite would be from search_path errors?
That is either a table spelling error or a search path error.
Certainly the latter, those tables / routines have worked for a long time and no table name alteration is made
I set these search_paths to resolve the warnings in the dashboard, maybe this was incorrect?
It is always best to just force the table with public.client_profiles if that is the schema it is in.
Then search path can be ''.
Maybe I shouldn't worry about the warning but wouldn't that throw a warning in the dashboard? (I'm trying to have high security compliance for Hipaa reasons)
What does throw a warning in dashboard mean?
Setting the search path for the function to '' is normally what Supabase likes to see for their security checks.

Oh I blanked - search path '' is different from empty search path
That warning is because you should not have installed pg_net in public.
I believe by default supabase installs it to extensions schema.
Yeah, I'll resolve that shortly, I was just showing what I meant by dashboard warning, but I can revert those paths to '' - When you say
force the table with public.x What adjustment in specific is that? Is that just in SQL functions or on items in the JS API?In the function code add
public. to the front of the table name.
That then does not use a search path.Thanks! I'll try that!