anomalyco / anomalyco/opencode

authorize returns 500 instead of a typed error when the auth method doesn't exist

Open
#40,774 0 comments 0 reactions 1 assignee View on GitHub

@nexxeln is already working on this.

Since Aug 6, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

What happens

POST /provider/:id/authorize returns a 500 when method doesn't resolve to a registered auth method.

ProviderAuth.authorize indexes into the hook table with no guard on either lookup (packages/opencode/src/provider/auth.ts:166):

const method = hooks[input.providerID].methods[input.method]
if (method.type !== "oauth") return

AuthorizeInput.method is Schema.Finite (auth.ts:57), so any finite number decodes, and the handler passes it straight through (server/routes/instance/httpapi/handlers/provider.ts:70-74). Two inputs make method undefined and the .type read throw:

  • an index past the end of methods
  • a providerID with no registered auth hook at all

A TypeError isn't one of the typed ProviderAuth.Errors the endpoint declares, so mapProviderAuthError never converts it and the client gets a 500 instead of a structured error.

Expected

A 400 with a typed error, the way callback already does 25 lines below for the same class of problem:

const match = pending.get(input.providerID)
if (!match) return yield* new OauthMissing({ providerID: input.providerID })
Repro

With the provider-oauth-parity plugin fixture from test/server/httpapi-provider.test.ts (it registers two methods, so index 2 is one past the end):

requestAuthorize({ providerID, method: 2, headers })   // 500, expected 400
requestAuthorize({ providerID: "no-such-provider", headers })  // 500, expected 400

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.