security: restrict pickle deserialization in v0 schema and migration tool#5635
security: restrict pickle deserialization in v0 schema and migration tool#5635daridor9 wants to merge 5 commits intogoogle:mainfrom
Conversation
Replace raw pickle.loads() with safe_loads() in DynamicPickleType.process_result_value(). Ref: google#5634
Replace raw pickle.loads() with safe_loads() in _row_to_event() migration function. Ref: google#5634
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Hello @daridor9, thank you for your contribution! This is a valuable security fix. Before we can proceed with the review, could you please sign the Contributor License Agreement (CLA)? The Once the CLA is signed, we can move forward with labeling and reviewing your PR. Response from ADK Triaging Agent |
Covers potential enum values in state_delta/agent_state dict[str, Any] fields. Ref: google#5634
Summary
This PR adds a
RestrictedUnpicklerto prevent arbitrary code execution via crafted pickle payloads in the v0 schema runtime path and the migration tool.Fixes #5634
Changes
New:
_safe_unpickle.pyRestrictedUnpicklersubclass that allowlists only known-safe types:google.adk.*)google.genai.*)pydantic.*,pydantic_core.*)collections/datetime/copyregos,subprocess,posix,builtins.__import__)safe_loads()function as drop-in replacement forpickle.loads()ADK_ALLOW_UNSAFE_V0_PICKLE=1env var for databases with non-standard pickled types (logs deprecation warning)Patched:
v0.py(Sink 1 — runtime read path)DynamicPickleType.process_result_value()now callssafe_loads()instead ofpickle.loads()Patched:
migrate_from_sqlalchemy_pickle.py(Sink 2 — migration path)_row_to_event()now callssafe_loads()instead ofpickle.loads()adk migrate sessionis safe to run on untrusted v0 databasesTesting
EventActionspickle data will continue to work — all ADK types are allowlistedos.system,subprocess.Popen) are blocked with a clear error messageSecurity Context
AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H)Submitted by SPR{K}3 Security Research (@daridor9)