anomalyco / anomalyco/opencode
authorize returns 500 instead of a typed error when the auth method doesn't exist
@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
providerIDwith 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.