feat: add safeguards for remote media URLs (#34892)

This commit is contained in:
Mick
2026-08-15 18:12:15 +08:00
committed by GitHub
parent 0c072235f4
commit 35cefd1c51
14 changed files with 453 additions and 45 deletions
+22
View File
@@ -70,6 +70,7 @@ from sglang.srt.speculative.decoupled_spec_io import DecoupledSpecIpcConfig
from sglang.srt.utils.common import (
LORA_TARGET_ALL_MODULES,
SUPPORTED_LORA_TARGET_MODULES,
configure_media_url_security,
get_device,
get_device_memory_capacity,
get_device_sm,
@@ -2764,6 +2765,19 @@ class ServerArgs:
"environment override when this argument is 0.",
NS("mm"),
] = 0
allowed_media_domains: A[
List[str],
"Restrict client-supplied HTTP(S) image, video, and audio URLs to these "
"exact hostnames. Redirect destinations are checked against the same "
"allowlist. When unset, remote media from any domain is allowed.",
NS("mm"),
] = dataclasses.field(default_factory=list)
media_url_max_file_size_mb: A[
int,
"Maximum size in MiB for one client-supplied remote media download. "
"The limit is enforced while streaming; set to 0 to disable it.",
NS("mm"),
] = 64
mm_preprocess_cache_size_mb: A[
Optional[int],
"CPU memory budget for content-addressed multimodal preprocessing "
@@ -3561,6 +3575,7 @@ class ServerArgs:
self._handle_moe_runner_backend_alias()
self._handle_return_hidden_states_mode()
self._handle_media_url_security()
if self.model_path.lower() in ["none", "dummy"]:
return
@@ -4051,6 +4066,13 @@ class ServerArgs:
f"but got {type(self.mm_process_config[key])}"
)
def _handle_media_url_security(self):
"""Normalize and publish the media URL policy before workers start."""
self.allowed_media_domains = configure_media_url_security(
self.allowed_media_domains,
self.media_url_max_file_size_mb,
)
def _handle_deprecated_args(self):
if self.disable_fast_image_processor:
if self.image_processor_backend not in {"auto", "pil"}: