T09 · Insecure Skill Coding Practices
Error
- Location
- monitor.sh:25
- Finding
- Arbitrary-Target Server-Side Request Forgery in Endpoint Monitoring<![CDATA[ ## Vulnerability Details **File Location**: `monitor.sh`, lines 25-34 and 88-95 **Vulnerability Type**: Server-Side Request Forgery (SSRF) **Risk Level**: High ### Vulnerable Code Endpoint values are passed directly to `fetch()`: ```javascript async function checkEndpoint(url) { const start = Date.now(); try { const res = await fetch(url); const time = Date.now() - start; return { url, status: res.status, time, ok: res.ok }; } catch (e) { return { url, status: 0, time: Date.now() - start, ok: false, error: e.message }; } } ``` The `add` action accepts an arbitrary URL without destination validation: ```bash add) URL="$2" if [ -z "$URL" ]; then echo "Usage: $0 add <url>" exit 1 fi echo "Adding $URL..." cat endpoints.json | jq ". += [\"$URL\"]" > tmp.json && mv tmp.json endpoints.json echo "✅ Added $URL" ;; ``` ### Technical Analysis The monitor treats every configured endpoint as trusted and issues an outbound request with Node.js `fetch()`. It does not restrict URL schemes, permitted hostnames, ports, resolved IP addresses, or redirects. Consequently, a user capable of adding an endpoint can direct the monitor toward loopback interfaces, private network ranges, link-local addresses, cloud metadata services, or other destinations reachable from the host. Redirects can also potentially bypass validation unless every redirect destination is independently checked. The generated dashboard does not expose response bodies, limiting direct data extraction. Nevertheless, response status, timing, success state, and error messages are recorded, enabling internal-network probing and blind interaction with HTTP services. GET endpoints that perform state changes could also be triggered. The script does not automatically execute `server.js`; exploitation requires the generated server to be started separately. ### Attack Path 1. Run `./monitor.sh start` to generate ...[truncated 1322 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Accept only explicitly supported schemes, preferably `https:`. - Maintain an explicit allowlist of approved monitoring hostnames or domains. - Resolve each hostname before connecting and reject loopback, private, link-local, multicast, unspecified, and reserved IP ranges for both IPv4 and IPv6. - Repeat destination validation after DNS resolution and before each request to mitigate DNS rebinding. - Disable redirects or validate the scheme, hostname, port, and resolved address of every redirect destination. - Restrict destination ports to those required by the monitoring use case. - Apply outbound firewall or proxy rules so the monitor cannot reach metadata services or sensitive internal networks. - Add request timeouts, response-size limits, and concurrency limits. - Do not return detailed internal connection errors to unauthenticated clients. - Require authorization before users can add or modify monitored endpoints. ]]>
