T09 · Insecure Skill Coding Practices
- Location
scripts/build_readable_html.py:53- Finding
Arbitrary Local File Disclosure Through Unrestricted Image Embedding
- Content
View full analysis
- Remediation
View remediation
Path | None: if not path_str: return None supplied = Path(path_str) if supplied.is_absolute(): return None candidate = (IMAGE_DIR / supplied).resolve() try: candidate.relative_to(IMAGE_DIR) except ValueError: return None if not candidate.is_file(): return None return candidate ``` 2. **Prevent symlink-based escapes** - Perform containment checks after `resolve()`. - Consider rejecting symlinks entirely if they are not required by the workflow. - Revalidate the opened file where race-resistant filesystem APIs are available. 3. **Verify actual image content** - Do not rely solely on file extensions or MIME guesses. - Open the candidate with Pillow and call `verify()`. - Allowlist only formats required by the report, such as PNG, JPEG, GIF, and WebP. - Reject unknown content instead of embedding it as `application/octet-stream`. 4. **Enforce strict size and dimension limits** - Check `stat().st_size` before reading. - Reject files larger than a documented maximum. - Limit decoded image dimensions to mitigate decompression bombs. - Configure Pillow's decompression-bomb protections rather than disabling them. 5. **Reduce exposure in intermediate artifacts** - Avoid storing embedded image bytes in the readable JSON unless required. - Store only validated relative image references in intermediate metadata. - Generate the final Base64 representation only after all ...[truncated 650 chars]
