supabase: Impersonation (Auth Hook JWT) does not reflect production behaviour
Bug report
- I confirm this is a bug with Supabase, not with my own application.
- I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
When using the Impersonation feature of Supabase Studio, it doesn’t reflect the actual permissions as it does not call the defined Custom Access Token Hook.
This in fact is not a feature request but a bug because Supabase Studio by all means must reflect production behaviour when it comes to impersonation with regards to the authenticated user.
The original discussion is found here: https://github.com/orgs/supabase/discussions/22482#discussioncomment-9011500
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Create a Custom Access Token Hook as follows:
CREATE OR REPLACE FUNCTION public.custom_access_token_hook(event jsonb)
RETURNS jsonb
LANGUAGE plpgsql
AS $$
DECLARE
claims jsonb;
user_id uuid;
BEGIN
user_id := (event->>'user_id')::uuid;
claims := event->'claims';
-- Check if 'app_metadata' exists in claims
if jsonb_typeof(claims->'app_metadata') is null then
-- If 'app_metadata' does not exist, create an empty object
claims := jsonb_set(claims, '{app_metadata}', '{}');
end if;
-- Set a claim of 'admin'
claims := jsonb_set(claims, '{app_metadata, combo}', '["snoo"]');
-- Update the 'claims' object in the original event
event := jsonb_set(event, '{claims}', claims);
-- Return the modified or original event
return event;
END;
$$;
grant execute
on function public.custom_access_token_hook
to supabase_auth_admin;
- Go to the SQL editor and impersonate any authenticated user
- Execute
SELECT auth.jwt(); - See
comboproperty missing
Expected behavior
With the given custom hook combo: ["snoo"] should show up in the user object of SELECT auth.jwt().
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 12
- Comments: 16 (9 by maintainers)
Just stumbled over this when trying to debug RBAC rules created by following this documentation: https://supabase.com/docs/guides/database/postgres/custom-claims-and-role-based-access-control-rbac
I think it should at least be mentioned in the docs that impersonation via studio doesn’t trigger the custom hook
Sorry for the wrong notifications here, I was confused by the thread. So long story short, why did we close it due to inactivity although still open? Could someone enlighten me?