T09 · Insecure Skill Coding Practices
- Location
scripts/design_system.py:504- Finding
Path Traversal Enables Arbitrary Markdown File Creation or Overwrite
- Content
View full analysis
- Remediation
View remediation
str: slug = value.strip().lower().replace(" ", "-") if not re.fullmatch(r"[a-z0-9_-]+", slug): raise ValueError(f"Invalid {field}") if slug in {".", ".."}: raise ValueError(f"Invalid {field}") return slug ``` 2. **Enforce canonical path containment** - Resolve the approved output root and every destination. - Verify that each resolved destination remains beneath that root before creating directories or opening files. ```python root = (Path(output_dir) if output_dir else Path.cwd()).resolve() allowed_root = (root / "design-system").resolve() destination = (allowed_root / project_slug / "pages" / f"{page_slug}.md").resolve() if allowed_root not in destination.parents: raise ValueError("Output path escapes the approved directory") ``` 3. **Restrict `output_dir`** - Prefer a caller-provided trusted root rather than accepting arbitrary user input. - If custom output directories are necessary, validate them against an explicit allowlist or workspace boundary. 4. **Prevent accidental overwrites** - Use exclusive creation mode (`x`) by default. - Require a separate, explicit overwrite option before replacing an existing file. - Where replacement is intended, write to a temporary file in the same directory and use an atomic rename. 5. **Reduce default privilege** - Keep persistence disabled unless explicitly requested. - Ensure the Skill runs with filesystem permissions limited to its designated workspace. 6. **Add security tests** - Test ab ...[truncated 231 chars]
