Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(auth): stop the pepper advisory from advising a key re-issue
Yudhi Armyndharisef5cc0ee38c5
diff --git a/src/main-logging.spec.ts b/src/main-logging.spec.tsindex 066631f16..27f9e2fee 100644--- a/src/main-logging.spec.ts+++ b/src/main-logging.spec.ts@@ -13,3 +13,15 @@ describe('bootstrap logging', () => {expect(source).not.toMatch(/\bconsole\.\w+\(/);});});++describe('API_KEY_PEPPER advisory', () => {+ // A pepper set on an install with keys locks every key out, the admin key included, so the advisory+ // must not tell the operator to enable it and then re-issue keys through the API.+ it('names the lockout and the recovery instead of a re-issue', () => {+ const source = readFileSync(resolve(__dirname, 'main.ts'), 'utf8');++ expect(source).not.toMatch(/re-issue keys|re-hashes keys/);+ expect(source).toContain('before the first boot');+ expect(source).toContain('until the previous pepper is restored');+ });+});diff --git a/src/main.ts b/src/main.tsindex b557bd258..18b1b6949 100644--- a/src/main.ts+++ b/src/main.ts@@ -98,11 +98,13 @@ async function bootstrap() {});// Advisory (not enforced): without API_KEY_PEPPER, stored API-key hashes use plain SHA-256. Enabling- // a pepper re-hashes keys and invalidates existing ones, so we only nudge the operator (see api-key-hash.ts).+ // a pepper on an install with keys locks every key out (see api-key-hash.ts), so we only nudge the operator.if (isApiKeyPepperMissingInProduction(process.env.NODE_ENV, process.env.API_KEY_PEPPER)) {bootstrapLogger.warn('API_KEY_PEPPER is not set in production: stored API-key hashes use plain SHA-256. ' +- 'Set API_KEY_PEPPER and re-issue keys to enable HMAC hashing.',+ 'Set API_KEY_PEPPER before the first boot to enable HMAC hashing; on an install with keys it locks out ' ++ 'every key until the previous pepper is restored, or api_keys is cleared and the instance restarted to ' ++ 'seed a new admin key.',);}