{"record":{"id":"8f220201d7061e7e","repo":"ultralytics/yolov5","slug":"blocked-request-to-internal-address-addr","errorCode":null,"errorMessage":"Blocked request to internal address: {addr}","messagePattern":"Blocked request to internal address: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"models/common.py","lineNumber":827,"sourceCode":"    def _load_metadata(f=Path(\"path/to/meta.yaml\")):\n        \"\"\"Loads metadata from a YAML file, returning strides and names if the file exists, otherwise `None`.\"\"\"\n        if f.exists():\n            d = yaml_load(f)\n            return d[\"stride\"], d[\"names\"]  # assign stride, names\n        return None, None\n\n\ndef _validate_ssrf_url(url: str) -> None:\n    \"\"\"Raise ValueError if url resolves to any private/internal address.\"\"\"\n    hostname = urlparse(url).hostname or \"\"\n    try:\n        results = socket.getaddrinfo(hostname, None)\n    except socket.gaierror as e:\n        raise ValueError(f\"Could not resolve hostname '{hostname}': {e}\") from e\n    for _family, _type, _proto, _canonname, sockaddr in results:\n        addr = ipaddress.ip_address(sockaddr[0])\n        if addr.is_private or addr.is_loopback or addr.is_link_local or addr.is_reserved or addr.is_multicast:\n            raise ValueError(f\"Blocked request to internal address: {addr}\")\n\n\ndef _request_ssrf_url(url: str, max_redirects: int = 5):\n    \"\"\"Fetch a URL after validating each resolved redirect target.\"\"\"\n    session = requests.Session()\n    for _ in range(max_redirects + 1):\n        _validate_ssrf_url(url)\n        response = session.get(url, stream=True, allow_redirects=False)\n        if not response.is_redirect:\n            return response\n        url = urljoin(response.url, response.headers[\"location\"])\n        response.close()\n    raise ValueError(f\"Too many redirects while fetching {url}\")\n\n\nclass AutoShape(nn.Module):\n    \"\"\"AutoShape class for robust YOLOv5 inference with preprocessing, NMS, and support for various input formats.\"\"\"\n","sourceCodeStart":809,"sourceCodeEnd":845,"githubUrl":"https://github.com/ultralytics/yolov5/blob/20d1d78a08277e365d57bfa3a2cce752772d9e59/models/common.py#L809-L845","documentation":"_validate_ssrf_url raises ValueError when the hostname resolves to an IP classified as private, loopback, link-local, reserved, or multicast. This is the SSRF guard: YOLOv5 download paths refuse to fetch from internal addresses so a malicious URL (e.g. in a crafted data yaml 'download:' field) cannot reach cloud metadata endpoints or intranet services. The check inspects every address returned by getaddrinfo and every redirect hop.","triggerScenarios":"A data yaml with download: http://10.0.0.5/dataset.zip or http://localhost:8000/data.zip; a URL whose public-looking hostname DNS-rebinds to 169.254.169.254; a redirect from a public host to an internal one; legitimately using an internal mirror to serve weights.","commonSituations":"Corporate environments hosting datasets on internal NAS/IPs; self-hosted artifact mirrors (Nexus, Artifactory on a LAN IP); security testing of untrusted yaml files; attempts to use 127.0.0.1 for local testing of download flows.","solutions":["Use a public URL for downloads, or download the file yourself and pass the local path — local files bypass the URL validator.","If an internal mirror is required, fetch it outside this code path (curl/wget) and reference the local file.","Audit any third-party data yaml for its download: value before running train.py on it.","Do not attempt to disable the guard; it is intentional protection for untrusted yaml input."],"exampleFix":"# before (blocked by SSRF guard)\n# data.yaml: download: http://10.20.30.40/coco128.zip\n\n# after\n# wget http://10.20.30.40/coco128.zip -O ~/datasets/coco128.zip, then point data.yaml paths at the local copy","handlingStrategy":"validation","validationCode":"import socket, ipaddress\nfrom urllib.parse import urlparse\n\ndef url_is_public(url: str) -> bool:\n    host = urlparse(url).hostname or ''\n    try:\n        addrs = [sockaddr[0] for *_m, sockaddr in socket.getaddrinfo(host, None)]\n    except socket.gaierror:\n        return False\n    def bad(a):\n        x = ipaddress.ip_address(a)\n        return x.is_private or x.is_loopback or x.is_link_local or x.is_reserved or x.is_multicast\n    return not any(bad(a) for a in addrs)","typeGuard":null,"tryCatchPattern":"try:\n    _request_ssrf_url(url)\nexcept ValueError as e:\n    if 'Blocked request to internal address' in str(e):\n        raise SystemExit('Internal URLs are blocked by design; download manually and use a local path') from e","preventionTips":["Never put internal/LAN URLs into shared data yamls.","Fetch from internal mirrors outside this code path and reference local files.","Audit third-party yaml 'download:' fields before running them."],"tags":["security","ssrf","network","download"],"backgroundTag":null,"analyzedSha":"20d1d78a08277e365d57bfa3a2cce752772d9e59","analyzedAt":"2026-08-15T02:56:15.443Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}