T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/glm_grounding_cli.py:174- Finding
Arbitrary Local Files Can Be Uploaded to an External API
- Content
View full analysis
tuple[str, str]: """ Encode a local file to base64 data URI. Returns: tuple of (data_uri, error_message) On success, error_message is empty. """ path = Path(file_path) if not path.exists(): return "", f"File not found: {file_path}" if not path.is_file(): return "", f"Not a regular file: {file_path}" # Guess MIME type, fallback to application/octet-stream mime, _ = mimetypes.guess_type(str(path)) if not mime: mime = "application/octet-stream" try: data = path.read_bytes() b64 = base64.b64encode(data).decode("ascii") return f"data:{mime};base64,{b64}", "" except Exception as e: return "", f"Failed to read file: {e}" ``` ```python if image: if not _is_url(image): encoded_image, encode_err = _encode_file(image) if encode_err: return _error("INPUT_ERROR", encode_err, source) image_for_api = encoded_image else: image_for_api = image mm_content.append({"type": "image_url", "image_url": {"url": image_for_api}}) elif video is not None: # video if not _is_url(video): encoded_video, encode_err = _encode_file(video) if encode_err: return _error("INPUT_ERROR", encode_err, source) video_for_api = encoded_video else: video_for_api = video mm_content.append({"type": "video_url", "video_url": {"url": video_for_api}}) content = [*mm_content, *content] messages = [{"role": "user", "content": content}] payload = { "model": model, "messages": messages, } try: raw_result = _make_api_request(api_url, api_key, payload) except RuntimeError as e: return _error ...[truncated 2262 chars]- Remediation
View remediation
