Skip to content

Commit e16629b

Browse files
committed
fix(tools): Shell escape path and range in ReadFileTool command
Use shlex.quote to escape the path and range arguments in the ReadFileTool shell command to prevent potential shell injection vulnerabilities. Change-Id: I5156b616296fc7fac3b98da2b500e4aeb1e3022c
1 parent ad8b6c7 commit e16629b

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/google/adk/tools/environment/_read_file_tool.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from __future__ import annotations
1818

1919
import logging
20+
import shlex
2021
from typing import Any
2122
from typing import Optional
2223
from typing import TYPE_CHECKING
@@ -109,8 +110,9 @@ async def run_async(
109110
sed_range = f'{start},{end_line}'
110111
else:
111112
sed_range = f'{start},$'
112-
# TODO: use shlex.quote to quote `path` and `sed_range`.
113-
cmd = f"cat -n '{path}' | sed -n '{sed_range}p'"
113+
path_arg = shlex.quote(path)
114+
sed_arg = shlex.quote(f'{sed_range}p')
115+
cmd = f'cat -n {path_arg} | sed -n {sed_arg}'
114116
res = await self._environment.execute(cmd)
115117
if res.exit_code == 0:
116118
return {

0 commit comments

Comments
 (0)