Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(config): validate the CSP, Swagger, error-detail and pin flags

Yudhi Armyndharisf3fb6a54baf7
diff --git a/src/config/env.validation.spec.ts b/src/config/env.validation.spec.ts
index a9967dd5e..7b3e99a7d 100644
--- a/src/config/env.validation.spec.ts
+++ b/src/config/env.validation.spec.ts
@@ -595,6 +595,23 @@ describe('validateEnv', () => {
},
);
+ // Read as an exact 'true'/'false' override; anything else falls back to the NODE_ENV default, so
+ // CSP_UPGRADE_INSECURE_REQUESTS=False kept the blank-dashboard trap on in production.
+ it.each([
+ 'CSP_UPGRADE_INSECURE_REQUESTS',
+ 'ENABLE_SWAGGER',
+ 'VALIDATION_ERROR_DETAIL',
+ 'PLUGIN_INSTALL_REQUIRE_PIN',
+ 'WEBHOOK_SSRF_REDIRECTS',
+ ])('accepts only an exact true or false for %s', key => {
+ for (const bad of ['False', 'TRUE', '0', 'false\r']) {
+ expect(() => validateEnv({ [key]: bad })).toThrow(new RegExp(`${key} must be "true" or "false"`));
+ }
+ for (const ok of ['true', 'false', '']) {
+ expect(() => validateEnv({ [key]: ok })).not.toThrow();
+ }
+ });
+
it('accepts only an exact true or false for REDIS_TLS', () => {
expect(() => validateEnv({ REDIS_TLS: 'yes' })).toThrow(/REDIS_TLS must be "true" or "false"/);
expect(() => validateEnv({ REDIS_TLS: 'true ' })).toThrow(/REDIS_TLS/);
diff --git a/src/config/env.validation.ts b/src/config/env.validation.ts
index 6d4c1a477..a4aa5703a 100644
--- a/src/config/env.validation.ts
+++ b/src/config/env.validation.ts
@@ -577,6 +577,15 @@ export function validateEnv(config: EnvConfig): EnvConfig {
// Perf/observability only, but same silent-typo class.
'CACHE_ENABLED',
'DATABASE_LOGGING',
+ // Exact 'true'/'false' overrides; any other spelling silently falls back to the NODE_ENV default,
+ // so `CSP_UPGRADE_INSECURE_REQUESTS=False` kept the blank-dashboard upgrade on in production and a
+ // `PLUGIN_INSTALL_REQUIRE_PIN=True` outside production left the integrity pin unenforced.
+ 'CSP_UPGRADE_INSECURE_REQUESTS',
+ 'ENABLE_SWAGGER',
+ 'VALIDATION_ERROR_DETAIL',
+ 'PLUGIN_INSTALL_REQUIRE_PIN',
+ // `=== 'true'` in the SSRF guard: a typo keeps redirects refused when the operator allowed them.
+ 'WEBHOOK_SSRF_REDIRECTS',
// DELIBERATELY NOT LISTED. `MCP_READONLY` is read `!== 'false'` and mcp.server.spec.ts asserts
// that `yes` keeps it read-only — a tolerance the repo tests on purpose. `PUPPETEER_HEADLESS` is
// read `!== 'false'` and `new` is a real Puppeteer value that works today. Both fail toward the