T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/discover_flows.py:40
- Finding
- Unrestricted URL Fetching Enables Server-Side Request Forgery<![CDATA[ ## Vulnerability Details **File Location**: `scripts/discover_flows.py`, lines 40–54 **Vulnerability Type**: Server-Side Request Forgery (SSRF) **Risk Level**: High ### Vulnerable Code ```python ap.add_argument('--url', required=True) ap.add_argument('--timeout', type=int, default=20) args = ap.parse_args() base = args.url.strip() if not base.startswith('http://') and not base.startswith('https://'): base = 'https://' + base pages = ['/', '/pricing', '/api', '/docs', '/blog', '/changelog', '/downloads'] seen = set() discovered = [] for p in pages: try: r = requests.get(urljoin(base, p), timeout=args.timeout, allow_redirects=True, headers={'User-Agent': 'OpenClawFlowMonitor/1.0'}) ``` ### Technical Analysis The command-line `--url` value is used as the base of outbound HTTP requests without validating its hostname, destination port, DNS resolution results, or network address range. Both HTTP and HTTPS destinations are accepted. Consequently, a user can direct the script to loopback, private, link-local, reserved, or otherwise internal network destinations. The fixed `pages` collection causes the application to make up to seven requests against the selected host, allowing it to probe several common application paths. The use of `allow_redirects=True` creates an additional bypass path. Even if validation of the original URL were added elsewhere, an attacker-controlled public endpoint could redirect the request to an internal address. The script does not inspect or revalidate redirect destinations. Although response bodies are not printed directly, they are parsed for links. Discovered URLs and source locations are subsequently included in the generated JSON output, which can reveal internal hostnames, paths, ports, and service structure. ### Attack Path 1. An attacker supplies a target such as `http://127.0.0.1:8080`, a private-network hostname, a link-local cloud metadata address, or an attacker-controlled public redirector. ...[truncated 1600 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Restrict supported schemes** - Permit HTTPS by default. - Reject non-HTTP schemes explicitly. - Permit plain HTTP only through a deliberate, documented override. 2. **Validate resolved addresses** - Resolve the destination hostname before each connection. - Reject IPv4 and IPv6 addresses that are loopback, private, link-local, multicast, reserved, unspecified, or otherwise non-global. - Validate every returned DNS address rather than only the first result. - Protect against DNS rebinding by ensuring the validated address is the address actually used for the connection. 3. **Secure redirect handling** - Disable automatic redirects with `allow_redirects=False`. - If redirects are necessary, process them one at a time with a strict maximum. - Normalize, resolve, and validate the scheme, hostname, port, and resolved addresses of every redirect target before following it. 4. **Restrict destinations and ports** - Prefer an explicit hostname allowlist for scheduled monitoring. - Bind each monitoring job to the hostname explicitly approved by the user. - Restrict ports to an approved set such as 443, with narrowly scoped exceptions where required. 5. **Limit response processing** - Use streaming requests and enforce a maximum response-body size. - Accept and parse only expected textual content types. - Apply separate connection and read timeouts. 6. **Reduce information exposure** - Avoid returning internal destination details in generated JSON or logs. - Report rejected requests without disclosing sensitive network-resolution information. - Log validation failures securely for administrative review. 7. **Add security tests** - Test direct requests to loopback, RFC1918, IPv4-mapped IPv6, link-local, and cloud metadata addresses. - Test public-to-private redirects, alternate IP representations, DNS rebinding scenarios, and user-info or port parsing edge cases. ]]>
