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 <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user