From dfc5645de2679840efc043168bc5b62070ad17ff Mon Sep 17 00:00:00 2001 From: Ian Mustafa Date: Tue, 9 Dec 2025 12:21:57 +0700 Subject: [PATCH] Add verbosity to missing auth headers error (#3) --- src/middlewares/apiKeyAuth.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/middlewares/apiKeyAuth.ts b/src/middlewares/apiKeyAuth.ts index e815478..26c0477 100644 --- a/src/middlewares/apiKeyAuth.ts +++ b/src/middlewares/apiKeyAuth.ts @@ -186,11 +186,26 @@ export const apiKeyAuthMacro = new Elysia().macro({ const nonce = headers['x-nonce'] const signature = headers['x-signature'] const rawTimestamp = headers['x-timestamp'] + + const missingHeaders = [] + if (!apiKey) { + missingHeaders.push('X-API-Key') + } + if (!nonce) { + missingHeaders.push('X-Nonce') + } + if (!rawTimestamp) { + missingHeaders.push('X-Timestamp') + } + if (!signature) { + missingHeaders.push('X-Signature') + } if (!apiKey || !nonce || !signature || !rawTimestamp) { + const missing = missingHeaders.join(', ') logger.debug({ 'headers.authorization': headers.authorization, - }, 'Failed API key authentication attempt due to missing auth headers') - throw new UnauthenticatedError('Missing auth headers') + }, 'Failed API key authentication attempt due to missing auth headers: ' + missing) + throw new UnauthenticatedError('Missing auth headers: ' + missing) } const timestamp = Number(rawTimestamp)