T09 · Insecure Skill Coding Practices
- Location
scripts/baidu_img.js:91- Finding
<![CDATA[Unrestricted Remote URL and Redirect Handling Enables SSRF]]>
- Content
View full analysis
{ let redirected = 0; const visit = (u) => { const lib = u.startsWith('https') ? https : http; const req = lib.get( u, { headers, timeout: TIMEOUT_MS }, (res) => { const status = res.statusCode || 0; if (status === 301 || status === 302) { res.resume(); if (redirected++ > 5) return reject(new Error('Too many redirects')); const loc = res.headers.location; if (!loc) return reject(new Error('Redirect missing Location')); return visit(new URL(loc, u).toString()); } resolve(res); }, ); req.on('error', reject); req.on('timeout', () => req.destroy(new Error('timeout'))); }; visit(rawUrl); }); } ``` The untrusted URL is selected from remote search-result metadata and later passed to the request function: ```js for (const it of items) { const u = pickUrl(it, source); if (!u) continue; const host = (it.fromURLHost || '').trim(); ``` ```js async function downloadOne(url, outPath, referer) { const headers = { 'User-Agent': UA, Accept: 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8', }; if (referer) headers.Referer = referer; let lastErr = null; for (let i = 0; i <= RETRY; i++) { try { const buf = await httpGetBinary(url, headers); if (buf.length < 256) throw new Error(`Response data too small (${buf.length}B)`); fs.writeFileSync(outPath, buf); return buf.l ...[truncated 3293 chars]- Remediation
View remediation
