Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(auth): correct what presentedApiKey covers
Yudhi Armyndharis40112fe5222a
diff --git a/src/common/security/bearer-token.ts b/src/common/security/bearer-token.tsindex 15ad8e0e3..977e7453c 100644--- a/src/common/security/bearer-token.ts+++ b/src/common/security/bearer-token.ts@@ -14,9 +14,12 @@ interface KeyHeaders {}/**- * The API key a request presents: the `X-API-Key` header, else an `Authorization: Bearer` token. Every- * surface that authenticates a key reads it through here, so none of them can disagree on what the- * credential is. A repeated header counts by its first value; an empty one is as good as absent.+ * The API key a request presents: the `X-API-Key` header, else an `Authorization: Bearer` token. The REST+ * guard, the health probe, Bull Board, the key index and the MCP gate read it through here, so none of+ * them can disagree on what the credential is; the `/events` handshake reads `auth.apiKey`, then+ * `x-api-key`, on its own. An empty value is as good as absent. Node joins a repeated `X-API-Key` into one+ * string (`first, second`), which is no key on any surface, while a repeated `Authorization` keeps its+ * first value. The array branch of `first` is for a headers object built by hand, as the unit tests do.*/export function presentedApiKey(headers: KeyHeaders): string | undefined {const first = (value: string | string[] | undefined): string | undefined => (Array.isArray(value) ? value[0] : value);