T09 · Insecure Skill Coding Practices
- Location
scripts/create_agent_bundle.py:88- Finding
Unvalidated slug permits filesystem writes outside the temporary build directory
- Content
View full analysis
- Remediation
View remediation
64 or not SLUG_PATTERN.fullmatch(slug): parser.error( "--slug must contain only lowercase letters, digits, and single hyphens" ) ``` 2. Resolve the destination and enforce containment within the temporary directory: ```python temp_root = Path(tmpdir).resolve() skill_dir = (temp_root / slug).resolve() try: skill_dir.relative_to(temp_root) except ValueError: parser.error("Resolved skill path escapes the temporary build directory") ``` 3. Reject absolute paths, path separators, `.` components, and `..` components explicitly as defense in depth. 4. Perform all validation before calling `mkdir()` or `write_text()`. 5. Where overwriting is not required, use exclusive file creation or check for existing destinations before writing. 6. Add regression tests covering absolute slugs, `../` traversal, empty slugs, consecutive hyphens, path separators, and valid hyphen-case slugs. ]]>
