T09 · Insecure Skill Coding Practices
- Location
ai-article-detector.js:50- Finding
Unrestricted URL Fetching Enables Server-Side Request Forgery
- Content
View full analysis
Vulnerability Details
File Location:
ai-article-detector.js, lines 50-61
Vulnerability Type: Server-Side Request Forgery (SSRF)
Risk Level: HighVulnerable Code
js const response = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)' } }); if (!response.ok) throw new Error(`HTTP ${response.status}`); const html = await response.text();Technical Analysis
The URL supplied through the command-line argument is passed to
fetch()without validating its protocol, hostname, resolved IP address, destination port, or redirect chain. Although outbound network access is necessary to retrieve an article, unrestricted access to arbitrary network destinations exceeds the minimum privileges needed for this functionality.An attacker can provide a URL targeting loopback addresses, private network ranges, link-local services, or cloud instance metadata endpoints. Because
node-fetchfollows redirects by default, an initially public URL may also redirect the request to an internal destination. Destination validation performed only before the initial request would therefore be insufficient.The retrieved response is parsed and analyzed locally. The reviewed code does not transmit the retrieved article to a fixed third party, but it can still act as a network request proxy into resources accessible from the host.
Attack Path
- An attacker supplies a crafted URL as the first command-line argument or passes it to
detect(). detect()forwards the value tofetchArticle().fetchArticle()passes the untrusted URL directly tofetch().- The request reaches an internal service directly, or a public attacker-controlled endpoint redirects it to an internal service.
- The application reads the internal response and processes its contents as article text.
- Observable output, response status, errors, processing behavior, and ar ...[truncated 771 chars]
- An attacker supplies a crafted URL as the first command-line argument or passes it to
- Remediation
View remediation
Remediation Suggestions
- Parse input with the standard
URLclass and allow only explicitly required protocols, normallyhttps:and optionallyhttp:. - Reject URLs containing embedded credentials or unsupported destination ports.
- Resolve the hostname before connecting and reject all loopback, private, link-local, multicast, unspecified, and reserved IPv4 and IPv6 ranges.
- Protect against DNS rebinding by ensuring the connection uses the validated address and by checking every resolved address.
- Disable automatic redirects or manually process redirects with a strict limit. Revalidate the protocol, hostname, port, and resolved addresses at every redirect.
- Prefer an allowlist of approved public domains if arbitrary websites are not essential.
- Apply outbound firewall or sandbox rules that prevent the process from accessing local, private, and metadata networks.
- Return generic network errors where possible to reduce the usefulness of the application as an internal network oracle.
- Parse input with the standard
