From a46c4c62776a307be0492eb1de03b748cbabd6dd Mon Sep 17 00:00:00 2001 From: marcos-hairpieces Date: Thu, 16 Oct 2025 09:50:38 -0400 Subject: [PATCH] fix: handle binary content properly in WebDAV requests Prevents corruption of binary files (images, videos, audio, PDFs) by passing streams through as-is instead of reading them as text for WebDAV content requests. --- server/plugins/renderer/renderer.module.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/server/plugins/renderer/renderer.module.js b/server/plugins/renderer/renderer.module.js index 6dbefa17..2d9afb38 100644 --- a/server/plugins/renderer/renderer.module.js +++ b/server/plugins/renderer/renderer.module.js @@ -115,15 +115,24 @@ internals.getResponse = async (request) => { const contentType = response.headers['content-type'] || ''; const isResponseJson = contentType.toLowerCase().includes('application/json'); const isWebDavRequest = request.path.startsWith('/content'); + const isBinaryContent = contentType + .toLowerCase() + .match(/^(image|video|audio|application\/octet-stream|application\/pdf)/); let bcAppData = response.data; if (isResponseJson) { bcAppData = JSON.parse(await readFromStream(response.data)); } else if (isWebDavRequest) { - const tappedStream = tapStream(response.data, (body) => { - return body; - }); - bcAppData = await readStream(tappedStream); + if (isBinaryContent) { + // For binary content, don't read the stream - pass it through as-is + bcAppData = response.data; + } else { + // For text content, read as string + const tappedStream = tapStream(response.data, (body) => { + return body; + }); + bcAppData = await readStream(tappedStream, false); + } } // cache response cache.put(