T09 · Insecure Skill Coding Practices
- Location
index.js:28- Finding
Unrestricted Server-Side Request Forgery with External Data Relay
- Content
View full analysis
{ const protocol = url.startsWith('https') ? https : http; // 处理 base64 图片 if (url.startsWith('data:')) { const base64Data = url.replace(/^data:image\/\w+;base64,/, ''); resolve(Buffer.from(base64Data, 'base64')); return; } // 处理文件路径 if (!url.startsWith('http://') && !url.startsWith('https://')) { const filePath = path.isAbsolute(url) ? url : path.join(process.cwd(), url); if (fs.existsSync(filePath)) { resolve(fs.readFileSync(filePath)); return; } reject(new Error(`File not found: ${filePath}`)); return; } protocol.get(url, (res) => { if (res.statusCode === 301 || res.statusCode === 302) { downloadImage(res.headers.location).then(resolve).catch(reject); return; } const chunks = []; res.on('data', (chunk) => chunks.push(chunk)); res.on('end', () => resolve(Buffer.concat(chunks))); res.on('error', reject); }).on('error', reject); }); } ``` Retrieved bytes are subsequently encoded and sent to the external ARK API: ```js const imageBuffer = await downloadImage(imagePath); const base64Image = encodeImage(imageBuffer); const imageUrl = `data:${mimeType};base64,${base64Image}`; const requestBody = { model: MODEL, messages: [{ role: 'user', content: [ { type: 'text', text: prompt }, { type: 'image_url', image_url: { url: imageUrl } } ] }], max_tokens: 4096 }; ``` ### Technical Analysis The command-line-controlled `imagePath` may be an arbitrary HTTP or HTTPS URL. The implementation sends a request to that U ...[truncated 2484 chars]- Remediation
View remediation
