fix(wecom): bound outbound local media paths#26424
Open
lidge-jun wants to merge 1 commit into
Open
Conversation
c63ca08 to
7a4e0b5
Compare
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.
What does this PR do?
Fixes WeCom outbound local media loading so
file://and plain local path sources are resolved and checked beforeread_bytes(). Local media uploads are now limited to Hermes media cache directories and the system temp directory, which blocks arbitrary local file reads while preserving generated/cached media delivery.HTTP/HTTPS media sources still use the existing
_download_remote_bytes()path withtools.url_safety.is_safe_url()SSRF protection.I found this while following up on the OpenClaw/Hermes runtime and security-hardening work after the Oracle zip contribution, and kept the patch intentionally narrow to the public WeCom issue.
Related Issue
Fixes #8733
Type of Change
Changes Made
gateway/platforms/wecom.py: add a resolved allowlist for outbound local media roots: image/audio/video/document caches plustempfile.gettempdir().gateway/platforms/wecom.py: validate every local/file URL outbound media source before existence checks andread_bytes().gateway/platforms/wecom.py: reject non-localfile://host/...media URLs.tests/gateway/test_wecom.py: cover allowed media-cache files, blocked arbitrary local files, and symlink escape attempts.How to Test
scripts/run_tests.sh tests/gateway/test_wecom.pygit diff --check.venv/bin/python -m ruff check gateway/platforms/wecom.py tests/gateway/test_wecom.py.venv/bin/python -m py_compile gateway/platforms/wecom.py tests/gateway/test_wecom.pyChecklist
Code
fix(scope):)pytest tests/ -qand all tests passFocused WeCom tests and touched-file checks passed; full
pytest tests/ -qwas not run because this is a narrow platform-adapter fix.Documentation & Housekeeping
docs/, docstrings) — N/Acli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/AFor New Skills
N/A
Screenshots / Logs