fix(admin): 反馈图片代理接口按扩展名固定 Content-Type 并禁用嗅探

This commit is contained in:
HTEWJ\26070045 committed 2026-10-27 09:08:10 +08:00
1 parent 37b743d5d3
commit e8ad4cc743
3 files changed
+22 -3

No files matched your search

@@ -218,7 +218,7 @@ def test_report_rows_include_images(app, client, user_headers, admin_headers):
def test_admin_image_raw_streams(app, client, user_headers, admin_headers, monkeypatch):
"""管理员经 raw 接口取到图片字节;错配 feedback_id → 404 FEEDBACK.IMAGE_NOT_FOUND;非管理员 → 403。"""
"""管理员经 raw 接口取到图片字节(Content-Type 按扩展名固定 + nosniff);错配 feedback_id → 404 FEEDBACK.IMAGE_NOT_FOUND;非管理员 → 403。"""
# 隔离 MinIO:读取字节走本地假实现,提交仍只落库不触对象存储
monkeypatch.setattr(
"app.services.file_assets.service.file_asset_storage.get_bytes",
@@ -241,6 +241,8 @@ def test_admin_image_raw_streams(app, client, user_headers, admin_headers, monke
assert resp.status_code == 200
assert resp.data == b"\x89PNG\r\n\x1a\nfake"
assert resp.content_type.startswith("image/png")
# 安全响应头:Content-Type 按扩展名白名单固定后,仍禁用浏览器 MIME 嗅探(防伪造内容内联渲染)
assert resp.headers.get("X-Content-Type-Options") == "nosniff"
# 错配 feedback_id:image 不属于该反馈 → FEEDBACK.IMAGE_NOT_FOUND(而非 FILE_ASSET.*)
resp = client.get(