fix: restrict remote media domains#4734
Open
CUHKSZzxy wants to merge 7 commits into
Open
Conversation
# Conflicts: # tests/test_lmdeploy/test_content_merge.py
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces an exact-host allowlist (allowed_media_domains) for HTTP(S) multimodal media fetching to reduce SSRF risk, and wires that setting from CLI/API entrypoints down into the multimodal processor and URL loader, including manual redirect handling with revalidation.
Changes:
- Add
allowed_media_domainsplumbed throughapi_server/engines/pipeline and intoMultimodalProcessor+load_from_url. - Enforce per-request redirect handling (
allow_redirects=False) with explicit redirect loops and revalidation on each hop. - Add/extend tests for allowlist behavior, host confusion attempts, redirects, and forwarding of the allowlist through multimodal parsing; document the CLI flag (zh-cn).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_lmdeploy/test_vl/test_safe_url.py | Adds/updates URL safety tests covering allowlist + redirects + host confusion. |
| tests/test_lmdeploy/test_content_merge.py | Updates multimodal parsing tests and adds coverage for allowlist forwarding to URL loaders. |
| lmdeploy/vl/media/connection.py | Implements allowed_media_domains enforcement and manual redirect revalidation for HTTP fetches. |
| lmdeploy/serve/processors/multimodal.py | Stores/pass-through of allowed_media_domains into load_from_url for all modalities. |
| lmdeploy/serve/openai/api_server.py | Adds allowed_media_domains parameter to server entrypoint and forwards to engine. |
| lmdeploy/serve/core/vl_async_engine.py | Wires allowlist into VL async engine + prompt processor. |
| lmdeploy/serve/core/async_engine.py | Wires allowlist into the default async engine prompt processor. |
| lmdeploy/pipeline.py | Exposes allowlist on pipeline construction and forwards it to engine. |
| lmdeploy/cli/serve.py | Adds --allowed-media-domains CLI flag and forwards it to server launch/serve. |
| lmdeploy/api.py | Exposes allowlist on the public pipeline() API and forwards to Pipeline. |
| docs/zh_cn/multi_modal/multimodal_inputs.md | Documents the new CLI option and exact-host matching semantics (zh-cn). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lvhan028
reviewed
Jul 10, 2026
|
|
||
| ## 本地文件与 Base64 | ||
|
|
||
| 当 API 服务面向不可信客户端时,建议在启动服务时使用 `--allowed-media-domains` 限制 HTTP(S) 媒体 URL 可访问的域名,降低 SSRF 风险。该参数按精确 hostname 匹配;例如 `--allowed-media-domains example.com` 只允许 `https://example.com/...`,不允许 `https://cdn.example.com/...`。 |
Collaborator
There was a problem hiding this comment.
missing the english document
lvhan028
reviewed
Jul 10, 2026
Comment on lines
343
to
345
| if isinstance(image, str): | ||
| image = load_image(image) | ||
| item = {'type': 'image_data', 'image_data': {'data': image}} |
Collaborator
There was a problem hiding this comment.
Should we use "allowed_media_domains" here?
lvhan028
reviewed
Jul 10, 2026
|
|
||
|
|
||
| def load_from_url(url: str, media_io: MediaIO[_M]) -> _M: | ||
| def load_from_url(url: str, media_io: MediaIO[_M], allowed_media_domains: list[str] | None = None) -> _M: |
Collaborator
There was a problem hiding this comment.
Agent suggests:
Normalize allowed_media_domains at the enforcement point
parse_url() already lowercases the URL host, but allowlist entries are compared as-is (parsed.hostname not in allowed_media_domains). A config like --allowed-media-domains Example.COM would incorrectly reject https://example.com/....
# Conflicts: # lmdeploy/cli/serve.py # lmdeploy/serve/openai/api_server.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
allowed_media_domainsoption for multimodal media URL fetching.Validation
Assistance
Assisted with Codex + GPT-5.5 xHigh Fast, reviewed manually