llamaCVEVulnerability Intelligence
/
Advisory · GitHub

GHSA-8H52-44R7-W343

API-key manager can rotate an org_super_admin sibling key and recover its plaintext credential

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ón70 dDesde la divulgación, 10 sept 2026, 5:07 a. m.
Detección69 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
10 sept 26
18 nov 26
20 nov 26
10 sept 26
28 sept 26
15 oct 26
2 nov 26
20 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-8H52-44R7-W343 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

DC-014 Validation Report

  • Candidate: DC-014 — API-key managers can rotate a higher-privileged sibling key and recover its plaintext credential
  • Raw candidates: `FR-009-C01`, `FR-010-C01`
  • Instance key: `apikey-sibling-rotation:supabase/functions/_backend/public/apikey/scope.ts:219-235`
  • Source ledgers: `artifacts/05_findings/FR-009-C01/candidate_ledger.jsonl`; `artifacts/05_findings/FR-010-C01/candidate_ledger.jsonl`
  • Target commit: `255357ca7277c95737c5148b20e43391efe858b8`
  • Disposition: `reportable`
  • Survives validation: `yes`
  • Severity: `high`
  • Confidence: `0.97`
  • Method: Bounded static source/control/sink validation through both deployed API mounts, API-key authentication, sibling discovery, same-owner and target-org controls, caller/target RBAC, both regeneration branches, the service-owned SQL helper, exact seed fixtures, and focused existing integration tests. No production request, external account, repository edit, or state-changing local request was performed.

Pre-established validation rubric

  • [x] Deployed route and API-key-auth reachability: Both shipped deployments mount the shared GET/PUT handlers, and `middlewareAuth()` accepts a valid API key through the supported headers.
  • [x] Target enumeration and ownership constraints: The caller can enumerate and select same-user sibling keys whose binding organizations are all manageable; key material is omitted from listing, but the target ID is returned.
  • [x] Caller permission versus target-role dominance: Authorization checks only the caller's `org.manage_apikeys` permission and target-org coverage. It never requires the caller to dominate the target's role or global grants.
  • [x] Rotation and secret-return sink: Both hashed and legacy branches rotate the attacker-selected target with service-role authority and return its newly generated reusable plaintext credential while preserving the target's RBAC identity.
  • [x] Realistic fixtures, tests, and countercontrols: The seed contains an exact same-user/same-org `apikey_manager`/`org_super_admin` pair. Existing tests separately prove manager enumeration/sibling PUT and that regeneration returns a newly authenticating secret. Self-update, permission-field edits, unmanaged-org targets, and cross-user targets were assessed and do not stop the seeded higher-sibling path.

Root control and affected labels

  • Deployed route mounts: `supabase/functions/apikey/index.ts:1-10`; `supabase/functions/_backend/public/apikey/index.ts:1-16`; `cloudflare_workers/api/index.ts:90-97`.
  • API-key authentication: `supabase/functions/_backend/utils/hono_middleware.ts:190-200,373-413,447-470,518-546`.
  • Target discovery: `supabase/functions/_backend/public/apikey/get.ts:53-70,73-94`.
  • Root authorization control: `supabase/functions/_backend/public/apikey/scope.ts:78-101,195-258,261-277`.
  • Attacker-selected update path: `supabase/functions/_backend/public/apikey/put.ts:277-366`.
  • Rotation/plaintext sink: `supabase/functions/_backend/public/apikey/put.ts:420-447`; `supabase/migrations/20260708000000_prod_baseline.sql:33010-33049`.
  • Role intent and permission set: `supabase/migrations/20260708000000_prod_baseline.sql:27429-27470`.
  • Exact seed precondition: `supabase/seed.sql:584-587,1519-1538,1549-1586`.
  • Existing test evidence: `tests/apikeys.test.ts:504-545,546-605,909-987`.

Evidence

1. The shared GET and PUT handlers are deployed and accept API-key authentication

