Skip to content

The agent that grows with you

fix(plugins): require an https:// update_url

ethernetd395860ec58d
diff --git a/hermes_cli/plugins_cmd.py b/hermes_cli/plugins_cmd.py
index a2023f41468..b4eade1722c 100644
--- a/hermes_cli/plugins_cmd.py
+++ b/hermes_cli/plugins_cmd.py
@@ -836,13 +836,12 @@ def _install_plugin_core(
# manifest's update_url is COPIED into the row at install. Check
# time compares manifest vs tag; a mismatch is needs-fixing and
# only `hermes plugins trust-update-url` moves the tag.
- try:
- manifest = _read_manifest(Path(tmp_target))
- update_url = (manifest or {}).get("update_url")
- if isinstance(update_url, str) and update_url.strip():
- new_metadata[plugin_name]["update_url"] = update_url.strip()
- except Exception:
- pass
+ if manifest.get("update_url"):
+ from hermes_cli.plugins_updates import https_update_url
+ try:
+ new_metadata[plugin_name]["update_url"] = https_update_url(manifest["update_url"])
+ except ValueError as exc:
+ raise PluginOperationError(f"Plugin '{plugin_name}' {exc}") from exc
if catalog_entry is not None:
new_metadata[plugin_name]["catalog_name"] = catalog_entry.name
new_metadata[plugin_name]["catalog_tier"] = catalog_entry.tier
@@ -1642,6 +1641,13 @@ def cmd_trust_update_url(name: str) -> None:
"update_url mismatch."
)
return
+ if claimed is not None:
+ from hermes_cli.plugins_updates import https_update_url
+ try:
+ claimed = https_update_url(claimed)
+ except ValueError as exc:
+ console.print(f"[red]Error:[/red] Plugin '{name}' {exc}. Not trusted.")
+ sys.exit(1)
row["update_url"] = claimed
rows[target.name] = row
diff --git a/hermes_cli/plugins_updates.py b/hermes_cli/plugins_updates.py
index 786b8f2a7dd..06f71dae30d 100644
--- a/hermes_cli/plugins_updates.py
+++ b/hermes_cli/plugins_updates.py
@@ -339,6 +339,20 @@ def check_pip_plugins(
return results
+def https_update_url(url: object) -> str:
+ """Normalize a manifest ``update_url``; raises ValueError unless it is ``https://``.
+
+ The feed picks which commit of the trusted origin gets installed and the gateway fetches
+ it unattended every check interval, so a plaintext ``http://`` (MITM → an old vulnerable
+ commit), ``file://`` or ``ftp://`` feed is refused at install, at trust-update-url AND at
+ the fetch itself (rows saved before this rule existed).
+ """
+ text = str(url or "").strip()
+ if not text.lower().startswith("https://"):
+ raise ValueError(f"update_url must be an https:// URL, got {text!r}")
+ return text
+
+
def default_fetch(url: str) -> str:
"""The real feed fetcher: url -> text (raises on failure).
@@ -347,7 +361,7 @@ def default_fetch(url: str) -> str:
"""
import urllib.request
- with urllib.request.urlopen(url, timeout=_FETCH_TIMEOUT) as resp:
+ with urllib.request.urlopen(https_update_url(url), timeout=_FETCH_TIMEOUT) as resp:
data = resp.read(_MAX_FEED_BYTES)
return data.decode("utf-8", errors="replace")
diff --git a/tests/hermes_cli/test_plugin_install_ref.py b/tests/hermes_cli/test_plugin_install_ref.py
index f7588da4f45..2821eb73fb7 100644
--- a/tests/hermes_cli/test_plugin_install_ref.py
+++ b/tests/hermes_cli/test_plugin_install_ref.py
@@ -434,3 +434,40 @@ def test_checkout_that_lands_on_another_commit_is_still_rejected(monkeypatch, tm
with pytest.raises(PluginOperationError, match="does not match requested"):
_checkout_exact_revision(clone, "git", tag_object_sha)
+
+
[email protected]("update_url", ["http://feed.example/f.yml", "file:///etc/feed.yml", "ftp://feed.example/f.yml"])
+def test_install_refuses_a_non_https_update_url(monkeypatch, tmp_path, update_url):
+ """The saved update_url is fetched unattended by the gateway and picks which origin commit
+ gets installed; anything a network peer can rewrite (http/ftp) or a local path must not
+ become the feed. Refused before any install state exists."""
+ from hermes_cli.plugins_cmd import PluginOperationError, _install_plugin_core
+
+ repo, _old, _new = _plugin_repo(tmp_path)
+ (repo / "plugin.yaml").write_text(
+ yaml.safe_dump({"name": "demo", "version": "1.0.0", "update_url": update_url}), encoding="utf-8")
+ _commit(repo, "feed", "feed")
+ home = tmp_path / "home"
+ monkeypatch.setenv("HERMES_HOME", str(home))
+
+ with pytest.raises(PluginOperationError, match="https://"):
+ _install_plugin_core(repo.as_uri(), force=False)
+
+ assert not (home / "plugins" / "demo").exists()
+ assert not (home / "plugins" / ".install-metadata.json").exists()
+
+
+def test_install_saves_an_https_update_url_tag(monkeypatch, tmp_path):
+ from hermes_cli.plugins_cmd import _install_plugin_core
+
+ repo, _old, sha = _plugin_repo(tmp_path)
+ (repo / "plugin.yaml").write_text(
+ yaml.safe_dump({"name": "demo", "version": "1.0.0", "update_url": " https://feed.example/f.yml "}),
+ encoding="utf-8")
+ sha = _commit(repo, "feed", "feed")
+ home = tmp_path / "home"
+ monkeypatch.setenv("HERMES_HOME", str(home))
+
+ _install_plugin_core(repo.as_uri(), force=False)
+
+ assert _metadata(home)["demo"]["update_url"] == "https://feed.example/f.yml"
diff --git a/tests/hermes_cli/test_plugins_check_updates.py b/tests/hermes_cli/test_plugins_check_updates.py
index 65932f37ff8..8d967d52460 100644
--- a/tests/hermes_cli/test_plugins_check_updates.py
+++ b/tests/hermes_cli/test_plugins_check_updates.py
@@ -467,3 +467,18 @@ def test_run_checks_never_mutates(tmp_path):
)
assert results[0].update_available is True
assert (plugins / ".install-metadata.json").read_text(encoding="utf-8") == before
+
+
[email protected]("url", ["http://feed.example/f.yml", "file:///etc/passwd", "ftp://x/f.yml", ""])
+def test_default_fetch_refuses_non_https_feeds_before_any_request(monkeypatch, url):
+ """Rows saved before the https rule (or hand-edited) still reach the real fetcher from the
+ gateway tick; the sink refuses them instead of opening the URL."""
+ import urllib.request
+ from hermes_cli.plugins_updates import default_fetch
+
+ def never(*a, **k):
+ raise AssertionError("urlopen must not be reached")
+
+ monkeypatch.setattr(urllib.request, "urlopen", never)
+ with pytest.raises(ValueError, match="https://"):
+ default_fetch(url)