-
-
Notifications
You must be signed in to change notification settings - Fork 131
fix(security): require membership for channel permission overrides #3093
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
Open
riderx
wants to merge
13
commits into
main
Choose a base branch
from
fix/security-ghsa-626c-channel-overrides
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+625
−0
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
29d185d
fix(security): require org membership for channel permission override…
cursoragent 56c6294
test(db): capture outsider apikey rbac_id before RLS auth context
cursoragent c32b5c3
ci: retrigger pull_request checks
cursoragent 0ccdfde
test(db): grant temp apikey rbac table to authenticated role
cursoragent fff9fea
fix(db): bump channel overrides migration timestamp after main rebase
cursoragent b5db70d
ci: retrigger pull_request checks after main rebase
cursoragent 4393b80
ci: retrigger after cancelled workflow
cursoragent 916762a
ci: retrigger tests when queue lighter
cursoragent eda4b08
ci: retrigger after cancelled workflow jobs
cursoragent ebfff04
ci: retrigger after 3094 test fix (sequential)
cursoragent 65a428b
ci: retrigger pull_request Run tests
cursoragent f160082
fix(db): bump migration timestamp after main app_fame migration
cursoragent a9fbe4a
fix(security): align channel override membership with rbac_principal_…
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
supabase/migrations/20260826101006_channel_overrides_require_membership.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| -- GHSA-626c-p6fq-3whq: channel permission overrides must target a principal | ||
| -- that already belongs to the channel's owner org. Caller still needs | ||
| -- app.update_user_roles. Membership matches rbac_principal_has_org_binding | ||
| -- (any non-expired org/app/channel binding, or user via group binding, or | ||
| -- group in org). SECURITY DEFINER wrapper so the check is not filtered by | ||
| -- groups/role_bindings RLS (app-scoped admins cannot SELECT those rows). | ||
| -- Join channels -> apps for owner_org, same as the previous policies. | ||
|
|
||
| CREATE SCHEMA IF NOT EXISTS rbac_internal; | ||
|
|
||
| CREATE OR REPLACE FUNCTION rbac_internal.channel_override_principal_in_org( | ||
| p_principal_type text, | ||
| p_principal_id uuid, | ||
| p_org_id uuid | ||
| ) | ||
| RETURNS boolean | ||
| LANGUAGE sql | ||
| STABLE | ||
| SECURITY DEFINER | ||
| SET search_path = '' | ||
| AS $$ | ||
| SELECT public.rbac_principal_has_org_binding( | ||
| p_principal_type, | ||
| p_principal_id, | ||
| p_org_id | ||
| ); | ||
| $$; | ||
|
|
||
| ALTER FUNCTION rbac_internal.channel_override_principal_in_org(text, uuid, uuid) | ||
| OWNER TO postgres; | ||
| REVOKE ALL ON FUNCTION rbac_internal.channel_override_principal_in_org(text, uuid, uuid) | ||
| FROM PUBLIC; | ||
| GRANT USAGE ON SCHEMA rbac_internal TO authenticated, service_role; | ||
| GRANT EXECUTE ON FUNCTION rbac_internal.channel_override_principal_in_org(text, uuid, uuid) | ||
| TO authenticated, service_role; | ||
|
|
||
| COMMENT ON FUNCTION rbac_internal.channel_override_principal_in_org(text, uuid, uuid) IS | ||
| 'RLS helper: delegates to rbac_principal_has_org_binding (any scope binding, ' | ||
| 'group membership, or group in org). Called from channel_permission_overrides ' | ||
| 'INSERT/UPDATE policies and cleanup DELETE (once per written row, ' | ||
| 'authenticated only). SECURITY DEFINER so app-scoped admins are not blocked ' | ||
| 'by groups/role_bindings SELECT RLS. Lives in rbac_internal (not ' | ||
| 'PostgREST-exposed).'; | ||
|
|
||
| DROP FUNCTION IF EXISTS public.channel_override_principal_in_org(text, uuid, uuid); | ||
|
|
||
| DELETE FROM public.channel_permission_overrides AS overrides | ||
| USING public.channels AS channels | ||
| JOIN public.apps AS apps | ||
| ON channels.app_id::text = apps.app_id::text | ||
| WHERE overrides.channel_id = channels.id | ||
| AND NOT rbac_internal.channel_override_principal_in_org( | ||
| overrides.principal_type, | ||
| overrides.principal_id, | ||
| apps.owner_org | ||
| ); | ||
|
|
||
| DROP POLICY IF EXISTS "channel_permission_overrides_admin_insert" | ||
| ON public.channel_permission_overrides; | ||
| CREATE POLICY "channel_permission_overrides_admin_insert" | ||
| ON public.channel_permission_overrides | ||
| FOR INSERT | ||
| TO authenticated | ||
| WITH CHECK ( | ||
| EXISTS ( | ||
| SELECT 1 | ||
| FROM public.channels | ||
| JOIN public.apps | ||
| ON channels.app_id::text = apps.app_id::text | ||
| WHERE channels.id = channel_permission_overrides.channel_id | ||
| AND public.rbac_check_permission( | ||
| public.rbac_perm_app_update_user_roles(), | ||
| apps.owner_org, | ||
| apps.app_id, | ||
| NULL::bigint | ||
| ) | ||
| AND rbac_internal.channel_override_principal_in_org( | ||
| channel_permission_overrides.principal_type, | ||
| channel_permission_overrides.principal_id, | ||
| apps.owner_org | ||
| ) | ||
| ) | ||
| ); | ||
|
|
||
| COMMENT ON POLICY "channel_permission_overrides_admin_insert" | ||
| ON public.channel_permission_overrides IS | ||
| 'Authenticated app admins can insert channel permission overrides only for ' | ||
| 'principals that belong to the channel org.'; | ||
|
|
||
| DROP POLICY IF EXISTS "channel_permission_overrides_admin_update" | ||
| ON public.channel_permission_overrides; | ||
| CREATE POLICY "channel_permission_overrides_admin_update" | ||
| ON public.channel_permission_overrides | ||
| FOR UPDATE | ||
| TO authenticated | ||
| USING ( | ||
|
riderx marked this conversation as resolved.
|
||
| EXISTS ( | ||
| SELECT 1 | ||
| FROM public.channels | ||
| JOIN public.apps | ||
| ON channels.app_id::text = apps.app_id::text | ||
| WHERE channels.id = channel_permission_overrides.channel_id | ||
| AND public.rbac_check_permission( | ||
| public.rbac_perm_app_update_user_roles(), | ||
| apps.owner_org, | ||
| apps.app_id, | ||
| NULL::bigint | ||
| ) | ||
| AND rbac_internal.channel_override_principal_in_org( | ||
| channel_permission_overrides.principal_type, | ||
| channel_permission_overrides.principal_id, | ||
| apps.owner_org | ||
| ) | ||
| ) | ||
| ) | ||
| WITH CHECK ( | ||
| EXISTS ( | ||
| SELECT 1 | ||
| FROM public.channels | ||
| JOIN public.apps | ||
| ON channels.app_id::text = apps.app_id::text | ||
| WHERE channels.id = channel_permission_overrides.channel_id | ||
| AND public.rbac_check_permission( | ||
| public.rbac_perm_app_update_user_roles(), | ||
| apps.owner_org, | ||
| apps.app_id, | ||
| NULL::bigint | ||
| ) | ||
| AND rbac_internal.channel_override_principal_in_org( | ||
| channel_permission_overrides.principal_type, | ||
| channel_permission_overrides.principal_id, | ||
| apps.owner_org | ||
| ) | ||
| ) | ||
| ); | ||
|
|
||
| COMMENT ON POLICY "channel_permission_overrides_admin_update" | ||
| ON public.channel_permission_overrides IS | ||
| 'Authenticated app admins can update channel permission overrides only for ' | ||
| 'principals that belong to the channel org. Legacy outsider rows are deleted ' | ||
| 'by this migration; remaining rows must still target org members.'; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.