-
Notifications
You must be signed in to change notification settings - Fork 50
Fix bug making anyone claims admin #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix bug making anyone claims admin #8
Conversation
This is incorrect. You are free to change this function if you want this security check to go beyond the scope of calls made from the javascript client. Otherwise, I think we should keep it like this. |
However, this block seems backward (and is indeed a bug!) Can you verify this and make sure I'm correct here and that this is indeed wrong? IF coalesce((current_setting('request.jwt.claims', true)::jsonb)->'app_metadata'->'claims_admin', 'false')::bool THEN
return true; -- user has claims_admin set to true
ELSE
return false; -- user does NOT have claims_admin set to true
END IF; |
I think it comes from this "bug" in the cli.... |
@GaryAustin1 Ah, so what does |
I don't use the CLI, was just helping someone debug your function and found root cause looking at the CLI config. |
When I run a local supabase instance, it seems the PostgREST server connects to Postgres with the |
It was/is definitely a bug in the local version setup (Steve confirmed using postgres user was incorrect) but to me looked like they had fixed it. But the issue is still marked open. |
Here's a proposal. Instead of checking |
I'm going to test this: CREATE OR REPLACE FUNCTION has_jwt() RETURNS "bool"
LANGUAGE "plpgsql"
AS $$
BEGIN
return (select current_setting('request.jwt', true)::jsonb <> null);
END;
$$; |
That's not working for me. Back to the original code, can you create this function and call it from your app via CREATE OR REPLACE FUNCTION get_session_user() RETURNS text
LANGUAGE plpgsql
AS $$
BEGIN
return session_user;
END;
$$; In my Supabase-hosted apps, it always returns |
In looking at this again, it does look to be correct (the false part is just a default value if it's not set, so this look correct now): IF coalesce((current_setting('request.jwt.claims', true)::jsonb)->'app_metadata'->'claims_admin', 'false')::bool THEN
return true; -- user has claims_admin set to true
ELSE
return false; -- user does NOT have claims_admin set to true
END IF;
|
@burggraf The hosted app has always been correct as far as I know. Just the docker/cli image used in local has been incorrect for a long time. I traced back the change history quite a ways back when the issue came up and could never find a point it was correct. |
First off - thanks for this library!
What kind of change does this PR introduce?
Security fix.
What is the current behavior?
The
is_claims_admin
function always returnstrue
. This allows any authenticated user to set claims on their own account. This completely defeats the purpose of this library.What is the new behavior?
The
is_claims_admin
function returnsfalse
when it should.Additional context
The
session_user
is always"postgres"
(the user that was used to establish the connection). I assumecurrent_user
is what was intended here.Furthermore, the
current_user
will never have the value"authenticator"
. However, for authenticated users it will have the value"authenticated"
.Since this library is about security, I suggest it comes with a disclaimer saying that this library does not have any automated tests, and therefore might not work as intended.
FWIW, I discovered the bug through automated tests in my own application using this library.