The Supabase `apikey` function mounts the shared API-key router and serves it (`supabase/functions/apikey/index.ts:1-10`). The Cloudflare API worker mounts the same router at `/apikey` (`cloudflare_workers/api/index.ts:90-97`). The shared router installs its GET and PUT subrouters (`public/apikey/index.ts:1-16`), and the concrete operations use `middlewareAuth()` (`get.ts:53,73`; `put.ts:464-465`).

`middlewareAuth()` accepts `capgkey`, `x-api-key`, or the compatible authorization form, resolves the API-key record, and stores both the owning `userId` and full API-key row in the request context (`hono_middleware.ts:190-200,373-413,447-470,518-546`). This is an authenticated remote route, not an unreachable helper.

2. A manager can enumerate and select the higher-privileged same-owner sibling

GET `/apikey` selects the authenticated user's public API-key rows, filters them through `filterApiKeysManageableByAuth`, and returns the manageable rows (`get.ts:53-70`). The public shape excludes existing `key` and `key_hash`, but includes each sibling's numeric ID; that is sufficient to select a target for PUT.

For API-key callers, `filterApiKeysManageableByAuth` loads each target's binding organizations and retains it when every target organization is in the caller's manageable set (`scope.ts:236-258`). The single-target selector then uses service-role access but restricts the row only by `user_id = auth.userId` plus caller-supplied ID or legacy key (`scope.ts:261-277`).

These are real constraints:

  • a target owned by another user is rejected;
  • a target with no binding organization is rejected;
  • a target bound to any organization where the caller lacks `org.manage_apikeys` is rejected.

They do not distinguish separate API-key principals owned by the same user. The seed supplies the exact qualifying pair: keys `112` and `113` have the same `user_id`; their repaired bindings place both in organization `f1a2b3c4-d5e6-4f70-8a9b-0c1d2e3f4a50`, with key `112` as `org_super_admin` and key `113` as `apikey_manager` (`seed.sql:584-587,1549-1586`).

3. The caller permission check does not contain target privilege

The caller's manageable organizations are derived from its own binding organizations and `checkPermission(c, 'org.manage_apikeys', { orgId })` (`scope.ts:78-94`). The target check is only:

targetOrgIds.length > 0
&& targetOrgIds.every(orgId => manageableOrgIds.has(orgId))

(`scope.ts:97-101,219-235`).

There is no comparison of:

  • caller and target role `priority_rank`;
  • caller and target effective permissions;
  • target global permissions;
  • a parent/child or issuer relationship;
  • whether the target role is one the caller could assign.

The migration makes the intended separation explicit. `org.manage_apikeys` includes lifecycle actions such as rotate, but describes doing so “without assigning user roles”; `apikey_manager` is for CI/CD key management “without org role assignment rights,” has priority rank 78, and receives only `org.manage_apikeys` and `org.read` (`prod_baseline.sql:27429-27470`). That lifecycle permission reasonably authorizes rotating an appropriate managed key. It does not by itself establish that a manager should receive and use the replacement credential of an existing stronger principal.

The PUT handler reinforces that separation by rejecting self-update and all API-key-authenticated binding/global-permission edits (`put.ts:345-350`). However, after those checks it loads the target organization IDs and performs only the org-set check (`put.ts:352-354`). `regenerate` remains allowed regardless of target role.

4. Regeneration returns the stronger principal's new plaintext secret

For a hashed target, PUT invokes `regenerate_hashed_apikey_for_user` with the selected target ID and authenticated owning user ID, then returns the entire result (`put.ts:420-429`). The `SECURITY DEFINER` helper:

  1. generates a new plaintext UUID;
  2. updates only the target row's `key` and `key_hash`, constrained by ID and user ID;
  3. puts the plaintext value back into the returned composite row;
  4. returns that row to the service-owned caller.

(`prod_baseline.sql:33010-33049`).

For a legacy target, the service-role client updates the selected same-user row with the trigger sentinel, selects the resulting complete row, and returns it (`put.ts:432-447`). Thus both branches disclose the replacement plaintext.

Neither branch changes `rbac_id`, role bindings, or global grants. Authentication resolves the target API-key row and uses that row as the active API-key principal (`hono_middleware.ts:447-470`). The returned secret therefore authenticates as the target's existing stronger principal, not as the caller. Rotating seed key `112` through key `113` converts the manager credential into possession of an `org_super_admin` credential.

