Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(security): refuse the dev API key in production (#325)
Yudhi Armyndharisf44ab0f9eeec
diff --git a/src/config/bootstrap-security.spec.ts b/src/config/bootstrap-security.spec.tsindex 6f80ba986..1e9f1053e 100644--- a/src/config/bootstrap-security.spec.ts+++ b/src/config/bootstrap-security.spec.ts@@ -111,6 +111,22 @@ describe('assertNoDefaultSecretsInProduction', () => {);});+ it('refuses prod when ALLOW_DEV_API_KEY=true (it seeds the public dev-admin-key as ADMIN)', () => {+ expect(() => assertNoDefaultSecretsInProduction({ nodeEnv: 'production', allowDevApiKey: 'true' })).toThrow(+ /ALLOW_DEV_API_KEY/,+ );+ });++ it('refuses prod with API_MASTER_KEY set to the well-known dev-admin-key', () => {+ expect(() => assertNoDefaultSecretsInProduction({ nodeEnv: 'production', apiMasterKey: 'dev-admin-key' })).toThrow(+ /API_MASTER_KEY/,+ );+ });++ it('allows ALLOW_DEV_API_KEY=true outside production (the dev opt-in still works)', () => {+ expect(() => assertNoDefaultSecretsInProduction({ nodeEnv: 'development', allowDevApiKey: 'true' })).not.toThrow();+ });+it('allows the default sqlite + local-storage prod setup (no secrets needed)', () => {expect(() =>assertNoDefaultSecretsInProduction({ nodeEnv: 'production', databaseType: 'sqlite', storageType: 'local' }),diff --git a/src/config/bootstrap-security.ts b/src/config/bootstrap-security.tsindex 0d6e220b9..65bd0eb1a 100644--- a/src/config/bootstrap-security.ts+++ b/src/config/bootstrap-security.ts@@ -50,6 +50,7 @@ const FORBIDDEN_PROD_SECRETS = new Set(['minioadmin','your-secure-password','dev-master-key',+ 'dev-admin-key','changeme','change-me','password',@@ -65,6 +66,8 @@ export interface SecretCheckEnv {s3AccessKey?: string;s3SecretKey?: string;apiMasterKey?: string;+ /** ALLOW_DEV_API_KEY — when 'true' it seeds the well-known public `dev-admin-key` as an ADMIN credential. */+ allowDevApiKey?: string;}/**@@ -90,6 +93,11 @@ export function assertNoDefaultSecretsInProduction(env: SecretCheckEnv): void {if (env.apiMasterKey && FORBIDDEN_PROD_SECRETS.has(env.apiMasterKey.trim().toLowerCase())) {problems.push('API_MASTER_KEY');}+ // ALLOW_DEV_API_KEY=true seeds the publicly-documented `dev-admin-key` as an ADMIN credential+ // (when no API_MASTER_KEY is set) — never allow that opt-in to be carried into production.+ if (env.allowDevApiKey === 'true') {+ problems.push('ALLOW_DEV_API_KEY (seeds the public dev-admin-key)');+ }if (problems.length > 0) {throw new Error(diff --git a/src/main.ts b/src/main.tsindex 372a2b11d..a594ac3a3 100644--- a/src/main.ts+++ b/src/main.ts@@ -99,6 +99,7 @@ async function bootstrap() {s3AccessKey: process.env.S3_ACCESS_KEY,s3SecretKey: process.env.S3_SECRET_KEY,apiMasterKey: process.env.API_MASTER_KEY,+ allowDevApiKey: process.env.ALLOW_DEV_API_KEY,});// Disable Nest's default body parser so we can set an explicit size cap below.