Skip to content

fix(rest): REST data API honors sys_api_key — shared verifier with MCP (closes #1633)#1634

Merged
xuyushun441-sys merged 1 commit into
mainfrom
fix/rest-api-key-auth
Jun 7, 2026
Merged

fix(rest): REST data API honors sys_api_key — shared verifier with MCP (closes #1633)#1634
xuyushun441-sys merged 1 commit into
mainfrom
fix/rest-api-key-auth

Conversation

@xuyushun441-sys
Copy link
Copy Markdown
Contributor

Closes #1633. Staging e2e found MCP authenticated a sys_api_key but REST /api/v1/data 401'd the same key. Converged both onto ONE verifier: @objectstack/core/security owns the shared primitives + new resolveApiKeyPrincipal (fail-closed); runtime re-exports core + resolveExecutionContext delegates to it; rest's resolveExecCtx tries it before getSession so /data+/meta authenticate the key under permissions+RLS like MCP. Tests: core 9 + runtime 381 + rest 88 green.

🤖 Generated with Claude Code

closes #1633)

Staging e2e found MCP authenticated a sys_api_key but REST /api/v1/data 401'd the
same key — rest's resolveExecCtx only checked the better-auth session.

Converged both surfaces onto ONE verifier (no drift):
- @objectstack/core/security: shared key primitives + new
  resolveApiKeyPrincipal(ql, headers, nowMs?) (hash→lookup→reject
  unknown/revoked/expired/owner-less, fail-closed). core = cycle-free shared
  home (rest→core, runtime→core, core→neither; server-side).
- runtime: api-key.ts re-exports core (stable surface); resolveExecutionContext
  delegates its key branch to resolveApiKeyPrincipal.
- rest: resolveExecCtx tries resolveApiKeyPrincipal before getSession → /data +
  /meta authenticate the key under its permissions + RLS, like MCP.

Tests: core api-key.test.ts (9, primitives+verifier); runtime 381 + rest 88 green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Building Building Preview, Comment Jun 7, 2026 2:41am

Request Review

@xuyushun441-sys xuyushun441-sys merged commit c262301 into main Jun 7, 2026
7 of 8 checks passed
@github-actions github-actions Bot added documentation Improvements or additions to documentation tests tooling labels Jun 7, 2026
@xuyushun441-sys xuyushun441-sys deleted the fix/rest-api-key-auth branch June 7, 2026 02:41
@github-actions github-actions Bot added the size/l label Jun 7, 2026
* cannot recover the raw key by probing for partial matches.
*/
export function hashApiKey(raw: string): string {
return createHash('sha256').update(raw, 'utf8').digest('hex');
if (x && x.trim()) return x.trim();
const auth = readHeader(headers, 'authorization');
if (!auth) return undefined;
const m = auth.match(/^ApiKey\s+(.+)$/i);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

REST data API (@objectstack/rest) doesn't honor sys_api_key — only MCP/dispatch path does (ADR-0036)

3 participants