T09 · Insecure Skill Coding Practices
- Location
scripts/fetch_news.mjs:49- Finding
Unrestricted URL Fetching Enables Server-Side Request Forgery
- Content
View full analysis
!a.startsWith('--')); const useDirect = args.includes('--direct'); ``` ```js async function fetchDirect(targetUrl) { const response = await fetch(targetUrl, { headers: { 'User-Agent': 'Mozilla/5.0 (compatible; NewsFetcher/2.0)' } }); if (!response.ok) { throw new Error(`HTTP ${response.status}`); } const text = await response.text(); return { raw_content: text }; } ``` ```js console.log(`🔗 访问链接: ${url}\n`); try { const result = await fetchDirect(url); if (result.raw_content && result.raw_content.length > 300) { console.log(`✅ 成功获取`); console.log(` 📊 ${result.raw_content.length} 字符\n`); console.log('─'.repeat(50)); console.log('📄 内容:\n'); console.log(result.raw_content.substring(0, 5000)); } else { console.log('❌ 内容不足'); } ``` ### Technical Analysis The script accepts a URL directly from command-line input and passes it to `node-fetch` without validating its scheme, hostname, resolved IP address, port, or redirect destinations. Although the declared function only requires access to public news sources, the implementation permits requests to arbitrary network locations reachable from the host. Consequently, an attacker may supply URLs targeting loopback interfaces, private network ranges, link-local addresses, internal DNS names, or cloud instance metadata services. Redirects also require validation because `node-fetch` follows redirects by default; an apparently public URL could redirect to a prohibited internal endpoint. The script reads the response body and prints up to 5,000 characters. This turns otherwise blind SSRF into a response-disclosure channel and may expo ...[truncated 1572 chars]- Remediation
View remediation
