Skip to content

Commit faa1744

Browse files
yusmer96-makercopybara-github
authored andcommitted
fix: block posix, nt, _posixsubprocess, and _socket modules in agent config validation
Merge google#6389 PiperOrigin-RevId: 948150331
1 parent 3fb8c7e commit faa1744

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/google/adk/agents/config_agent_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ def _load_config_from_path(config_path: str) -> AgentConfig:
143143
_BLOCKED_MODULES = frozenset({
144144
# Process / OS execution
145145
"os",
146+
"posix", # Unix alias: posix.system is os.system
147+
"nt", # Windows alias: nt.system is os.system
146148
"subprocess",
149+
"_posixsubprocess",
147150
"sys",
148151
"builtins",
149152
"importlib",
@@ -160,6 +163,7 @@ def _load_config_from_path(config_path: str) -> AgentConfig:
160163
"ctypes",
161164
# Network access
162165
"socket",
166+
"_socket",
163167
"http",
164168
"urllib",
165169
"ftplib",

tests/unittests/agents/test_agent_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,12 @@ def test_allowed_module_passes_when_enforced(tmp_path: Path):
526526
"blocked_module",
527527
[
528528
"os.system",
529+
"posix.system",
530+
"nt.system",
529531
"subprocess.call",
532+
"_posixsubprocess.fork_exec",
533+
"socket.socket",
534+
"_socket.socket",
530535
"builtins.exec",
531536
],
532537
)
@@ -542,7 +547,12 @@ def test_resolve_agent_code_reference_blocks_when_enforced(
542547
"blocked_ref",
543548
[
544549
"os.system",
550+
"posix.system",
551+
"nt.system",
545552
"subprocess.call",
553+
"_posixsubprocess.fork_exec",
554+
"socket.socket",
555+
"_socket.socket",
546556
"builtins.exec",
547557
"pickle.loads",
548558
],

0 commit comments

Comments
 (0)