T09 · Insecure Skill Coding Practices
- Location
scripts/operations/generator.py:58- Finding
Unvalidated Operator Generation Persists Attacker-Controlled Python Code
- Content
View full analysis
dict: filepath = os.path.join(_OPERATIONS_DIR, filename) if not os.path.exists(filepath): return {"status": "error", "message": f"文件不存在: {filepath}", "filepath": filepath} mod_name = f"scripts.operations.{filename.replace('.py', '')}" try: mod = importlib.import_module(mod_name) func_name = _extract_func_name(func_code) if func_name and hasattr(mod, func_name): return {"status": "skipped", "message": f"函数 '{func_name}' 已存在于 {filename}", "filepath": filepath} except ImportError: pass try: with open(filepath, "a", encoding="utf-8") as f: f.write("\n\n") f.write(func_code) return {"status": "ok", "message": f"已追加到 {filename}", "filepath": filepath} except IOError as e: return {"status": "error", "message": f"写入失败: {e}", "filepath": filepath} ``` ```python def generate_operator_from_formula( formula: str, operator_name: str, description: str, parameters: list[dict], expression: str, target_file: str = "uncertainty.py", ) -> dict: param_str = ", ".join(f"{p['name']}: {p['type']}" for p in parameters) func_code = ( f"\n\n" f"def {operator_name}({param_str}) -> float:\n" f' """\n' f" {description}.\n" f"\n" f" 公式: {formula}\n" f"\n" f" Parameters\n" f" ----------\n" f"{param_doc}\n" f"\n" f" Returns\n" f" -------\n" f" float\n" f' """\n' f" {expression}\n" ) result = append_function_to_file(target_file, func_code) ``` ### Technical Analysis ...[truncated 1842 chars]- Remediation
View remediation
