Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(status): match stored status media types case-insensitively
Yudhi Armyndharisec05449a6b59
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex 7b5752172..bdf4663e5 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -4243,6 +4243,8 @@ Stream a stored status's media bytes (the file behind a `mediaUrl` returned abov**Response** `200` — the raw media bytes as the response body, served as an **attachment** (`Content-Disposition: attachment`, `X-Content-Type-Options: nosniff`). `Content-Type` is the stored mimetype when it belongs to the image/video/audio families — except `image/svg+xml` in any parameterized or whitespace-padded form, which is scriptable despite the `image/` prefix — and `application/octet-stream` otherwise, so no stored status media is ever served as active content on the API origin. Streamed via `StreamableFile` from whatever backs `StorageService` (local disk or S3 — the route does not care which).+The stored mimetype is trimmed and lowercased before either check, and the served `Content-Type` is that normalized value, since MIME types are case-insensitive.+**Errors:** `401` missing/invalid API key, or key not scoped to this session · `404` `Status media not found or expired` — the status is text-only, its media was omitted (e.g. over the configured size cap), or the 24h TTL has since purged the rowNote: `:statusId/media` is a two-path-segment route, so it never collides with the single-segment `GET /status/:id` above regardless of declaration order.diff --git a/src/modules/status/status.service.spec.ts b/src/modules/status/status.service.spec.tsindex 38c13a333..a6017fc85 100644--- a/src/modules/status/status.service.spec.ts+++ b/src/modules/status/status.service.spec.ts@@ -151,7 +151,15 @@ describe('StatusService media validation and selection', () => {expect(media.mimetype).toBe('application/octet-stream');});- it.each(['image/svg+xml;charset=utf-8', 'image/svg+xml ', 'image/svg+xml ;charset=utf-8'])(+ it.each([+ 'image/svg+xml;charset=utf-8',+ 'image/svg+xml ',+ 'image/svg+xml ;charset=utf-8',+ 'image/SVG+XML',+ 'image/Svg+Xml; charset=utf-8',+ 'IMAGE/svg+xml;charset=utf-8',+ ' image/svg+xml',+ ])('serves the parameterized/spaced form %s as inert octet-stream too (browsers parse it as SVG)',async mimetype => {// The stored mimetype is engine-reported verbatim, so it can carry MIME parameters or@@ -174,7 +182,20 @@ describe('StatusService media validation and selection', () => {const media = await service.getStatusMedia('sess', 'w1');- expect(media.mimetype).toBe('image/jpeg;charset=ISO-8859-1');+ expect(media.mimetype).toBe('image/jpeg;charset=iso-8859-1');+ });++ it.each([+ ['text/HTML', 'application/octet-stream'],+ ['IMAGE/JPEG', 'image/jpeg'],+ ['audio/ogg; codecs=opus', 'audio/ogg; codecs=opus'],+ ])('serves a stored %s as %s', async (stored, served) => {+ store.getMedia.mockResolvedValue({ path: 'statuses/sess/x', mimetype: stored });+ storageService.getFile.mockResolvedValue(Buffer.from('x'));++ const media = await service.getStatusMedia('sess', 'w1');++ expect(media.mimetype).toBe(served);});});diff --git a/src/modules/status/status.service.ts b/src/modules/status/status.service.tsindex 83038e132..e4377f5f7 100644--- a/src/modules/status/status.service.ts+++ b/src/modules/status/status.service.ts@@ -94,9 +94,12 @@ export class StatusService {}try {const buffer = await this.storageService.getFile(media.path);+ // MIME types are case-insensitive, and a browser treats `image/SVG+XML` exactly as it treats+ // `image/svg+xml`: both checks run on the normalized form, and that form is what gets served.+ const declared = media.mimetype.trim().toLowerCase();const mimetype =- SAFE_STATUS_MIMETYPE.test(media.mimetype) && !SCRIPTABLE_SVG_MIMETYPE.test(media.mimetype)- ? media.mimetype+ SAFE_STATUS_MIMETYPE.test(declared) && !SCRIPTABLE_SVG_MIMETYPE.test(declared)+ ? declared: 'application/octet-stream';return { buffer, mimetype };} catch (error) {