Thomas B
10/30/2021, 12:39 PMSECURITY DEFINER SET search_path = public
thingy that I have to use when writing Functions when using Supabase, but I really do not see other tutorials or the like use.. Am I allowed to just add extensions
to it along with public, or is there any security issues with that?
I can only get pgjwt (https://github.com/michelp/pgjwt) to work with that added. 🙂
Here is the full function:
CREATE OR REPLACE FUNCTION handle_new_user() RETURNS trigger
SECURITY DEFINER SET search_path = public, extensions
AS
$$
BEGIN
INSERT INTO profiles (id, jwt)
VALUES (NEW.id, (SELECT SIGN('{
"sub": "1234567890",
"name": "John Doe"
}', 'secret')));
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
garyaustin
10/30/2021, 4:03 PMgaryaustin
10/30/2021, 4:04 PMThomas B
10/30/2021, 7:29 PMSECURITY DEFINER SET search_path = public, extensions
if I do not use this, both public and extensions, stuff wont work properly. Extensions for the pgjwt
extension I use and public for the other stuff I guess.
- the way I test this function is by inviting an user via the Supabase dashboard. That will just give an error if no SECURITY DEFINER at all is set. :/
I am fine by using it, I just wanted to make sure it was safe to add. 🙂garyaustin
10/30/2021, 8:07 PMgaryaustin
10/30/2021, 8:15 PMThomas B
10/30/2021, 8:16 PMSECURITY DEFINER
without the SET....
part, and it still won't work without. 🙂 Did I misunderstand you, or?Thomas B
10/30/2021, 8:18 PMCREATE OR REPLACE FUNCTION handle_new_user() RETURNS trigger
SECURITY DEFINER
AS
$$
BEGIN
INSERT INTO profiles (id, jwt)
VALUES (NEW.id, (SELECT SIGN('{
"sub": "1234567890",
"name": "John Doe"
}', 'secret')));
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- -------------------------------------------
CREATE TRIGGER on_user_signup
AFTER INSERT
ON auth.users
FOR EACH ROW
EXECUTE PROCEDURE handle_new_user();
This gives an error when inviting users from the dashboard.
Adding SET search_path = public, extensions
to the SECURITY DEFINER makes it work just fine. 🧐garyaustin
10/30/2021, 8:18 PMThomas B
10/30/2021, 8:24 PMSteve
11/02/2021, 9:59 PMsearch_path
in your function if you do SELECT extensions.SIGN(..)