T09 · Insecure Skill Coding Practices
- Location
scripts/download_logos.js:172- Finding
Path Traversal Enables Arbitrary File Overwrite
- Content
View full analysis
{ const protocol = url.startsWith('https') ? https : http; const file = fs.createWriteStream(dest); const req = protocol.get(url, { headers: { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36', 'Referer': 'https://image.baidu.com/', 'Accept': 'image/webp,image/apng,image/*,*/*;q=0.8', }, timeout: 20000 }, (response) => { if ([301, 302].includes(response.statusCode)) { file.close(); fs.unlink(dest, () => {}); const loc = response.headers.location; if (loc && loc.startsWith('http')) return downloadFile(loc, dest).then(resolve).catch(reject); return reject(new Error('bad redirect')); } if (response.statusCode !== 200) { file.close(); fs.unlink(dest, () => {}); return reject(new Error('HTTP ' + response.statusCode)); } response.pipe(file); file.on('finish', () => { file.close(); const size = fs.statSync(dest).size; if (size < 1000) { fs.unlink(dest, () => {}); return reject(new Error(`File too small (${size}b)`)); } resolve(dest); }); }); req.on('error', (e) => { file.close(); fs.unlink(dest, () => {}); reject(e); }); req.on('timeout', () => { req.destroy(); file.close(); fs.unlink(dest, () => {}); reject(new Error('timeout')); }); }); } ``` ```javascript const destPath = path.join(outputDir, c.file); ``` The retry implementation contains the same i ...[truncated 2296 chars]- Remediation
View remediation
