Skip to content

fix(auth): restore organization API key management - #8740

Merged
bokelley merged 2 commits into
mainfrom
bokelley/api-key-creation-fix
Nov 5, 2026
Merged

bokelley merged 2 commits into
mainfrom
bokelley/api-key-creation-fix

Conversation

@bokelley

@bokelley bokelley commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

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-store and 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:manage with the app's existing policy—owner/admin only, removed from member. The previous permission settings were saved for rollback.

Validation:

  • 210 focused API key route tests passed, including provider refusals, token binding, secret withholding, and reconciliation guidance.
  • 89 PostgreSQL integration tests passed with real identity/epoch locks and modeled WorkOS boundaries.
  • Both mutation queries validated against the published WorkOS GraphQL schema. A live temporary key was created with the exact mutations, validated successfully, revoked, and confirmed invalid afterward; no key value was logged or retained.
  • Independent code and security reviews passed after addressing both code-review findings.
  • Full normal pre-commit hook passed on the final audit-fix head 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.

Comment thread server/src/routes/api-keys.ts Resolved
aao-secretariat[bot]
aao-secretariat Bot previously approved these changes Nov 5, 2026

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bokelley
bokelley merged commit 12b25de into main Nov 5, 2026
31 checks passed
@bokelley
bokelley deleted the bokelley/api-key-creation-fix branch November 5, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant