ultralytics/yolov5 · error · ValueError
Blocked request to internal address: {addr}
Error message
Blocked request to internal address: {addr} What it means
_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.
Source
Thrown at models/common.py:827
def _load_metadata(f=Path("path/to/meta.yaml")):
"""Loads metadata from a YAML file, returning strides and names if the file exists, otherwise `None`."""
if f.exists():
d = yaml_load(f)
return d["stride"], d["names"] # assign stride, names
return None, None
def _validate_ssrf_url(url: str) -> None:
"""Raise ValueError if url resolves to any private/internal address."""
hostname = urlparse(url).hostname or ""
try:
results = socket.getaddrinfo(hostname, None)
except socket.gaierror as e:
raise ValueError(f"Could not resolve hostname '{hostname}': {e}") from e
for _family, _type, _proto, _canonname, sockaddr in results:
addr = ipaddress.ip_address(sockaddr[0])
if addr.is_private or addr.is_loopback or addr.is_link_local or addr.is_reserved or addr.is_multicast:
raise ValueError(f"Blocked request to internal address: {addr}")
def _request_ssrf_url(url: str, max_redirects: int = 5):
"""Fetch a URL after validating each resolved redirect target."""
session = requests.Session()
for _ in range(max_redirects + 1):
_validate_ssrf_url(url)
response = session.get(url, stream=True, allow_redirects=False)
if not response.is_redirect:
return response
url = urljoin(response.url, response.headers["location"])
response.close()
raise ValueError(f"Too many redirects while fetching {url}")
class AutoShape(nn.Module):
"""AutoShape class for robust YOLOv5 inference with preprocessing, NMS, and support for various input formats."""
View on GitHub (pinned to 20d1d78a08)
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.
Example fix
# before (blocked by SSRF guard) # data.yaml: download: http://10.20.30.40/coco128.zip # after # wget http://10.20.30.40/coco128.zip -O ~/datasets/coco128.zip, then point data.yaml paths at the local copy
Defensive patterns
Strategy: validation
Validate before calling
import socket, ipaddress
from urllib.parse import urlparse
def url_is_public(url: str) -> bool:
host = urlparse(url).hostname or ''
try:
addrs = [sockaddr[0] for *_m, sockaddr in socket.getaddrinfo(host, None)]
except socket.gaierror:
return False
def bad(a):
x = ipaddress.ip_address(a)
return x.is_private or x.is_loopback or x.is_link_local or x.is_reserved or x.is_multicast
return not any(bad(a) for a in addrs) Try / catch
try:
_request_ssrf_url(url)
except ValueError as e:
if 'Blocked request to internal address' in str(e):
raise SystemExit('Internal URLs are blocked by design; download manually and use a local path') from e Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not resolve hostname '{hostname}': {e}
- Too many redirects while fetching {url}
- {e}. Cache may be out of date, try `force_reload=True` or se
- Dataset not found ❌
AI-assisted analysis of ultralytics/yolov5@20d1d78a08 (2026-08-15).
Data as JSON: /api/errors/8f220201d7061e7e.
Report an issue: GitHub.