T09 · Insecure Skill Coding Practices
- Location
scripts/init_skill.py:200- Finding
Unvalidated Skill Name Allows Path Traversal and Filesystem Writes Outside the Output Directory
- Content
View full analysis
- Remediation
View remediation
64 or not re.fullmatch( r"[a-z0-9]+(?:-[a-z0-9]+)*", skill_name, ): raise ValueError( "Skill name must be a kebab-case identifier of at most 64 characters" ) ``` 2. Explicitly reject absolute paths, path separators, and special path components: ```python candidate_name = Path(skill_name) if candidate_name.is_absolute() or len(candidate_name.parts) != 1: raise ValueError("Skill name must be a single relative path component") ``` 3. Resolve the final destination and verify containment beneath the base directory: ```python base_dir = Path(path).resolve() skill_dir = (base_dir / skill_name).resolve() if not skill_dir.is_relative_to(base_dir): raise ValueError("Skill destination escapes the requested output directory") ``` 4. Apply validation in both the CLI entry point and `init_skill()` so that library callers cannot bypass it. 5. Create files with restrictive permissions and avoid making generated placeholder scripts executable unless execution is required. 6. Add regression tests covering absolute names, `../`, nested path components, leading or trailing hyphens, consecutive hyphens, and names longer than 64 characters. ]]>
