T09 · Insecure Skill Coding Practices
- Location
scripts/video.py:87- Finding
Path Traversal Through Unvalidated Scene Identifiers
- Content
View full analysis
- Remediation
View remediation
str: if not isinstance(value, str) or not SID_PATTERN.fullmatch(value): raise ValueError("Scene ID must contain only letters, digits, underscores, or hyphens") return value ``` 2. Resolve and verify every path before reading or writing: ```python def confined_path(base: pathlib.Path, name: str) -> pathlib.Path: base = base.resolve() candidate = (base / name).resolve() if not candidate.is_relative_to(base): raise ValueError(f"Path escapes permitted directory: {candidate}") return candidate ``` 3. Construct paths only after validating the scene identifier: ```python sid = validate_sid(scene["id"]) frame = confined_path(frame_dir, f"{sid}.png") out = confined_path(out_dir, f"{sid}.mp4") last_out = confined_path(last_dir, f"{sid}_last.png") ``` 4. Reject absolute paths, path separators, `.` components, and `..` components even if additional validation is introduced elsewhere. 5. Document the accepted scene-ID format in `SKILL.md` and fail before submitting any network jobs if validation fails. ]]>
