Skip to content

Commit e22a122

Browse files
authored
Merge commit from fork
* Block dangerous flags in find_file function Added a set of dangerous flags to prevent RCE and file manipulation in the find_file function. * Fix typo in error message for dangerous flags
1 parent e38ac2b commit e22a122

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/cai/tools/reconnaissance/filesystem.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
from cai.tools.common import run_command # pylint: disable=E0401
66
from cai.sdk.agents import function_tool
77

8+
# Dangerous flags that enable RCE, file writes, or file deletion
9+
DANGEROUS_FIND_FLAGS = {
10+
"-exec", "-execdir", "-ok", "-okdir",
11+
"-delete",
12+
"-fprintf", "-fprint", "-fls", "-fprint0",
13+
"-print0",
14+
}
15+
816
@function_tool
917
def list_dir(path: str, args: str = "", ctf=None) -> str:
1018
"""
@@ -61,5 +69,10 @@ def find_file(file_path: str, args: str = "", ctf=None) -> str:
6169
"""
6270
Find a file in the filesystem.
6371
"""
72+
# Block dangerous flags that enable RCE, file writes, or deletion
73+
for flag in DANGEROUS_FIND_FLAGS:
74+
if flag in args:
75+
return f"Error: DANGEROUS flag '{flag}' is not allowed"
76+
6477
command = f'find {file_path} {args}'
6578
return run_command(command, ctf=ctf)

0 commit comments

Comments
 (0)