The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor: keep subdir/sha shape rules at the admission gate only
teknium1e780748afc42
diff --git a/hermes_cli/plugin_catalog.py b/hermes_cli/plugin_catalog.pyindex 7a337e4bf86..9b296580dbf 100644--- a/hermes_cli/plugin_catalog.py+++ b/hermes_cli/plugin_catalog.py@@ -39,15 +39,8 @@ LIVE_CATALOG_FAILURE_TTL_SECONDS = 60.0_REQUEST_TIMEOUT = 5.0_MAX_LIVE_BYTES = 2 * 1024 * 1024-# \Z, not $: $ also matches just before a trailing newline, which would let a-# value carrying a newline reach the clone/install paths the admission CI-# already rejects. Keep in sync with scripts/validate_plugin_catalog.py.-_SHA_RE = re.compile(r"^[0-9a-f]{40}\Z")-_VERSION_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._+-]{0,31}\Z")-_REPO_RE = re.compile(r"^https://\S+\Z")-# The admission CI joins subdir onto a pinned clone before validating: it must be-# a plain relative path or the gate can be pointed at files outside the pin.-_SUBDIR_RE = re.compile(r"^[A-Za-z0-9._/-]+\Z")+_SHA_RE = re.compile(r"^[0-9a-f]{40}$")+_VERSION_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._+-]{0,31}$")# Catalog images may only come from GitHub: the Desktop catalog browser never fans out to# third-party hosts, and a raw URL pinned to the entry's commit is as immutable as the sha.IMAGE_HOSTS = ("raw.githubusercontent.com", "github.com")@@ -59,7 +52,7 @@ def is_allowed_image_url(url: str) -> bool:parts = urlsplit(url)host = (parts.hostname or "").lower()return parts.scheme == "https" and bool(host) and (host in IMAGE_HOSTS or host.endswith(IMAGE_HOST_SUFFIX))-_NAME_RE = re.compile(r"^[a-z0-9_-]{1,64}\Z")+_NAME_RE = re.compile(r"^[a-z0-9_-]{1,64}$")@dataclass@@ -143,17 +136,10 @@ def entry_from_mapping(data: Any, label: str) -> Optional[PluginCatalogEntry]:sha = str(data.get("sha") or "").strip().lower()tier = str(data.get("tier") or "community")category = str(data.get("category") or "desktop")- subdir_raw = data.get("subdir")problem = (f"invalid name {name!r} (must match [a-z0-9_-]{{1,64}})" if not _NAME_RE.match(name)- else f"repo must be an https:// URL (got {repo!r})" if not _REPO_RE.match(repo)+ else f"repo must be an https:// URL (got {repo!r})" if not repo.startswith("https://")else f"sha must be a full 40-character hex commit SHA (got {data.get('sha')!r})" if not _SHA_RE.match(sha)- else "subdir must be a string" if "subdir" in data and not isinstance(subdir_raw, str)- else f"subdir {subdir_raw!r} must be a relative path without '.' or '..' segments"- if isinstance(subdir_raw, str) and subdir_raw and (- not _SUBDIR_RE.match(subdir_raw)- or any(seg in ("", ".", "..") for seg in subdir_raw.split("/"))- )else f"tier must be one of {'/'.join(CATALOG_TIERS)} (got {tier!r})" if tier not in CATALOG_TIERSelse f"category must be one of {'/'.join(CATALOG_CATEGORIES)} (got {category!r})"if category not in CATALOG_CATEGORIES@@ -179,8 +165,7 @@ def entry_from_mapping(data: Any, label: str) -> Optional[PluginCatalogEntry]:description=str(data.get("description") or "").strip(),maintainer=str(data.get("maintainer") or "").strip(), tier=tier, category=category,requires_hermes=str(data.get("requires_hermes") or "").strip(),- subdir=subdir_raw if isinstance(subdir_raw, str) else "",- docs_url=str(data.get("docs_url") or "").strip(),+ subdir=str(data.get("subdir") or "").strip(), docs_url=str(data.get("docs_url") or "").strip(),version=version, image=image, screenshots=screenshots, readme=data.get("readme") is not False,platforms=_str_list(data.get("platforms")),title=str(data.get("title") or "").strip(), onboarding=data.get("onboarding") is True,diff --git a/tests/hermes_cli/test_plugin_catalog.py b/tests/hermes_cli/test_plugin_catalog.pyindex b0710467088..e1a7f2ac2db 100644--- a/tests/hermes_cli/test_plugin_catalog.py+++ b/tests/hermes_cli/test_plugin_catalog.py@@ -81,23 +81,6 @@ def test_invalid_entries_are_skipped_not_raised(tmp_path):assert entries[0].description == "café"-def test_source_fields_the_admission_gate_rejects_are_dropped(tmp_path):- """The runtime twin mirrors the gate: a traversal subdir would let- ``_raw_manifest_url`` escape the pinned repo, a whitespace repo reaches the- installer, and a non-string or newline-bearing field must not coerce."""- (tmp_path / "a.yaml").write_text(yaml.safe_dump(_entry("ok")))- (tmp_path / "b.yaml").write_text(yaml.safe_dump(_entry("nested", subdir="plugins/x")))- (tmp_path / "c.yaml").write_text(yaml.safe_dump(_entry("trav", subdir="../x")))- (tmp_path / "d.yaml").write_text(yaml.safe_dump(_entry("deep", subdir="plugin/../x")))- (tmp_path / "e.yaml").write_text(yaml.safe_dump(_entry("ws", repo="https://x/y z")))- (tmp_path / "f.yaml").write_text(yaml.safe_dump(_entry("nonstr", subdir=5)))- (tmp_path / "g.yaml").write_text(yaml.safe_dump(_entry("nl\n")))- (tmp_path / "h.yaml").write_text(yaml.safe_dump(_entry("nullsub", subdir=None)))- entries = pc.load_catalog(tmp_path)- assert {e.name for e in entries} == {"ok", "nested"}- assert next(e for e in entries if e.name == "nested").subdir == "plugins/x"--def test_find_removed_matches_name_or_normalized_repo(tmp_path):(tmp_path / "removed.yaml").write_text(yaml.safe_dump({"removed": [{"name": "evil", "repo": "https://github.com/x/evil.git", "reason": "malware", "date": "2026-01-01"}]}))diff --git a/website/scripts/extract-plugins.py b/website/scripts/extract-plugins.pyindex 4c0d1b1d180..a751462f9e8 100644--- a/website/scripts/extract-plugins.py+++ b/website/scripts/extract-plugins.py@@ -43,24 +43,18 @@ DEFAULT_CATALOG_DIR = REPO_ROOT / "plugin-catalog"DEFAULT_OUTPUT_DIR = REPO_ROOT / "website" / "static" / "api"# Written by fetch-plugin-stars.py (at most one GitHub probe per day); absent → no ranking data.DEFAULT_STARS_FILE = DEFAULT_OUTPUT_DIR / "plugin-stars.json"-# \Z, not $: $ also matches just before a trailing newline; the emitted JSON-# feeds installed clients' clone/install paths and must not smuggle one.-_GITHUB_REPO_RE = re.compile(r"^https://github\.com/([^/\s]+)/([^/\s#?]+?)(?:\.git)?/?\Z")+_GITHUB_REPO_RE = re.compile(r"^https://github\.com/([^/\s]+)/([^/\s#?]+?)(?:\.git)?/?$")CATALOG_TIERS = ("official", "community")CATALOG_CATEGORIES = ("desktop", "memory", "platform", "web", "tools", "voice", "automation", "models", "general")-SHA_RE = re.compile(r"^[0-9a-f]{40}\Z")+SHA_RE = re.compile(r"^[0-9a-f]{40}$")# Keep in sync with scripts/validate_plugin_catalog.py (cosmetic fields attached to the pin).-VERSION_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._+-]{0,31}\Z")-_REPO_RE = re.compile(r"^https://\S+\Z")-# Installed clients join subdir onto a pinned clone to install; the feed must not-# emit traversal or absolute forms (mirrors scripts/validate_plugin_catalog.py).-_SUBDIR_RE = re.compile(r"^[A-Za-z0-9._/-]+\Z")+VERSION_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._+-]{0,31}$")IMAGE_HOSTS = ("raw.githubusercontent.com", "github.com")IMAGE_HOST_SUFFIX = ".githubusercontent.com"MAX_SCREENSHOTS = 6# Forges whose raw-file URL scheme the site knows; ``readme: true`` on any other host is ignored.-_FORGE_REPO_RE = re.compile(r"^https://(github\.com|gitlab\.com)/([^/\s]+)/([^/\s#?]+?)(?:\.git)?/?\Z")+_FORGE_REPO_RE = re.compile(r"^https://(github\.com|gitlab\.com)/([^/\s]+)/([^/\s#?]+?)(?:\.git)?/?$")_SLUG_RE = re.compile(r"[^a-z0-9._-]+")@@ -239,9 +233,6 @@ def load_catalog_entries(catalog_dir: Path, stars: dict[str, int] | None = None,if not SHA_RE.match(sha):_log(f"skipping {path.name} ({name}): sha is not a 40-hex commit pin")continue- if not _REPO_RE.match(repo):- _log(f"skipping {path.name} ({name}): repo is not a whitespace-free https:// URL")- continuetier = str(raw.get("tier") or "community").strip().lower()if tier not in CATALOG_TIERS:@@ -252,17 +243,7 @@ def load_catalog_entries(catalog_dir: Path, stars: dict[str, int] | None = None,_log(f"{path.name} ({name}): unknown category {category!r}, treating as general")category = "general"- subdir_raw = raw.get("subdir")- if "subdir" in raw and (- not isinstance(subdir_raw, str)- or (isinstance(subdir_raw, str) and subdir_raw and (- not _SUBDIR_RE.match(subdir_raw)- or any(seg in ("", ".", "..") for seg in subdir_raw.split("/"))- ))- ):- _log(f"skipping {path.name} ({name}): subdir is not a plain relative path")- continue- subdir = subdir_raw if isinstance(subdir_raw, str) else ""+ subdir = str(raw.get("subdir") or "").strip()entries.append({"name": name,"description": str(raw.get("description") or "").strip(),