GHSA-JHJH-VP9P-54FG
Cross-Domain SSO Email Assertion Allows Account Takeover via Identity Merge in provision-user
CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-JHJH-VP9P-54FG divulgada · CVSS 8.7 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
The SSO user provisioning merge path in `provision-user.ts` transfers SSO identities and deletes duplicate accounts based solely on email address match without verifying that the authenticating SSO provider is authorized for the victim's email domain. An org admin who controls a malicious IdP for their own domain can forge SAML assertions containing an arbitrary victim's email, triggering the merge flow and gaining full access to the victim's account.
Details
When a user authenticates via SSO and an existing account with the same email is found, the code at `provision-user.ts:180-258` enters the merge path. This path is intended to unify a pre-existing email/password account with a new SSO login.
The critical flaw is that the provider-to-domain lookup at lines 190-195 is advisory only — its failure does not abort the merge:
// provision-user.ts:190-199
const { data: mergeProvider, error: mergeProviderError } = await (admin as any)
.from('sso_providers')
.select('id, org_id, enforce_sso')
.eq('domain', userDomain) // looks up provider for VICTIM's domain
.eq('status', 'active')
.single()
if (mergeProviderError) {
cloudlogErr({ requestId, message: 'Failed to resolve SSO provider during merge — skipping org membership insert', originalUserId, domain: userDomain, error: mergeProviderError })
// WARNING: execution continues — no return/throw
}After this non-blocking check, the identity transfer proceeds unconditionally:
// provision-user.ts:225
const transferredIdentityCount = await transferSsoIdentities(getSharedPgClient(), originalUserId, userId, trustedSsoProviders)And the attacker's duplicate account is deleted:
// provision-user.ts:250
const { error: deleteError } = await admin.auth.admin.deleteUser(userId)Compare with the non-merge path at lines 260-271, which correctly gates on a valid provider:
// provision-user.ts:268-270
if (providerError || !provider) {
return quickError(404, 'provider_not_found', 'No active SSO provider found for your email domain')
}The root cause is that the merge path never validates that the SSO provider that authenticated the attacker (`sso:<attacker-provider-id>`) corresponds to an `sso_providers` row whose domain matches the victim's email domain. DNS verification (required during provider setup in `providers.ts:141-142`) only proves ownership of the attacker's domain — it does not constrain what email addresses the IdP asserts.
PoC
Prerequisites: Attacker has an enterprise-plan org with admin access and a configured SSO provider for `attacker.com` (DNS-verified and active).
Step 1: Configure the attacker's IdP (e.g., a local SimpleSAML instance) to return a SAML assertion with `email=victim@target.com` instead of the attacker's real email.
Step 2: Initiate SSO login through the attacker's provider:
# Trigger SSO login via attacker's provider — browser redirects to attacker's IdP
curl -v "https://capgo-instance.example/api/sso/login?provider_id=<attacker-provider-id>"Step 3: The attacker's IdP returns a signed SAML response asserting `email=victim@target.com`. Supabase Auth validates the SAML signature (valid — it's the attacker's own IdP) and creates a new `auth.users` row with `email=victim@target.com` and `provider=sso:<attacker-provider-id>`.
Step 4: The provision-user endpoint is called automatically after SSO login:
curl -X POST "https://capgo-instance.example/api/private/sso/provision-user" \
-H "Authorization: Bearer <attacker-sso-session-token>" \
-H "Content-Type: application/json"Step 5: The merge path activates:
- Line 150-155: Finds existing `public.users` row for `victim@target.com`
- Line 190-195: Looks up `sso_providers` where `domain = 'target.com'` — fails (no provider for target.com)
- Line 197-199: Logs warning, continues execution
- Line 225: Transfers attacker's SSO identity to victim's account
- Line 250: Deletes attacker's duplicate `auth.users` record
Step 6: Attacker logs in again via their IdP (again asserting `victim@target.com`). The SSO identity now points to the victim's original account — attacker has full access.
# Verify access to victim's account
curl "https://capgo-instance.example/api/private/user" \
-H "Authorization: Bearer <new-session-token>"
# Returns victim's user profile, orgs, and appsImpact
- Full account takeover: An attacker with an enterprise org and malicious IdP can take over any Capgo account by forging the email in SAML assertions
- Cross-organization boundary violation: The attacker's SSO provider (scoped to `attacker.com`) can assert emails for any domain, breaking the implicit domain isolation
- Data exposure: Full read/write access to victim's organizations, apps, channels, bundles, and device data
- Cascading access: If the victim is an admin of other organizations, the attacker inherits that access
Recommended Fix
The merge path must abort when no active SSO provider exists for the victim's email domain, matching the behavior of the non-merge path. Add a domain-authorization check after the provider lookup:
// provision-user.ts — after line 199, replace the soft log with a hard gate:
if (mergeProviderError || !mergeProvider) {
cloudlog({ requestId, message: 'No active SSO provider for email domain — aborting merge to prevent cross-domain takeover', originalUserId, domain: userDomain })
return quickError(403, 'provider_domain_mismatch', 'No active SSO provider found for the email domain — merge not allowed')
}
// Additionally, validate that the authenticating provider matches the domain's provider:
const userProviderId = userProvider.replace('sso:', '')
if (mergeProvider.provider_id && mergeProvider.provider_id !== userProviderId) {
cloudlog({ requestId, message: 'Authenticating SSO provider does not match domain provider — aborting merge', userId, domain: userDomain, expected: mergeProvider.provider_id, actual: userProviderId })
return quickError(403, 'provider_mismatch', 'SSO provider does not match the email domain provider')
}This ensures that: (1) a merge can only proceed when a valid, active SSO provider exists for the victim's email domain, and (2) the provider that authenticated the user is the same one registered for that domain.
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
npmcapgo-app |
Corregida | 12.128.2 | — | — |
12.128.2Arsenal 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-jhjh-vp9p-54fgLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
