T09 · Insecure Skill Coding Practices
- Location
scripts/download.js:34- Finding
Arbitrary File Overwrite and Unrestricted Remote File Download
- Content
View full analysis
{ const urlObj = new URL(url); const file = fs.createWriteStream(outputPath); const options = { hostname: urlObj.hostname, port: urlObj.port || 443, path: urlObj.pathname + urlObj.search, method: 'GET' }; console.log(`📥 开始下载: ${outputPath}`); const req = https.request(options, (res) => { if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { // 重定向,递归下载 file.close(); downloadFile(res.headers.location, outputPath).then(resolve).catch(reject); return; } res.pipe(file); file.on('finish', () => { file.close(); const stats = fs.statSync(outputPath); console.log(`✅ 下载完成! 大小: ${(stats.size / 1024 / 1024).toFixed(2)} MB`); resolve(); }); }); ``` ```js // scripts/download.js:109-128 async function downloadVideo(fileId, outputPath) { const apiKey = getApiKey(); // 确保输出目录存在 const dir = path.dirname(outputPath); if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); } // 先获取下载链接 console.log(`🔍 获取文件 ${fileId} 的下载链接...`); const url = `https://api.minimaxi.com/v1/files/retrieve?file_id=${fileId}`; const result = await httpGet(url, apiKey); if (result.file?.download_url) { console.log('📎 获取到下载链接,准备下载...'); await downloadFile(result.file.download_url, outputPath); return result.file; } else { console.error('❌ 获取下载链接失败:', result); process.exit(1 ...[truncated 3590 chars]- Remediation
View remediation
