From 7fdf12ba3e24339a87325347c2e32b6581e7cd8f Mon Sep 17 00:00:00 2001 From: Lenin Mookiah <2639584+leninworld@users.noreply.github.com> Date: Wed, 25 Nov 2026 14:28:58 -0800 Subject: [PATCH] fix(extensions): reject historical releases with an unsafe download_url The extension catalog accepted a historical release whose download_url is not HTTPS (or loopback HTTP), unlike the preset, bundle and workflow catalogs. `specify extension info --versions` listed such a release as available, and `specify extension add --version ` selected it, only to fail later in the downloader's HTTPS check. Validate each historical download_url with is_https_or_localhost_http right after the existing presence check, with the same message shape as presets ("has an invalid download_url"). Assisted-by: OpenAI Codex CLI (model: gpt-5.6-sol, autonomous) Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous) --- .../extensions/_catalog_versions.py | 5 ++ .../extensions/test_catalog_versions.py | 80 +++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/src/specify_cli/extensions/_catalog_versions.py b/src/specify_cli/extensions/_catalog_versions.py index 63965cbeef..4e56934607 100644 --- a/src/specify_cli/extensions/_catalog_versions.py +++ b/src/specify_cli/extensions/_catalog_versions.py @@ -13,6 +13,7 @@ from packaging.version import InvalidVersion, Version +from .._download_security import is_https_or_localhost_http from . import ExtensionError _SHA256 = re.compile(r"^[0-9a-fA-F]{64}$") @@ -94,6 +95,10 @@ def _validated_releases(entry: dict[str, Any]) -> dict[str, dict[str, Any]]: raise ExtensionError( f"Extension '{extension_id}' release '{release_version}' needs a download_url." ) + if not is_https_or_localhost_http(record["download_url"]): + raise ExtensionError( + f"Extension '{extension_id}' release '{release_version}' has an invalid download_url." + ) digest = record.get("sha256") if isinstance(digest, str): digest = digest.strip() diff --git a/tests/specify_cli/extensions/test_catalog_versions.py b/tests/specify_cli/extensions/test_catalog_versions.py index 404256baa3..9cacecfa64 100644 --- a/tests/specify_cli/extensions/test_catalog_versions.py +++ b/tests/specify_cli/extensions/test_catalog_versions.py @@ -235,6 +235,86 @@ def test_malformed_history_is_rejected(tmp_path, monkeypatch, bad_history): catalog.get_extension_info("demo-history", "0.4.12") +def _entry_with_release_url(download_url: str) -> dict: + return { + "id": "demo-history", + "name": "Demo History", + "version": "0.5.1", + "download_url": "https://example.com/demo-0.5.1.zip", + "sha256": "a" * 64, + "_catalog_name": "trusted", + "_install_allowed": True, + "releases": { + "0.4.12": {"download_url": download_url, "sha256": "b" * 64}, + }, + } + + +@pytest.mark.parametrize( + "download_url", + [ + "http://example.com/a.zip", + "http://localhost.example.com/a.zip", + "ftp://example.com/a.zip", + "file:///tmp/a.zip", + "https:///a.zip", + ], +) +def test_historical_release_rejects_unsafe_download_url( + tmp_path, monkeypatch, download_url +): + catalog = _catalog(monkeypatch, tmp_path, _entry_with_release_url(download_url)) + + with pytest.raises(ExtensionError, match="has an invalid download_url"): + catalog.get_extension_info("demo-history", "0.4.12") + with pytest.raises(ExtensionError, match="has an invalid download_url"): + catalog.get_extension_versions("demo-history") + + +@pytest.mark.parametrize( + "download_url", + [ + "https://example.com/a.zip", + "http://localhost:8000/a.zip", + "http://127.0.0.1/a.zip", + "http://[::1]/a.zip", + ], +) +def test_historical_release_accepts_https_or_loopback_http( + tmp_path, monkeypatch, download_url +): + catalog = _catalog(monkeypatch, tmp_path, _entry_with_release_url(download_url)) + + selected = catalog.get_extension_info("demo-history", "0.4.12") + + assert selected["version"] == "0.4.12" + assert selected["download_url"] == download_url + + +@pytest.mark.parametrize("download_url", ["", " "]) +def test_blank_historical_download_url_still_reports_missing( + tmp_path, monkeypatch, download_url +): + catalog = _catalog(monkeypatch, tmp_path, _entry_with_release_url(download_url)) + + with pytest.raises(ExtensionError, match="needs a download_url"): + catalog.get_extension_info("demo-history", "0.4.12") + + +def test_extension_info_reports_unsafe_historical_download_url(tmp_path, monkeypatch): + project = tmp_path / "project" + (project / ".specify").mkdir(parents=True) + _catalog(monkeypatch, project, _entry_with_release_url("http://example.com/a.zip")) + monkeypatch.chdir(project) + + result = CliRunner().invoke( + app, ["extension", "info", "demo-history", "--versions"] + ) + + assert result.exit_code != 0 + assert "has an invalid download_url" in " ".join(result.output.split()) + + def test_selected_release_download_uses_its_url_without_relookup(tmp_path, monkeypatch): archive = _archive(tmp_path, "0.4.12") entry = _entry(archive)