Skip to content

Commit 3219e4c

Browse files
committed
Fix path traversal in skill extraction (Zip Slip variant)
Validate normalized relative paths in _build_wrapper_code to prevent directory traversal via malicious GCS skill resource names. A crafted skill resource name containing '../' could write files outside the temporary directory, potentially leading to RCE via runpy.run_path(). Fixes #5603
1 parent e6c24ce commit 3219e4c

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/google/adk/tools/skill_toolset.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,10 @@ def _build_wrapper_code(
661661
" _orig_cwd = os.getcwd()",
662662
" with tempfile.TemporaryDirectory() as td:",
663663
" for rel_path, content in _files.items():",
664-
" full_path = os.path.join(td, rel_path)",
664+
" norm_rel = os.path.normpath(rel_path)",
665+
" if norm_rel.startswith('..') or os.path.isabs(norm_rel):",
666+
" raise PermissionError('Path traversal blocked in skill file: ' + rel_path)",
667+
" full_path = os.path.join(os.path.abspath(td), norm_rel)",
665668
" os.makedirs(os.path.dirname(full_path), exist_ok=True)",
666669
" mode = 'wb' if isinstance(content, bytes) else 'w'",
667670
" with open(full_path, mode) as f:",

0 commit comments

Comments
 (0)