T09 · Insecure Skill Coding Practices
- Location
scripts/run_v2.py:445- Finding
Arbitrary R Code Execution Through User-Controlled Output Paths
- Content
View full analysis
None: """ Root tree at midpoint and ladderize for better visualization Args: input_tree: Input tree file (Newick format) output_tree: Output rooted tree file """ print_info("Rooting tree at midpoint and ladderizing") r_script = f""" library(ape) # Read tree tree <- read.tree("{input_tree}") # Midpoint rooting tree_rooted <- midpoint(tree) # Ladderize tree_rooted <- ladderize(tree_rooted) # Save write.tree(tree_rooted, "{output_tree}") cat("✓ Tree rooted and ladderized\\n") """ try: subprocess.run(["Rscript", "-e", r_script], check=True, capture_output=True, text=True) print_success(f"Rooted tree: {output_tree}") except subprocess.CalledProcessError as e: print_error(f"Tree rooting failed: {e}") sys.exit(1) ``` The fallback visualization contains the same pattern: ```python def visualize_basic(tree_file: Path, output_dir: Path) -> None: """Basic tree visualization fallback""" r_script = f""" library(ape) tree <- read.tree("{tree_file}") # Circular tree pdf("{output_dir}/tree_circular.pdf", width=12, height=12) plot(tree, type="fan", cex=0.5, main="Phylogenetic Tree (Circular)") dev.off() # Rectangular tree pdf("{output_dir}/tree_rectangular.pdf", width=16, height=20) plot(tree, type="phylogram", cex=0.4, main="Phylogenetic Tree") dev.off() cat("✓ Basic figures generated\\n") """ subprocess.run(["Rscript", "-e", r_script], check=True) ``` The affected path components originate from command-line arguments: ```python parser.add_ ...[truncated 2680 chars]- Remediation
View remediation
