Skip to content

feat(auth): accept sktsec_-prefixed Socket API keys as Bearer tokens#187

Merged
Bret Comnes (bcomnes) merged 1 commit into
mainfrom
tuckner/allow-api-key
Jun 18, 2026
Merged

feat(auth): accept sktsec_-prefixed Socket API keys as Bearer tokens#187
Bret Comnes (bcomnes) merged 1 commit into
mainfrom
tuckner/allow-api-key

Conversation

@annextuckner

Copy link
Copy Markdown
Contributor

Problem

A client could only authenticate to an OAuth-enabled HTTP deployment (e.g. https://mcp.socket.dev/) with an OAuth access token. routeRequest ran every Authorization: Bearer token through OAuth introspection, so a raw Socket API key was rejected as invalid_token. A config like this failed:

"socket-mcp": {
  "command": "npx",
  "args": ["-y", "mcp-remote", "https://mcp.socket.dev/",
           "--header", "Authorization: Bearer sktsec_..."]
}

Change

Recognize a Socket API token by its sktsec_ prefix on the standard Authorization: Bearer header and apply it directly to req.auth, bypassing introspection. The auth dispatch is now:

Bearer token OAuth on OAuth off
sktsec_-prefixed Socket API key (skip introspection) Socket API key
other OAuth introspection (unchanged) applyClientApiKey (unchanged)

This keeps the same header working in both modes — no custom header needed — and leaves OAuth and non-OAuth behavior otherwise untouched.

The API-key helpers were extracted into lib/http-auth.ts (keeps http-server.ts under the 500-line lint cap); the test file was renamed to match.

Note

This trusts the sktsec_ prefix as the discriminator between Socket API tokens and OAuth access tokens — consistent with the SOCKET_PUBLIC_API_TOKEN constant in @socketsecurity/lib.

Verification

  • pnpm run lint
  • pnpm test — 144 passed ✅
  • pnpm run test:tsc

Local manual test (OAuth off): MCP_HTTP_MODE=true SOCKET_API_TOKEN=<sktsec_...> node --experimental-strip-types index.ts --http, then point mcp-remote at http://localhost:3000/ with --header "Authorization: Bearer sktsec_...".

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

A client could only authenticate to an OAuth-enabled HTTP deployment with
an OAuth access token: routeRequest ran every Bearer token through
introspection, so a raw Socket API key was rejected as invalid_token.

Recognize a Socket API key by its `sktsec_` prefix on the standard
`Authorization: Bearer` header and apply it directly to req.auth, skipping
introspection. OAuth access tokens (no prefix) still flow through
introspection unchanged, and non-OAuth mode is unaffected. This lets a
caller authenticate with a raw Socket key over the same header in both
modes, with no custom header.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bcomnes Bret Comnes (bcomnes) merged commit 750761a into main Jun 18, 2026
10 checks passed
@bcomnes Bret Comnes (bcomnes) deleted the tuckner/allow-api-key branch June 18, 2026 00:00

@bcomnes Bret Comnes (bcomnes) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

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.

3 participants