T09 · Insecure Skill Coding Practices
- Location
scripts/zentao_submit_bugs.py:692- Finding
Unrestricted Local File Upload Through Attachment Paths
- Content
View full analysis
Dict[str, Any]: result: Dict[str, Any] = { "source": file_path, "status": "failed", "fileId": None, "url": None, "error": None, } path = Path(file_path).expanduser() if not path.exists() or not path.is_file(): result["error"] = "附件文件不存在" return result mime_type, _ = mimetypes.guess_type(str(path)) mime_type = mime_type or "application/octet-stream" try: with path.open("rb") as f: response = client.request( "POST", "/files", data={"objectType": "bug", "objectID": str(bug_id)}, files={"imgFile": (path.name, f, mime_type)}, ) if response.status_code != 200: result["error"] = f"上传失败 HTTP {response.status_code}: {response.text[:200]}" return result data = response.json() if data.get("status") != "success": result["error"] = f"上传失败: {data}" return result file_id = data.get("id") or data.get("data", {}).get("id") ext = extract_file_extension(path.name) file_url = ( f"{client.cfg.base_url}/index.php?m=file&f=read&t={ext}&fileID={file_id}" if file_id else (data.get("url") or "") ) result.update( { "status": "success", "fileId": file_id, "url": file_url, } ) return result except Except ...[truncated 2696 chars]- Remediation
View remediation
/attachments`, and reject files outside that directory. 2. Resolve each candidate path with `Path.resolve()` and verify containment using `relative_to()` or an equivalent canonical-path check. 3. Reject absolute paths, path traversal, symbolic links, device files, sockets, and other non-regular inputs. 4. Allow only necessary attachment formats, such as PNG, JPEG, WebP, MP4, and approved document types. 5. Validate actual file signatures instead of relying exclusively on filename extensions. 6. Enforce per-file and aggregate upload-size limits. 7. Display the resolved path, size, and destination for each attachment before upload and require explicit approval for generated or externally supplied paths. 8. Exclude sensitive filenames and directories such as `.env`, `.ssh`, cloud credential directories, token-state files, and Agent configuration locations. 9. Consider accepting file handles or attachments explicitly selected by the user rather than arbitrary path strings in bug JSON. ]]>
