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
This commit is contained in:
xelitte 2026-01-30 09:03:07 +02:00 committed by GitHub
parent e38ac2b031
commit e22a1220f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 0 deletions

View File

@ -5,6 +5,14 @@ Here are the CLI tools for executing commands.
from cai.tools.common import run_command # pylint: disable=E0401 from cai.tools.common import run_command # pylint: disable=E0401
from cai.sdk.agents import function_tool from cai.sdk.agents import function_tool
# Dangerous flags that enable RCE, file writes, or file deletion
DANGEROUS_FIND_FLAGS = {
"-exec", "-execdir", "-ok", "-okdir",
"-delete",
"-fprintf", "-fprint", "-fls", "-fprint0",
"-print0",
}
@function_tool @function_tool
def list_dir(path: str, args: str = "", ctf=None) -> str: def list_dir(path: str, args: str = "", ctf=None) -> str:
""" """
@ -61,5 +69,10 @@ def find_file(file_path: str, args: str = "", ctf=None) -> str:
""" """
Find a file in the filesystem. Find a file in the filesystem.
""" """
# Block dangerous flags that enable RCE, file writes, or deletion
for flag in DANGEROUS_FIND_FLAGS:
if flag in args:
return f"Error: DANGEROUS flag '{flag}' is not allowed"
command = f'find {file_path} {args}' command = f'find {file_path} {args}'
return run_command(command, ctf=ctf) return run_command(command, ctf=ctf)