Repository navigation
fix(auth): restore organization API key management - #8740
Conversation
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — org API key create/revoke via WorkOS user/org-scoped Widgets API.
Scope is server/** (platform) only — no static/schemas/source/**, docs/reference, or dist changes — so no protocol changeset is required (PR body states this correctly). Verified operational readiness: widget-token delegation stays server-side (never returned to browser), token bound to exact userId/organizationId with scopes ["widgets:api-keys:manage"], fetch uses AbortSignal.timeout(5s) + redirect:"error", SDK maxRetries:0 with no manual retry, GraphQL HTTP-200-with-errors handled fail-closed (403/503), secret and widget token excluded from logs, Cache-Control:no-store on create, and triple membership/fence rechecks (pre-token, pre-write, post-write) withhold the secret on observed authority change.
high_risk is true only because server/src/routes/api-keys.ts is (modified) — but the sole finding is Medium, so row 5 (high_risk modified + medium) would fire escalate. Re-checked: high_risk=true, reason contains (modified), and a medium finding exists → row 5 matches.
Correction: row 5 applies → escalate.
Medium findings
- server/src/routes/api-keys.ts:513 — Created key id discarded when post-write authority recheck fails (audit gap)
Medium findings
- server/src/routes/api-keys.ts:513 — Created key id discarded when post-write authority recheck fails (audit gap)
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — subsequent pass resolves the prior Medium with no new findings.
This 46-line, 2-file delta adds a logger.warn in the post-write authority-recheck catch block of server/src/routes/api-keys.ts (capturing apiKeyId: result.id, actor, org, status), directly closing the prior Medium audit gap where the created key id was discarded on reconciliation failure. Matching test mocks and assertions confirm the secret is never carried in the warn. The secret-withholding behavior is unchanged.
Decision-table walk: no critical/high findings (row 1 n/a); gated_paths is false (row 2 n/a); high_risk is true only via a (modified) match on server/src/routes/**, with no deleted paths (rows 3/5 n/a since there are zero medium findings); no data-loss/schema/infra medium (row 4 n/a); prior decision was approve, not escalate (row 6 n/a); no no-auto-approve team match (row 7 n/a); zero medium findings (row 8 n/a). Falls through to row 9 → approve.
Prior Medium (api-keys.ts:513, discarded key id on recheck failure) is resolved; no new findings surfaced.
Creating or revoking an organization API key currently always returns 503 with “API key creation and revocation are disabled until membership changes can be fenced.” Restore permissionless registry key creation and revocation through WorkOS's user/organization-scoped Widgets API. The provider authorizes the mutation when the token is used; the unrestricted WorkOS server API remains read-only for key inventory.
Keep delegation server-side and preserve explicit organization selection, exact-credential owner/admin membership checks, identity/epoch locks, the permission allow-list, bounded requests, and no mutation retries. Created secrets use
Cache-Control: no-storeand are withheld after an observed authority change. If creation succeeded but the value cannot be returned, record the actor/org/key ID for reconciliation, preserve the denial status, and tell the caller to check the key list before retrying. The secret is never logged.WorkOS still decides whether a delegated token may grant requested permissions. Standalone widget sessions cannot grant privileged scopes; those requests return 403. This change restores permissionless registry keys and does not enable privileged key issuance or the separate widget-token delegation endpoint.
Provider configuration: aligned
widgets:api-keys:managewith the app's existing policy—owner/admin only, removed from member. The previous permission settings were saved for rollback.Validation:
44687a28d2481bbd666a71d4803371939a67c57a: all 825 server unit files (13,677 passed, 31 existing skips), 1,276 root Vitest tests, the root contract/guard suites, and both TypeScript checks.Provider references: Widgets API keys, permission checks happen when the token is used.
No protocol surface changed; no changeset is required.