fix: generation_tasks results 端点返回 OSS 预签名 URL(24h 有效期) #206
Reference in New Issue
Block a user
Delete Branch "fix/generated-video-url-403"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
P0-2 修复
问题:
GET /api/v1/generation/tasks/{task_id}/results返回的download_url为 null,前端使用file_url(OSS 私有 bucket 原始 URL)访问视频返回 403。根因:该端点未像
generated_videos.py中的其他端点一样调用storage_service.get_download_url()生成预签名 URL。修复:
storage_service依赖(复用已有OSSStorageService.get_download_url)file_url生成预签名 URL,有效期 86400 秒(24h)_to_generated_video_response支持download_url参数generated_videos.py中的模式保持一致测试:
test_results_endpoint_generates_presigned_urls:验证预签名 URL 生成 + 24h 有效期test_results_endpoint_handles_empty_videos:验证空结果正常返回未改 bucket ACL(保持 private,安全无风险)
P0-3 调查结论
Worker 容器内存限制为 2GB(旧备份为 4GB)。FFmpeg xfade 转场需要同时解码多个视频,内存峰值容易超过 2GB。建议:
Closes #P0-2
Closes #P0-3
✅ PR #206 审计通过
结论:通过 — 0 P0 / 0 P1 / 0 P2 / 0 P3(本 PR 新增)
修复验证 ✅
文件:
apps/api/app/api/routes/generation_tasks.pybucket.sign_url("GET", key, expires)— 标准实现,无安全问题_normalize_storage_key只提取路径,签名后 URL 一定是 OSS 域名,不存在跳转到恶意站点的风险GeneratedVideoResponse.download_url已存在(Optional[str]),file_url 原始值保留不变get_current_user+_check_project_access双重校验,未登录/无权限用户无法获取预签名 URLget_url),不会导致整个接口 500测试验证 ✅
文件:
tests/unit/test_generation_presigned_url.py(179 行,2 个用例)test_results_endpoint_generates_presigned_urls:验证每个视频都生成预签名 URL,expires=86400,download_url 字段存在,file_url 保留原值test_results_endpoint_handles_empty_videos:无视频时返回空列表,不调用 storage_service补充说明(非阻塞,历史遗留)
以下是
OSSStorageService.get_download_url已有实现中的可优化点,非本 PR 引入,不阻塞合并:_normalize_storage_key不校验 URL 域名,非 OSS 域名也会提取 key 签名。虽然无安全风险(签名结果仍是 OSS 域名),但不够严谨,建议后续加上白名单校验。except Exception静默降级返回原始 URL,私有 bucket 下原始 URL 仍是 403,排障时难发现问题,建议补一条 warning 日志。最终结论:P0-2 修复正确到位,PR #206 可以合并。