T09 · Insecure Skill Coding Practices
- Location
scripts/match_exercises.py:166- Finding
Arbitrary Dataset URL Fetching Enables Blind SSRF and Resource Exhaustion
- Content
View full analysis
list[dict[str, Any]]: if path and path.exists(): source = path else: source = cache if not source.exists(): source.parent.mkdir(parents=True, exist_ok=True) with urllib.request.urlopen(url, timeout=30) as res: source.write_bytes(res.read()) ``` The URL is exposed as an unrestricted command-line argument and passed directly to the fetch operation: ```python parser.add_argument("--dataset-url", default=DEFAULT_DATASET_URL) ``` ```python records = load_dataset(args.dataset, args.dataset_url, args.cache) ``` ### Technical Analysis The helper accepts an arbitrary value through `--dataset-url` and passes it directly to `urllib.request.urlopen()`. The implementation does not: - Restrict the scheme to HTTPS. - Allowlist the expected GitHub host. - Reject loopback, private, link-local, or other internal destinations. - Validate redirect destinations. - Impose a maximum response size. - Validate the response content type before saving it. - Stream the response with a bounded byte count. Consequently, anyone able to influence the helper's arguments can cause the process to initiate requests to attacker-selected destinations. Because the response body does not need to be successfully parsed before the request occurs, this supports blind SSRF even when the returned resource is not valid dataset JSON. The use of `res.read()` also reads the entire response into memory without a size limit. A malicious or unexpectedly large endpoint can therefore cause excessive memory consumption. The resulting content is then written to the selected cache path, potentially consuming disk space as well. # ...[truncated 1603 chars]- Remediation
View remediation
