fix(input-handler): validate URLs against SSRF and add zip-slip protection#159
fix(input-handler): validate URLs against SSRF and add zip-slip protection#159mimran-khan wants to merge 1 commit into
Conversation
…ip-slip protection Three security hardening changes to the input handler: 1. SSRF protection: Both git clone and file download now validate the target hostname against an allowlist of known-safe hosts (GitHub, GitLab, Bitbucket, HuggingFace). URLs resolving to private/loopback IPs are blocked regardless of hostname. 2. Zip-slip prevention: Archive extraction now validates every member path against the extraction directory to prevent path traversal attacks (e.g., ../../etc/passwd entries). 3. Configurable allowlists: ALLOWED_GIT_HOSTS and ALLOWED_DOWNLOAD_HOSTS are module-level constants that can be extended for enterprise deployments with internal forges. Fixes NVIDIA#147
|
Thanks for picking this up. I read the post-#159 One gap remains, and I think it is load-bearing. On the zip side I'd leave Happy to be wrong on the redirect point, push back with the hop you think revalidates if I missed one. Otherwise the allowlist and private-IP work is good and I'd like to see it land, with |
Summary
The input handler accepts arbitrary URLs for git clone and file download without validating the target host. This enables Server-Side Request Forgery (SSRF) — an attacker could craft a skill referencing internal endpoints (cloud metadata at 169.254.169.254, internal services at 10.x.x.x, etc.) to exfiltrate data or probe the network.
Additionally,
_extract_zipusesextractall()without path traversal checks, enabling zip-slip attacks where crafted archives write files outside the extraction directory.Changes
SSRF Protection
_is_private_ip()to detect loopback, private, link-local, and reserved addresses_validate_url_host()method enforcing allowlist + private IP check_clone_git()and_download_file()validate before network accessALLOWED_GIT_HOSTSandALLOWED_DOWNLOAD_HOSTSfrozensetsZip-Slip Prevention
_extract_zip()iterates all zip members and validates resolved paths stay within extraction directoryValueErrorwith clear message on path traversal attemptAllowlist Design
Testing
23 new tests covering:
Existing 6 input handler tests continue to pass.
Fixes #147