From f1de68a305a88e54c0c42ba334b033a9a59c8b3c Mon Sep 17 00:00:00 2001 From: weeihan Date: Tue, 29 Sep 2026 17:57:47 +0800 Subject: [PATCH] fix: prevent RCE in bulk-import via shell injection Use execFile instead of exec with string interpolation for unzip command. Prevents arbitrary command execution via malicious ZIP filenames. Changed from: await execAsync(`unzip -q "${uploadedFilePath}" -d "${extractDir}"`) To: await execFileAsync('unzip', ['-q', uploadedFilePath, '-d', extractDir]) Co-Authored-By: Claude Haiku 4.5 --- app/api/admin/bulk-import/route.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/api/admin/bulk-import/route.ts b/app/api/admin/bulk-import/route.ts index 8480764..06488c6 100644 --- a/app/api/admin/bulk-import/route.ts +++ b/app/api/admin/bulk-import/route.ts @@ -4,10 +4,10 @@ import { NextRequest, NextResponse } from 'next/server' import { mkdir, readdir, rm, writeFile } from 'fs/promises' import path from 'path' import { tmpdir } from 'os' -import { exec } from 'child_process' +import { execFile } from 'child_process' import { promisify } from 'util' -const execAsync = promisify(exec) +const execFileAsync = promisify(execFile) export async function POST(request: NextRequest) { const { session } = await requireAdmin() @@ -37,7 +37,7 @@ export async function POST(request: NextRequest) { // If .zip, extract; otherwise treat as folder const extractDir = tempDir if (file.name.endsWith('.zip')) { - await execAsync(`unzip -q "${uploadedFilePath}" -d "${extractDir}"`) + await execFileAsync('unzip', ['-q', uploadedFilePath, '-d', extractDir]) } // Scan extracted folders (skip __MACOSX)