T09 · Insecure Skill Coding Practices
- Location
scripts/app_builder.py:261- Finding
LLM-Controlled Filenames Permit Writes Outside the Generated Project Directories
- Content
View full analysis
- Remediation
View remediation
Path: if not isinstance(filename, str) or not filename: raise ValueError("Invalid generated filename") relative = Path(filename) if relative.is_absolute() or ".." in relative.parts: raise ValueError(f"Unsafe generated filename: {filename}") resolved_base = base.resolve() destination = (resolved_base / relative).resolve() if destination != resolved_base and resolved_base not in destination.parents: raise ValueError(f"Generated path escapes output directory: {filename}") return destination ``` 4. Use an explicit allowlist of expected output files and permitted extensions. 5. Refuse to follow existing symlinks in the output tree and create files using safe, exclusive filesystem operations where practical. 6. Validate that all returned values are strings before writing them. 7. Generate into a fresh, isolated directory with restrictive permissions. 8. Display generated manifests and scripts for review before execution. 9. Recommend `npm install --ignore-scripts` for initial inspection, followed by dependency and lifecycle-script review. 10. Add tests covering `../`, absolute paths, Windows drive paths, mixed separators, encoded traversal, and symlink escapes. ]]>
