diff --git a/.jules/sentinel.md b/.jules/sentinel.md index 946c2fcfde2c..01c2df225ed7 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -7,3 +7,7 @@ **Vulnerability:** SQL Injection via string-interpolated subqueries with LIMIT. The `query` function in `optional-skills/mcp/fastmcp/templates/database_server.py` wrapped user SQL in a subquery: `SELECT * FROM ({sql}) LIMIT N`. This allowed malicious users to bypass simple checks (e.g. ensuring it starts with SELECT) and inject additional clauses or statements by manipulating the closing parenthesis. **Learning:** SQLite does not natively support parameterization for the FROM clause (e.g., subqueries or table names). Attempting to string-interpolate user input into a subquery creates an injection vector, especially when trying to enforce a LIMIT clause on user-provided queries. **Prevention:** To prevent SQL injection when applying limits to user-provided SQL queries, execute the raw user query directly and restrict the output rows in Python using `cursor.fetchmany(limit)` instead of trying to wrap the query in another SELECT with a LIMIT clause. +## 2024-05-24 - Security Enhancement: Shell Injection Prevention +**Vulnerability:** Use of `subprocess.run(shell=True)` in `hermes_cli/tools_config.py` for cua-driver installation. +**Learning:** Using `shell=True` can introduce shell injection vulnerabilities, especially if any parts of the command are dynamic. Although this specific case was a hardcoded URL string, it's best practice to replace `shell=True` with an argument list for defense in depth. +**Prevention:** Avoid `shell=True` in `subprocess.run` and pass the command and its arguments as a list. When using `bash -c`, pass the script content as an argument to `-c` rather than interpolating it into a single string with `shell=True`. diff --git a/hermes_cli/tools_config.py b/hermes_cli/tools_config.py index 269ab747e7b6..8f29520c921b 100644 --- a/hermes_cli/tools_config.py +++ b/hermes_cli/tools_config.py @@ -786,11 +786,11 @@ def _run_post_setup(post_setup_key: str): _print_info(" Installing cua-driver (macOS background computer-use)...") try: install_cmd = ( - "/bin/bash -c \"$(curl -fsSL " + "curl -fsSL " "https://raw.githubusercontent.com/trycua/cua/main/" - "libs/cua-driver/scripts/install.sh)\"" + "libs/cua-driver/scripts/install.sh | /bin/bash" ) - result = subprocess.run(install_cmd, shell=True, timeout=300) + result = subprocess.run(["/bin/bash", "-c", install_cmd], timeout=300) if result.returncode == 0 and shutil.which("cua-driver"): _print_success(" cua-driver installed.") _print_info(" IMPORTANT — grant macOS permissions now:")