fix: validate module paths in YAML config to prevent arbitrary code execution - #6117
fix: validate module paths in YAML config to prevent arbitrary code execution#6117Ashutosh0x wants to merge 3 commits into
Conversation
…xecution via importlib
|
Hi @rohityan @surajksharma07 — this fixes #5822 which I reported 3 weeks ago. The Fix: Added Happy to adjust if needed! |
|
Hi @Ashutosh0x , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Please fix formatting errors before we can proceed with a review. |
|
Close this for now as it is resolved by 6a5be34 |
Summary
Fix for #5822 - Add module path validation to
resolve_code_reference(),resolve_fully_qualified_name(), and_resolve_agent_code_reference()inconfig_agent_utils.pyto prevent importing dangerous stdlib modules via YAML agent config.Problem
These functions call
importlib.import_module()with no validation on the module path. A malicious YAML config can specify any Python module path, causing the ADK to importos,subprocess,sys, or any stdlib module. Combined with attribute access viagetattr(), this enables arbitrary code execution.Example malicious YAML:
`yaml
tools:
name: os.system
`
Fix
Added
_validate_module_path()that enforces:__builtins__and similar dunder segmentsCalled in all 3 code resolution entry points:
resolve_fully_qualified_name()_resolve_agent_code_reference()resolve_code_reference()Testing
Added
tests/unittests/agents/test_config_module_validation.pywith 15 tests:�ash pytest tests/unittests/agents/test_config_module_validation.py -vFixes #5822