T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/ima_create.py:175- Finding
Unrestricted Local File Upload Through Image Input Handling
- Content
View full analysis
str: """Upload a local image file to IMA CDN and return its public URL. If `source` is already an HTTPS URL it is returned as-is. Otherwise the file is uploaded via the two-step presigned URL flow and the resulting CDN URL (fdl) is returned. """ if source.startswith("https://") or source.startswith("http://"): return source if not os.path.isfile(source): raise FileNotFoundError(f"Input image not found: {source}") content_type = mimetypes.guess_type(source)[0] or "image/jpeg" suffix = source.rsplit(".", 1)[-1].lower() if "." in source else "jpeg" logger.info(f"Uploading local image: {source} ({content_type})") token_data = _get_upload_token(api_key, suffix, content_type) ful = token_data["ful"] fdl = token_data["fdl"] with open(source, "rb") as f: image_bytes = f.read() resp = requests.put( ful, data=image_bytes, headers={"Content-Type": content_type}, timeout=60, ) resp.raise_for_status() logger.info(f"Upload complete: {fdl}") return fdl ``` ```python for src in raw_inputs: if src.startswith("https://") or src.startswith("http://"): resolved_inputs.append(src) else: print(f"📤 Uploading local image: {os.path.basename(src)}", flush=True) try: cdn_url = prepare_image_url(src, apikey) resolved_inputs.append(cdn_url) print(f" ✅ Uploaded → {cdn_url}", flush=True) except Exception as e: logger.error(f"Image upload failed: {src} — {e}") print(f"❌ Failed to upload image {src}: {e}", file=sys.stderr) sys.exit(1) ``` ### Technical Analysis Th ...[truncated 1976 chars]- Remediation
View remediation
