T09 · Insecure Skill Coding Practices
- Location
scripts/generate_image.py:87- Finding
Arbitrary Local File Disclosure Through reference_image
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate_image.py:87-92, 115-126
Vulnerability Type: Unrestricted local file read followed by external transmission
Risk Level: HighVulnerable Code
python def resolve_reference_image(value: str) -> Any: if value.startswith("http://") or value.startswith("https://"): return value path = Path(value) if path.exists(): return path.read_bytes() return valuepython def call_generate(req: dict[str, Any]) -> dict[str, Any]: prompt = req.get("prompt") if not prompt: raise ValueError("prompt is required") messages = [{"role": "user", "content": [{"text": prompt}]}] reference_image = req.get("reference_image") if reference_image: messages[0]["content"].insert( 0, {"image": resolve_reference_image(reference_image)}, ) response = ImageGeneration.call( model=MODEL_NAME, messages=messages, size=req.get("size", DEFAULT_SIZE), api_key=os.getenv("DASHSCOPE_API_KEY"), negative_prompt=req.get("negative_prompt"), style=req.get("style"), seed=req.get("seed"), )Technical Analysis
The
reference_imagefield is accepted from an inline JSON request or request file. If its value resolves to any existing filesystem path, the script reads the entire file usingPath.read_bytes()and places those bytes into the request sent to the external DashScope service.There is no restriction to an approved image directory, no canonical-path containment check, no symlink protection, no regular-file check, and no validation of the file format or maximum size. Consequently, any local file readable by the process can be treated as a reference image. Reading a local reference image is relevant to the declared functionality, but unrestricted access to the entire readable filesy ...[truncated 1147 chars]
- Remediation
View remediation
Remediation Suggestions
- Disable local-file reference images by default and require an explicit option to enable them.
- Resolve the supplied path with
Path.resolve()and enforce containment within a dedicated, approved input directory. - Reject absolute paths, traversal outside the approved directory, symlinks, device files, sockets, and other non-regular files.
- Permit only reviewed image formats and verify content using an image decoder rather than trusting the filename extension.
- Enforce a strict maximum file size before reading the file.
- Run the script under a dedicated, least-privileged account that cannot read unrelated credentials or configuration.
- Inform users before local content is transmitted to an external service and require confirmation where appropriate.
- Consider accepting explicit uploaded bytes from a trusted caller instead of allowing arbitrary filesystem paths.
