T09 · Insecure Skill Coding Practices
- Location
scripts/_shared/ark_api.py:225- Finding
Arbitrary Local File Disclosure Through Unvalidated Reference-Image Paths
- Content
View full analysis
list[str]: refs = [] for cid in char_ids[:MAX_REF]: info = char_manifest.get(cid, {}) for img in info.get("images", []): if "_full." in img: refs.append(img) break return refs ``` From `scripts/storyboard.py:79-80`: ```python prompt = build_prompt(style, scene) refs = pick_refs(scene.get("characters", []), char_manifest) ``` From `scripts/_shared/ark_api.py:54-59`: ```python content = [{"type": "text", "text": prompt}] for img in reference_images or []: content.append({ "type": "image_url", "image_url": {"url": self._image_to_data_uri(img)}, }) ``` From `scripts/_shared/ark_api.py:225-235`: ```python @staticmethod def _image_to_data_uri(path_or_url: str) -> str: if path_or_url.startswith(("http://", "https://", "data:")): return path_or_url p = pathlib.Path(path_or_url) ext = p.suffix.lower().lstrip(".") or "jpeg" if ext == "jpg": ext = "jpeg" b64 = base64.b64encode(p.read_bytes()).decode() return f"data:image/{ext};base64,{b64}" ``` ### Technical Analysis The character manifest is loaded from the user-selected character directory, and its `images` entries are treated as trusted paths. `pick_refs()` only checks whether the supplied string contains `_full.`. It does not ensure that the path: - Is relative to the specified character directory. - Resolves to a file beneath that directory. - Is a regular, non-symlink image file. - Has an approved image extension and valid image signature. - Is within an acceptable size limit. The accepted path is passed to `_image_to_ ...[truncated 2224 chars]- Remediation
View remediation
pathlib.Path: root = root.resolve(strict=True) candidate = pathlib.Path(value) if candidate.is_absolute(): raise ValueError("Absolute reference-image paths are not allowed") candidate = (root / candidate).resolve(strict=True) try: candidate.relative_to(root) except ValueError as exc: raise ValueError("Reference image escapes the character directory") from exc if candidate.is_symlink() or not candidate.is_file(): raise ValueError("Reference image must be a regular, non-symlink file") if candidate.suffix.lower() not in {".png", ".jpg", ".jpeg", ".webp"}: raise ValueError("Unsupported reference-image format") if candidate.stat().st_size > 20 * 1024 * 1024: raise ValueError("Reference image exceeds the size limit") return candidate ``` Image decoding should subsequently verify that the content i ...[truncated 62 chars]
