diff --git a/backend/app/gateway/routers/artifacts.py b/backend/app/gateway/routers/artifacts.py index 70dca401f2..1c9c08b65c 100644 --- a/backend/app/gateway/routers/artifacts.py +++ b/backend/app/gateway/routers/artifacts.py @@ -309,6 +309,11 @@ def _load_skill_archive_member(actual_skill_path: Path, skill_file_path: str, in raise HTTPException(status_code=404, detail=f"Skill file not found: {skill_file_path}") if not actual_skill_path.is_file(): raise HTTPException(status_code=400, detail=f"Path is not a file: {skill_file_path}") + # A trailing ".skill/" requests no member at all. Without this guard the + # archive lookup's fallback matches the first directory entry (name ends + # with "/") and returns its empty body with 200 instead of 404 (#8500). + if not internal_path: + raise HTTPException(status_code=404, detail=f"No skill archive member requested: {skill_file_path}") content = _extract_file_from_skill_archive(actual_skill_path, internal_path) if content is None: raise HTTPException(status_code=404, detail=f"File '{internal_path}' not found in skill archive") diff --git a/backend/tests/test_artifacts_router.py b/backend/tests/test_artifacts_router.py index d77655e94e..99a1083b48 100644 --- a/backend/tests/test_artifacts_router.py +++ b/backend/tests/test_artifacts_router.py @@ -1269,6 +1269,25 @@ def test_get_skill_archive_inline_returns_sha256_etag(tmp_path, monkeypatch) -> assert response.headers["x-content-type-options"] == "nosniff" +def test_get_skill_archive_trailing_slash_returns_404(tmp_path, monkeypatch) -> None: + # skills/export.py writes an explicit directory entry for each folder, so + # a trailing ".skill/" used to fall through the archive lookup's fallback + # match and answer 200 with the directory's empty body (#8500). + skill_path = tmp_path / "sample.skill" + with zipfile.ZipFile(skill_path, "w", compression=zipfile.ZIP_DEFLATED) as zip_ref: + zip_ref.writestr("skills/", b"") + zip_ref.writestr("skills/SKILL.md", b"# Sample\n") + + monkeypatch.setattr(artifacts_router, "resolve_thread_virtual_path", lambda _thread_id, _path, user_id=None: skill_path) + + app = make_authed_test_app() + app.include_router(artifacts_router.router) + with TestClient(app) as client: + response = client.get("/api/threads/thread-1/artifacts/mnt/user-data/outputs/sample.skill/") + + assert response.status_code == 404 + + @pytest.mark.parametrize(("filename", "content"), ACTIVE_ARTIFACT_CASES) def test_get_artifact_forces_download_for_active_content(tmp_path, monkeypatch, filename: str, content: str) -> None: artifact_path = tmp_path / filename