GHSA-JPJP-V827-J4GC
SSO provider_id is client-writable — incomplete fix in the latest migration lets an org admin hijack the org owner account
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-JPJP-V827-J4GC divulgada | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
SUMMARY :
The newest migration 20260826100000_sso_providers_block_direct_active_insert.sql hardened public.sso_providers against direct PostgREST writes, but the BEFORE UPDATE guard it installs only freezes four columns (dns_verified_at, domain, status, enforce_sso). It never freezes provider_id (nor metadata_url / attribute_mapping). The table is GRANT ALL ... TO anon, authenticated with no column-level restriction, and the UPDATE policy allow_org_admins_update_sso_providers lets any principal holding org.update_settings (the org_admin tier — one level below owner/super_admin) UPDATE the row over PostgREST. Postgres RLS is row-level, not column-level, so an org_admin can PATCH provider_id to an identity provider they control.
provider_id is the single trust anchor the SSO login/merge flow uses to bind an email domain to an authorized IdP. Once an org_admin repoints it, they can log in through their own IdP asserting the org owner's email; the server's provider-match check passes, and the merge routine transfers the attacker's SSO identity onto the pre-existing owner account, nulls that account's password, and deletes its other identities and all its sessions. The attacker gains an authenticated session as the org owner/super_admin and the real owner is locked out — vertical privilege escalation (org_admin -> owner) plus account takeover and denial of access.
================================================================
DOMAIN
================================================================
- Backend repo: github.com/Cap-go/capgo (supabase/ Postgres + supabase/functions/_backend/).
- Live: Capgo production on Supabase — direct table writes reach sso_providers via PostgREST /rest/v1/ with a normal user JWT + the anon apikey.
- Precondition: an org that has an active SSO provider (enterprise feature) and the attacker holding org_admin (org.update_settings) in that org.
================================================================
VULNERABLE ENDPOINT / CODE
================================================================
A. Incomplete column guard.
supabase/migrations/20260826100000_sso_providers_block_direct_active_insert.sql:29-66 —
enforce_sso_provider_client_update_guard() BEFORE UPDATE trigger raises only on dns_verified_at,
domain, status, enforce_sso. provider_id, metadata_url, attribute_mapping are unchecked -> client
UPDATEs to them succeed. (The only other triggers on the table are a timestamp updater and a domain
normalizer — neither touches provider_id.)
B. Table exposed to PostgREST with no column restriction.
supabase/migrations/20260708000000_prod_baseline.sql:24142-24143 (and prod.sql:28507-28508):
GRANT ALL ON TABLE public.sso_providers TO anon, authenticated. No column-level GRANT/REVOKE on provider_id.
C. UPDATE reachable by org_admin.
supabase/schemas/prod.sql:24726 —
CREATE POLICY "allow_org_admins_update_sso_providers" ON "public"."sso_providers"
FOR UPDATE TO "anon","authenticated"
USING (rbac_check_permission_request(rbac_perm_org_update_settings(), org_id, NULL, NULL))
WITH CHECK (rbac_check_permission_request(rbac_perm_org_update_settings(), org_id, NULL, NULL));
The policy constrains only the row (org membership), never which columns change. org.update_settings is
granted to org_admin (supabase/seed.sql:1294) and org_super_admin — a non-owner org_admin qualifies.
D. provider_id is meant immutable via the API — set only at creation
(supabase/functions/_backend/private/sso/providers.ts:166), never by the update route.
E. provider_id is the sole trust binding in the SSO merge.
supabase/functions/_backend/private/sso/provision-user.ts
- :586-590 resolve provider by domain = userDomain AND status = 'active' only.
- :118-128 getAuthorizedSsoProviders() returns [provider.provider_id].
- :603-607 if the authenticating SSO provider != provider.provider_id -> abort provider_mismatch
(the only barrier; the attacker made it match).
- :611-620 on match -> mergeSsoIdentityWithExistingAccount(originalUserId = pre-existing owner account
resolved by email at :39-65, duplicateUserId = attacker's SSO login, orgId).
- :151-182 setAuthUserSsoOnly() on the OWNER account: encrypted_password = null, rewrites provider/providers
to the attacker's sso:<id>, delete from auth.identities, delete from auth.sessions.
F. Attacker can obtain a usable IdP cheaply.
providers.ts:118-166 self-provisions a Supabase auth SSO provider from an attacker-supplied metadata_url,
gated only by org.update_settings + enterprise plan — both already held by the org_admin.
================================================================
STEPS TO REPRODUCE
================================================================
Non-destructive validation uses only researcher-owned orgs/accounts (a test "owner" account in a victim test
org, an attacker org_admin, and an attacker-controlled IdP).
- Attacker mints/uses an SSO provider whose IdP they operate -> provider id P_att.
- Target org X has an active SSO provider for victimcorp.com (real provider_id = P_victim); attacker holds
- Attacker overwrites org X's provider binding via direct PostgREST UPDATE (allowed by policy; trigger does
PATCH https://<project>.supabase.co/rest/v1/sso_providers?org_id=eq.<orgX_uuid>&status=eq.active
apikey: <anon_key>
Authorization: Bearer <attacker_org_admin_JWT>
Content-Type: application/json
Prefer: return=representation
{"provider_id":"<P_att>"}
Expect 200 with provider_id now P_att, and NO SSO_PROVIDER_*_DENIED error (proves the trigger did not block it).
4. Attacker logs in through IdP P_att, asserting email = owner@victimcorp.com.
5. provision-user resolves victimcorp.com -> org X row (provider_id = P_att), the provider_mismatch check at
:603 passes, mergeSsoIdentityWithExistingAccount runs.
6. The owner account is set SSO-only (encrypted_password = null), its other identities and all sessions are
deleted, and the attacker's P_att identity is attached. Attacker now authenticates as owner@victimcorp.com
(org owner / super_admin, inheriting the owner's role_bindings); the real owner is locked out.
Steps 1-3 are fully source-confirmed (trigger columns, table GRANT, RLS policy, API-immutable provider_id) and
are directly demonstrable with poc/f1_sso_provider_id_patch.sh. Steps 4-6 (SSO assertion of a foreign email)
should be confirmed on a live instance, as they also depend on whether Supabase Auth restricts which email
domains an IdP may assert.
================================================================
IMPACT
================================================================
- Vertical privilege escalation: org_admin -> org owner / super_admin within a tenant.
- Full account takeover of the org owner (attacker authenticates as them, inherits their roles).
- Denial of access: owner's password nulled, sessions/identities deleted -> owner locked out.
- Same root cause also lets the org_admin repoint metadata_url / attribute_mapping of an active provider
without re-verification (SSO trust redirection / assertion-mapping tampering).
Bounded by preconditions: the org must have an active SSO provider and the attacker must already be an org_admin.
Not cross-tenant / not unauthenticated.
================================================================
SUGGESTED FIX
================================================================
Add provider_id, metadata_url, attribute_mapping to the IS DISTINCT FROM checks in
enforce_sso_provider_client_update_guard() (or make them server/service_role-write-only via column GRANTs), and
restrict allow_org_admins_update_sso_providers to the columns clients legitimately edit. Require re-verification
when an active provider's IdP identity/metadata changes.
================================================================
REFERENCE
================================================================
- Incomplete fix: supabase/migrations/20260826100000_sso_providers_block_direct_active_insert.sql
- Table GRANT: supabase/migrations/20260708000000_prod_baseline.sql:24142-24143
- RLS policy: supabase/schemas/prod.sql:24726
- Merge/trust logic: supabase/functions/_backend/private/sso/provision-user.ts:39-65, 118-128, 151-182, 586-620
- API-immutable creation + self-provision: supabase/functions/_backend/private/sso/providers.ts:118-166
---
Fix PR (open)
Intentional fix PR https://github.com/Cap-go/capgo.app/pull/3214 (open). Blocks client writes to `sso_providers.provider_id`.
Do not disclose this advisory in the PR. Bounty/credit is due only after merge, production release, and reporter verification.
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Estado del parche por paquete
La fuente no informa paquetes ni versiones corregidas.
Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/Cap-go/capgo.app/security/advisories/GHSA-jpjp-v827-j4gcLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
