activation cache uses pickle.load (unsafe deserialization) — correction: the zip-slip vector does NOT reproduce
Correction (2026-08-04)
I need to correct this report. My original write-up claimed a zip-slip → pickle RCE chain. I re-tested the zip-slip leg locally and it does not reproduce: on Python 3.13, zipfile.ZipFile.extractall sanitizes traversal — entries with .., absolute paths, or sub/../ all land inside the target directory and do not escape. So the zip-slip write primitive I described is not real, and the "RCE chain" framing is withdrawn.
What does hold:
What still holds: pickle.load on the activation cache (unsafe deserialization, CWE-502)
src/memos/memories/activation/kv.py:158andsrc/memos/memories/activation/vllmkv.py:164both dodata = pickle.load(f)over cache files.- A crafted pickle runs arbitrary code on load (confirmed:
pickle.loadof a__reduce__-based payload executed the canary).
I have not demonstrated a working write primitive that lets an attacker plant a malicious cache file on disk, so I am not claiming this is a proven RCE — it is an unsafe-deserialization sink that should be hardened regardless (treat the cache as untrusted input: use a non-executable format like JSON/safetensors, or load only from a trusted, integrity-checked location).
Apologies for the over-stated original report; I've edited it down to the verified sink.
Suggested change
Replace pickle.load on the activation cache with a safe format (JSON/safetensors) or a safe-pickle variant, and/or load only from a trusted, non-writable location with an integrity check.
🤖 AutoDev has picked up this issue and started working on it.
Task ID: 5845caaa9f3b7735
Working branch: bugfix/autodev-2203-20260804015142516
Target branch: latest dev* branch
Workflow: opsp (analysis → coding → testing → PR)
I will post the PR link here once done. If I need more information, I will ask in the comments.
Correction (2026-08-04)
I need to correct this report. My original write-up claimed a zip-slip → pickle RCE chain. I re-tested the zip-slip leg locally and it does not reproduce: on Python 3.13, zipfile.ZipFile.extractall sanitizes traversal — entries with .., absolute paths, or sub/../ all land inside the target directory and do not escape. So the zip-slip write primitive I described is not real, and the "RCE chain" framing is withdrawn.
What does hold:
What still holds: pickle.load on the activation cache (unsafe deserialization, CWE-502)
src/memos/memories/activation/kv.py:158andsrc/memos/memories/activation/vllmkv.py:164both dodata = pickle.load(f)over cache files.- A crafted pickle runs arbitrary code on load (confirmed:
pickle.loadof a__reduce__-based payload executed the canary).
I have not demonstrated a working write primitive that lets an attacker plant a malicious cache file on disk, so I am not claiming this is a proven RCE — it is an unsafe-deserialization sink that should be hardened regardless (treat the cache as untrusted input: use a non-executable format like JSON/safetensors, or load only from a trusted, integrity-checked location).
Apologies for the over-stated original report; I've edited it down to the verified sink.
Suggested change
Replace pickle.load on the activation cache with a safe format (JSON/safetensors) or a safe-pickle variant, and/or load only from a trusted, non-writable location with an integrity check.
Closing: I re-ran the PoC and the zip-slip vector does not reproduce (Python 3.x extractall sanitizes ../ and absolute-path entries), so the RCE chain I described is withdrawn. The pickle.load on the activation cache is a real unsafe-deserialization sink, but without a demonstrated write primitive to plant a malicious cache file it's a latent hardening item rather than an exploitable bug — not worth an open issue. Apologies for the over-stated original report.
✅ AutoDev task 5845caaa9f3b7735 completed.
Summary: Hardens the two unauthenticated skill-memory sinks flagged in issue #2203.
1. Zip-slip (CWE-22) in _extract_and_parse_skill_zip. Added a private _safe_extract_zip(zf, extract_dir) helper next to the caller in src/memos/mem_reader/read_skill_memory/upload_skill_memory.py. Before extraction it walks zf.infolist() and rejects: absolute-path entries (POSIX or NT), .. traversal entries whose resolved destination escapes extract_dir, and symlink entries (external_attr bit 0o120000). Any hostile entry causes the entire extraction to abort with ValueError — no silent skip, because the codepath is unauthenticated and partial extraction would produce a subtly-wrong SkillMemory that hides the attack.
2. Unsafe pickle.load (CWE-502) in KVCacheMemory.load and VLLMKVCacheMemory.load. Added a nested _SafeUnpickler(pickle.Unpickler) per module that overrides find_class and enforces a per-module allowlist. kv.py allows DynamicCache/DynamicLayer, KVCacheItem, KVCacheRecords, stdlib containers, datetime.*, and the torch.* tensor rebuild helpers needed by DynamicCache. vllmkv.py allows VLLMKVCacheItem, KVCacheRecords, stdlib containers, datetime.* (no torch — the prompt is a str). Any other find_class call raises pickle.UnpicklingError before the class is imported, so a hostile __reduce__ never fires. The existing except-block resets kv_cache_memories = {} on failure and logs a WARN so operators see the attempted attack.
Tests + verification. 14 new tests: 9 zip-slip cases (../ / ../../../ / absolute-path / symlink / legit round trip / high-level parser guard / two platform-defensive edges) and 5 pickle cases (kv+vllm hostile-payload block, kv arbitrary-class block, kv+vllm legit round trip). TDD-verified: pre-fix _OsSystemPayload PoC actually wrote the canary file, confirming the sink was live; post-fix the canary is not created and the cache resets to empty. ruff check + ruff format --check pass on all changed files. Two pre-existing test_kv.py failures (test_get_cache_merge, test_delete_and_get_all) are transformers-API-version issues unrelated to this patch — reproducible on the base branch before the fix is applied.
Backward compatibility: existing on-disk activation caches produced by our own dump() still load unchanged (round-trip tests confirm). No public API change, no config change, no dependency change.
Base branch: main
Branch: bugfix/autodev-2203-20260804015142516
Commit: 9592126
PR: https://github.com/MemTensor/MemOS/pull/2204
Assigned to: @hijzy
Reviewers: @WeiminLee