{"record":{"id":"fa1156be8a5a061d","repo":"sgl-project/sglang","slug":"invalid-allowed-media-domain-domain-r","errorCode":null,"errorMessage":"Invalid allowed media domain {domain!r}","messagePattern":"Invalid allowed media domain (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/utils/common.py","lineNumber":1546,"sourceCode":"        raise ValueError(\n            f\"Invalid allowed media domain {domain!r}: provide a hostname only\"\n        )\n\n    # Brackets are URL syntax, not part of an IPv6 hostname.\n    if domain.startswith(\"[\") and domain.endswith(\"]\"):\n        domain = domain[1:-1]\n    try:\n        return str(ipaddress.ip_address(domain))\n    except ValueError:\n        if \":\" in domain:\n            raise ValueError(\n                f\"Invalid allowed media domain {domain!r}: ports are not supported\"\n            )\n\n    try:\n        normalized = domain.encode(\"idna\").decode(\"ascii\").lower()\n    except UnicodeError as e:\n        raise ValueError(f\"Invalid allowed media domain {domain!r}\") from e\n    if not normalized:\n        raise ValueError(\"allowed media domains cannot be empty\")\n    return normalized\n\n\ndef configure_media_url_security(\n    allowed_media_domains: Optional[Sequence[str]] = None,\n    max_file_size_mb: int = _DEFAULT_MEDIA_URL_MAX_FILE_SIZE_MB,\n) -> list[str]:\n    \"\"\"Configure process-wide safeguards for client-supplied media URLs.\n\n    A serving worker hosts one engine configuration, while media loading fans\n    out to worker threads. Keeping the immutable policy here makes the same\n    checks apply to image, video, audio, cache, and model-specific loaders.\n    \"\"\"\n\n    if max_file_size_mb < 0:\n        raise ValueError(\"media_url_max_file_size_mb must be non-negative\")","sourceCodeStart":1528,"sourceCodeEnd":1564,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/utils/common.py#L1528-L1564","documentation":"IDNA encoding of the allowed-media-domains entry failed with UnicodeError. Hostnames must be convertible to their ASCII IDNA form; entries with invalid IDNA characters (underscores, bare unicode that IDNA 2003/2008 rejects, stray punctuation) cannot be normalized and are rejected.","triggerScenarios":"Passing a hostname containing characters like '_', '*', or unicode that domain.encode('idna') rejects, e.g. 'my_bucket.cdn.example.com' or 'exämple.invalid-'.","commonSituations":"Allowlisting internal hostnames with underscores (common in some corporate DNS but invalid per RFC/IDNA); wildcard attempts like '*.example.com'; copy-paste of unicode hostnames.","solutions":["Remove invalid characters (replace '_' with '-'; wildcards are not supported at all)","Use the punycode/ASCII form of the hostname directly","Verify with python -c \"print('host'.encode('idna'))\" before adding"],"exampleFix":"# before\nconfigure_media_url_security(allowed_media_domains=['my_bucket.cdn.example.com', '*.example.com'])\n# after\nconfigure_media_url_security(allowed_media_domains=['my-bucket.cdn.example.com', 'example.com'])","handlingStrategy":"validation","validationCode":"def idna_ok(host: str) -> bool:\n    try: return bool(host.encode('idna').decode('ascii').lower())\n    except UnicodeError: return False\ndomains = [d for d in domains if idna_ok(d)]","typeGuard":"def is_idna_hostname(v: str) -> bool:\n    import re\n    return isinstance(v, str) and bool(re.fullmatch(r'(?!-)[A-Za-z0-9-]{1,63}(\\.(?!-)[A-Za-z0-9-]{1,63})*', v))","tryCatchPattern":null,"preventionTips":["Avoid underscores and wildcards in allowlisted hosts","Use punycode forms for international domains"],"tags":["validation","media","security","idna","dns"],"backgroundTag":"hostname-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}