fix(deserialization): replace pickle.loads with JSON across all sinks#2709
Open
amabito wants to merge 2 commits intoag2ai:mainfrom
Open
fix(deserialization): replace pickle.loads with JSON across all sinks#2709amabito wants to merge 2 commits intoag2ai:mainfrom
amabito wants to merge 2 commits intoag2ai:mainfrom
Conversation
Five deserialization sinks consumed untrusted bytes via pickle.loads or importlib.import_module on attacker-controlled strings. Each path allowed remote code execution for any actor with write access to the respective backend (Redis pub/sub, Redis GET, Cosmos DB items, local teachability store). This change replaces pickle with JSON across all five sites and replaces the dynamic class resolver with a registry lookup. Pickle read paths remain accessible behind explicit opt-in environment variables with deprecation warnings for smooth migration. Addresses: R1R3-B1, R1R3-B2, R3R2-B1, R3R2-B2, R4R1-B1
Codecov Report❌ Patch coverage is
... and 393 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Contributor
Author
|
CI is red on |
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.
Why are these changes needed?
autogen/cache/redis_cache.py:77ispickle.loads(cache.get(...)). That is thedefault production cache path -- anything that can write to your Redis instance
gets RCE on every AG2 process using it. Four sibling sinks had the same shape:
pickle.loadsin the Cosmos DB cache,pickle.loadson inbound Redis pub/submessages,
pickle.loadfrom a caller-suppliedpath_to_db_dirin teachability(RCE on the next agent startup if you can drop a file there), and
importlib.import_moduleon the__type__field arriving over Redis pub/subJSON -- a channel writer can trigger arbitrary import-time side effects with any
importable path. All five are fixed here because splitting the rollout would just
extend the exposure window.
JSON replaces pickle everywhere. Cache stores now write a one-byte version prefix
(
\x01+ JSON). Legacy pickle reads still work, but only whenAG2_ALLOW_PICKLE_CACHE_READ=1is set -- they log a DeprecationWarning on everyhit, noisy by design. Without the flag, the reader raises. The importlib resolver
is gone; a module-level
_EVENT_REGISTRYdict takes its place. CustomBaseEventsubclasses published over Redis pub/sub need@register_event_class;the rejection test in
test_serializer_security.pydemonstrates what happenswhen an unregistered
__type__arrives.Breaking changes: existing
.pklcache entries and teachability stores needmigration. A migration helper ships with this PR
(
python -m autogen.agentchat.contrib.capabilities.teachability_migrate_pickle_to_json).Stub docs at
docs/security/deserialization.mdanddocs/cache-migration.md;website integration is a follow-up.
Related issue number
Addresses: N/A (proactive security audit of deserialization paths)
Checks
(Stub docs added to
docs/security/deserialization.mdanddocs/cache-migration.md; website integration is a follow-up.)