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.
This commit is contained in:
lester076 2026-11-26 07:28:46 +08:00 committed by GitHub
parent aa9913c4cc
commit ad3e86b784
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View File

@ -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")

View File

@ -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