5. Existing tests compose the path, with one bounded runtime gap

The focused `apikey_manager` test authenticates as seeded key `113`, creates a same-org sibling through the owning user's JWT, and proves:

  • GET `/apikey` returns that sibling ID (`tests/apikeys.test.ts:504-527`);
  • PUT `/apikey/:siblingId` succeeds for a metadata update (`:539-545`);
  • binding promotion to `org_super_admin` is rejected (`:546-554`);
  • privileged creation and the `allowSystemRole` bypass are rejected (`:556-597`);
  • self-update is rejected (`:599-605`).

Separate regeneration tests prove that both plain and hashed rotation responses contain a changed plaintext key, the old key no longer authenticates, and the returned key does authenticate while retaining the target's RBAC management capability (`tests/apikeys.test.ts:909-987`). The source trace composes these proven branches with seed keys `113 -> 112`; no intervening control depends on target role.

The repository has no existing test that sends `{"regenerate":true}` from key `113` specifically to key `112`. This checkout also has no Bun, Docker, Supabase CLI, `node_modules`, or running disposable database, so executing or adding that state-changing integration case was not bounded here. The missing runtime capture is suitable submission hardening, not an unresolved code predicate.

Counterevidence and scope

  • Rotation is named in the permission. This is the strongest counterevidence. The finding is not that the manager may rotate ordinary managed keys; it is that rotation returns a higher-privileged sibling's bearer credential, bypassing the separate no-role-assignment boundary.
  • Same owner is required. This confines the path to keys under one user record. API keys nevertheless have independent `rbac_id` principals and intentionally different roles; the exact seed models that separation.
  • Every target org must be manageable. A stronger target with an extra unmanaged binding is blocked. A stronger target solely in the manager's org, including seeded key `112`, is accepted.
  • Self-update is blocked. The exploit selects a sibling, so the self-ID check does not apply.
  • Permission fields cannot be edited by an API key. The attack preserves the target's existing stronger fields and captures its replacement secret, so no permission-field edit is needed.
  • Existing key material is hidden from GET. GET still discloses the target ID. PUT creates and returns new key material.
  • Rotation revokes the old secret. This may alert or disrupt the legitimate operator, but it does not prevent immediate use of the replacement secret and may impede the victim's response.

Safe local reproduction

Against a disposable, freshly seeded local stack only:

  1. Authenticate `GET /apikey` with seeded key `113` and observe target ID `112`.
  2. Send `PUT /apikey/112` with `capgkey: <seed-key-113>` and body `{"regenerate":true}`.
  3. Confirm HTTP 200 and capture the returned non-empty `key`.
  4. Confirm the old key `112` secret fails authentication.
  5. Authenticate a harmless organization read and one `org_super_admin`-only action with the returned secret, then restore the database by resetting the disposable seed.

No production credential or tenant is needed or appropriate.

Remaining uncertainty and next step

Runtime deployment state was not queried, so the report relies on the committed deployment mounts, production baseline, seed, and tests at the target commit. Before submission, add a dedicated local integration test for `APIKEY_MANAGEMENT_APIKEY_MANAGER -> APIKEY_MANAGEMENT_ORG_SUPER_ADMIN`, assert the returned secret can perform an action allowed to the target but denied to the manager, and reset the local database afterward.

Remediation should enforce target privilege containment before metadata updates, rotation, or deletion: the caller must be authorized to assign every target binding/global grant, or the target must be an explicitly delegated child whose effective permissions are a subset of the caller's. A safer rotation API can return the replacement only to a JWT-backed owner or deliver it through a separate privileged recovery channel. Add regression cases for higher-role targets, target global grants, mixed managed/unmanaged bindings, same-role siblings, and lower-role children.

<!-- private-maintainer-note -->
Private maintainer note: fix PR opened at https://github.com/Cap-go/capgo.app/pull/3092 (require manage_apikeys for regenerate_hashed_apikey). Reporter: please verify after merge+release for bounty eligibility per https://capgo.app/bug-bounty/.

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-8h52-44r7-w343

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