T09 · Insecure Skill Coding Practices
- Location
scripts/mistral_ocr_extract.py:253- Finding
Untrusted OCR identifiers allow arbitrary file overwrite through path traversal
- Content
View full analysis
- Remediation
View remediation
Path: if not remote_name or Path(remote_name).is_absolute(): raise CLIError("Unsafe output filename") normalized_name = Path(remote_name).name if normalized_name != remote_name or normalized_name in {".", ".."}: raise CLIError("Unsafe output filename") if not re.fullmatch(r"[A-Za-z0-9._-]+", normalized_name): raise CLIError("Unsafe output filename") resolved_parent = parent.resolve() destination = (resolved_parent / normalized_name).resolve() try: destination.relative_to(resolved_parent) except ValueError as exc: raise CLIError("Output path escapes its destination directory") from exc return destination ``` Use the validated result for both image and table output paths. For tables, validate the identifier before appending the trusted extension. ]]>
