Skip to content
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

fix: define search path in auth functions #1636

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions migrations/20240625163155_set_search_path.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-- set the search_path to an empty string to force fully qualified names in the function
do $$
begin
-- auth.uid() function
create or replace function auth.uid()
returns uuid
set search_path to ''
as $func$
select coalesce(
nullif(current_setting('request.jwt.claim.sub', true), ''),
(nullif(current_setting('request.jwt.claims', true), '')::jsonb ->> 'sub')
)::uuid
$func$ language sql stable;

-- auth.role() function
create or replace function {{ index .Options "Namespace" }}.role()
returns text
set search_path to ''
as $func$
select coalesce(
nullif(current_setting('request.jwt.claim.role', true), ''),
(nullif(current_setting('request.jwt.claims', true), '')::jsonb ->> 'role')
)::text
$func$ language sql stable;

-- auth.email() function
create or replace function {{ index .Options "Namespace" }}.email()
returns text
set search_path to ''
as $func$
select
coalesce(
current_setting('request.jwt.claim.email', true),
(current_setting('request.jwt.claims', true)::jsonb ->> 'email')
)::text
$func$ language sql stable;

-- auth.jwt() function
create or replace function {{ index .Options "Namespace" }}.jwt()
returns jsonb
set search_path to ''
as $func$
select
coalesce(
nullif(current_setting('request.jwt.claim', true), ''),
nullif(current_setting('request.jwt.claims', true), '')
)::jsonb;
$func$ language sql stable;
end $$;
Loading