Skip to content

Commit 9e38939

Browse files
committed
fix(sandbox): strict MIME allowlist and nullish coalescing in docx addImage
1 parent 508edf6 commit 9e38939

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

apps/sim/sandbox-tasks/docx-generate.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ export const docxGenerateTask = defineSandboxTask<SandboxTaskInput>({
5858
const header = comma !== -1 ? dataUri.slice(0, comma) : '';
5959
const base64 = comma !== -1 ? dataUri.slice(comma + 1) : dataUri;
6060
const mime = header.split(';')[0].replace('data:', '') || 'image/png';
61-
const ext = mime.includes('png') ? 'png' : mime.includes('gif') ? 'gif' : mime.includes('bmp') ? 'bmp' : 'jpg';
61+
const extMap = { 'image/png': 'png', 'image/jpeg': 'jpg', 'image/jpg': 'jpg', 'image/gif': 'gif', 'image/bmp': 'bmp', 'image/svg+xml': 'svg' };
62+
const ext = extMap[mime];
63+
if (!ext) throw new Error('addImage: unsupported image type "' + mime + '". Use PNG, JPEG, GIF, BMP, or SVG.');
6264
if (!globalThis.Buffer) throw new Error('addImage: Buffer polyfill missing — ensure docx bundle is loaded');
6365
return new globalThis.docx.ImageRun(Object.assign({
6466
data: globalThis.Buffer.from(base64, 'base64'),
65-
transformation: { width: (opts && opts.width) || 200, height: (opts && opts.height) || 200 },
67+
transformation: { width: opts?.width ?? 200, height: opts?.height ?? 200 },
6668
type: ext,
6769
}, opts || {}));
6870
};

0 commit comments

Comments
 (0)