Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(config): refuse an S3 endpoint that is not an http(s) URL
Yudhi Armyndharis24c02f162d95
diff --git a/src/config/env.validation.spec.ts b/src/config/env.validation.spec.tsindex 11d058839..3d1e5b6d1 100644--- a/src/config/env.validation.spec.ts+++ b/src/config/env.validation.spec.ts@@ -627,6 +627,41 @@ describe('validateEnv', () => {expect(() => validateEnv({ NODE_URL: 'https://node-a.internal' })).not.toThrow();});+ // Without a scheme the S3 client throws "Invalid URL" on every call and media quietly lands on local disk.+ describe('S3_ENDPOINT', () => {+ it.each(['minio:9000', '127.0.0.1:9000', 'localhost:9000', 'minio', 'ftp://minio:9000'])(+ 'rejects %s while S3 is the selected storage',+ endpoint => {+ expect(() => validateEnv({ STORAGE_TYPE: 's3', S3_ENDPOINT: endpoint })).toThrow(+ /S3_ENDPOINT must be an absolute http\(s\) URL/,+ );+ },+ );++ it('does not echo the value, which may carry credentials', () => {+ expect(() => validateEnv({ STORAGE_TYPE: 's3', S3_ENDPOINT: 'AKIAKEY:hunter2@s3host:9000' })).not.toThrow(+ /hunter2/,+ );+ expect(() => validateEnv({ STORAGE_TYPE: 's3', S3_ENDPOINT: 'AKIAKEY:hunter2@s3host:9000' })).toThrow(+ /S3_ENDPOINT/,+ );+ });++ it.each(['http://minio:9000', 'https://s3.example.com', 'https://gateway.example.com/s3/', ' http://minio:9000 '])(+ 'accepts %s',+ endpoint => {+ expect(() => validateEnv({ STORAGE_TYPE: 's3', S3_ENDPOINT: endpoint })).not.toThrow();+ },+ );++ it('leaves an unset or blank endpoint alone, and a stale one while storage is local', () => {+ expect(() => validateEnv({ STORAGE_TYPE: 's3' })).not.toThrow();+ expect(() => validateEnv({ STORAGE_TYPE: 's3', S3_ENDPOINT: ' ' })).not.toThrow();+ expect(() => validateEnv({ STORAGE_TYPE: 'local', S3_ENDPOINT: 'minio:9000' })).not.toThrow();+ expect(() => validateEnv({ S3_ENDPOINT: 'minio:9000' })).not.toThrow();+ });+ });+it('rejects a non-positive media-conversion knob instead of silently using the default', () => {expect(() => validateEnv({ MEDIA_CONVERSION_CONCURRENCY: '0' })).toThrow(/positive integer/);expect(() => validateEnv({ MEDIA_CONVERSION_TIMEOUT_MS: 'abc' })).toThrow(/positive integer/);diff --git a/src/config/env.validation.ts b/src/config/env.validation.tsindex 7b5b6f16c..af75a65ba 100644--- a/src/config/env.validation.ts+++ b/src/config/env.validation.ts@@ -620,6 +620,22 @@ export function validateEnv(config: EnvConfig): EnvConfig {}}+ // The S3 client builds every request from this URL. A value without a scheme (`minio:9000`) fails each call as+ // "Invalid URL" and media goes to the local fallback directory instead, so a typo in the endpoint reads as a+ // working bucket. Only checked while S3 is the selected storage; the value is not echoed, as it may hold keys.+ const s3Endpoint = str('S3_ENDPOINT');+ if (s3Endpoint && rawEnum('STORAGE_TYPE') === 's3') {+ let protocol: string | undefined;+ try {+ protocol = new URL(s3Endpoint).protocol;+ } catch {+ protocol = undefined;+ }+ if (protocol !== 'http:' && protocol !== 'https:') {+ errors.push('S3_ENDPOINT must be an absolute http(s) URL such as "http://minio:9000"');+ }+ }+// Boolean feature flags read at module-eval time (app.module.ts) with a bare `=== 'true'` /// `!== 'false'` comparison: a typo (`True`, `1`, `yes`) or trailing whitespace/CR silently// (dis)ables the feature. Validate the RAW value — NOT a trimmed one — so `'true '` / `'true\r'`