From ad3e86b784c1a962baa997139b6c4521f5f4a3d5 Mon Sep 17 00:00:00 2001 From: lester076 <105119185+lester076@users.noreply.github.com> Date: Thu, 26 Nov 2026 07:28:46 +0800 Subject: [PATCH] fix(artifacts): return 404 for .skill requests without a member path (#8500) (#8629) A trailing ".skill/" requests no archive member at all. The empty internal path fell through to the archive lookup's fallback match, which matched the first directory entry (name ends with "/") and returned its empty body with 200 instead of 404. Reject an empty internal path in the skill branch before extraction. The regression test ships an archive with the usual explicit directory entry and asserts the trailing-slash request answers 404. --- backend/app/gateway/routers/artifacts.py | 5 +++++ backend/tests/test_artifacts_router.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) 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