ci(plugin-catalog): maintainer allowlist for third-party tool downloads in the self-updater gate
The self-updater gate rejects any plugin script that both fetches from GitHub and writes or renames files. rom-studio (#153798) trips it on kit/kit.ts, which downloads the third-party poryscript 3.6.1 compiler from its own release, checks a fixed sha256 and unpacks it into kit/.cache. It never fetches or replaces rom-studio's own files, so the pin stays the only update path (README rule 3). Teknium ruled to allow it. A maintainer now lists such a file in scripts/ci/catalog_self_updater_allowlist.json by repo, pinned sha, path and the file's sha256: a re-pin, an edit to that file or a second fetching file is gated again. The list lives under scripts/ci/, which an entry PR may not touch (catalog_changed_entries.py), so a submitter cannot add themselves. Rule 3 in both rule blocks names the exception.
This commit is contained in:
@@ -23,7 +23,10 @@ meaningful:
|
||||
self-updater lets an installed copy move to a commit nobody reviewed.
|
||||
Updates reach users only through a SHA-bump PR here plus
|
||||
`hermes plugins update <name>`. Keep the updater in the standalone
|
||||
distribution if you want one; strip it from the catalog build.
|
||||
distribution if you want one; strip it from the catalog build. Downloading
|
||||
a separate third-party tool pinned by checksum is not a self-updater; a
|
||||
maintainer allows such a file by repo, pinned sha and file hash in
|
||||
`scripts/ci/catalog_self_updater_allowlist.json`.
|
||||
4. **SHA bumps are new PRs.** Updating an entry's pin is a new PR whose diff
|
||||
(old SHA → new SHA) is re-reviewed like any other change — reviewers are
|
||||
expected to look at the upstream commit range being adopted.
|
||||
|
||||
9
scripts/ci/catalog_self_updater_allowlist.json
Normal file
9
scripts/ci/catalog_self_updater_allowlist.json
Normal file
@@ -0,0 +1,9 @@
|
||||
[
|
||||
{
|
||||
"repo": "https://github.com/erosika/rom-studio",
|
||||
"sha": "ed04b3ce35d6c942c4e25a7285f6c46dc911b9d6",
|
||||
"path": "kit/kit.ts",
|
||||
"sha256": "1196e7fc3b53e506f11381ac4fa8f7d234d3459613d971b01c4c9f9d3f0fefc4",
|
||||
"why": "downloads the third-party poryscript 3.6.1 compiler from its GitHub release, checks it against a fixed sha256 and unpacks it into kit/.cache; never fetches or replaces rom-studio's own files (PR #153798)"
|
||||
}
|
||||
]
|
||||
@@ -25,6 +25,7 @@ Exit 0 = every entry passed, 1 = at least one failed (one ``::error file=<entry>
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
@@ -68,6 +69,11 @@ def _file_fetches_github(path: str) -> bool:
|
||||
_SELF_UPDATE_WRITE = (r"writeTextFile|renamePath|writeFile\(|writeFileSync|renameSync|copyFileSync"
|
||||
r"|cpSync|createWriteStream")
|
||||
_SCRIPT_GLOBS = ("*.js", "*.mjs", "*.cjs", "*.ts", "*.jsx", "*.tsx", "*.mts", "*.cts")
|
||||
# Maintainer-reviewed exceptions to the self-updater gate: a file that downloads a THIRD-PARTY tool
|
||||
# pinned by checksum (not the plugin's own code) and unpacks it into its cache. Keyed by repo +
|
||||
# pinned sha + path + the file's sha256, so a re-pin or any edit to the file is gated again. It
|
||||
# lives under scripts/ci/, which an entry PR may not touch (catalog_changed_entries.py).
|
||||
_SELF_UPDATER_ALLOWLIST = Path(__file__).resolve().with_name("catalog_self_updater_allowlist.json")
|
||||
# 600s: listed repos reach >1 GB (hermes-jackal-verified 1.43 GB, hindsight 741 MB); 120s would
|
||||
# false-fail a re-pin on a slow runner.
|
||||
_CLONE_SECONDS = 600
|
||||
@@ -199,7 +205,18 @@ def _check_payloads(plugin_dir: str) -> None:
|
||||
raise EntryRejected(f"unscannable executable payload (README rule 17): {found}")
|
||||
|
||||
|
||||
def _check_self_updater(plugin_dir: str) -> None:
|
||||
def _allowlisted(path: str, plugin_dir: str, repo: str, sha: str) -> bool:
|
||||
rel = os.path.relpath(path, plugin_dir)
|
||||
try:
|
||||
digest = hashlib.sha256(Path(path).read_bytes()).hexdigest()
|
||||
except OSError:
|
||||
return False
|
||||
return any(row.get("repo") == repo and row.get("sha") == sha and row.get("path") == rel
|
||||
and row.get("sha256") == digest
|
||||
for row in json.loads(_SELF_UPDATER_ALLOWLIST.read_text(encoding="utf-8-sig")))
|
||||
|
||||
|
||||
def _check_self_updater(plugin_dir: str, repo: str = "", sha: str = "") -> None:
|
||||
# SELF-UPDATER GATE (README rule 3): the pin is the only update path. A desktop bundle that
|
||||
# both fetches from GitHub AND writes/renames plugin files is a self-updater; either half
|
||||
# alone is fine (a plugin may read the API, or manage its own data files). NUL-delimited
|
||||
@@ -218,7 +235,9 @@ def _check_self_updater(plugin_dir: str) -> None:
|
||||
writers = subprocess.run(["xargs", "-r0", "grep", "-lZE", _SELF_UPDATE_WRITE],
|
||||
input=real, stdout=subprocess.PIPE, check=False,
|
||||
timeout=_VALIDATE_SECONDS).stdout
|
||||
found = _substituted(writers).replace("\n", " ")
|
||||
flagged = [p for p in writers.split(b"\0")
|
||||
if p and not _allowlisted(os.fsdecode(p), plugin_dir, repo, sha)]
|
||||
found = _substituted(b"\0".join(flagged)).replace("\n", " ")
|
||||
if found:
|
||||
raise EntryRejected("self-updating code in catalog build (fetches GitHub AND writes "
|
||||
f"plugin files): {found}")
|
||||
@@ -249,7 +268,7 @@ def validate_entry(entry: str, workroot: str) -> None:
|
||||
validate = ["hermes", "plugins", "validate", "--install-deps", plugin_dir]
|
||||
if _run(validate, timeout=_VALIDATE_SECONDS).returncode != 0:
|
||||
raise EntryRejected("hermes plugins validate failed")
|
||||
_check_self_updater(plugin_dir)
|
||||
_check_self_updater(plugin_dir, repo, sha)
|
||||
_check_attested(fields["ATTESTED"], plugin_dir, repo, sha)
|
||||
_check_payloads(plugin_dir)
|
||||
|
||||
|
||||
@@ -72,3 +72,33 @@ SHA = "a" * 40
|
||||
def test_entry_fields_are_refused_before_use(entry, bad):
|
||||
verdict = fields.source_fields(entry)["BAD"]
|
||||
assert verdict.startswith(bad) if bad else verdict == ""
|
||||
|
||||
|
||||
def test_self_updater_allowlist_matches_only_the_reviewed_file(tmp_path, monkeypatch):
|
||||
# A maintainer-reviewed third-party download passes only at its exact repo, pin and file
|
||||
# hash: a re-pin, an edited byte or a second fetching file is gated again.
|
||||
import hashlib
|
||||
import json
|
||||
|
||||
plugin = tmp_path / "plugin"
|
||||
(plugin / "kit").mkdir(parents=True)
|
||||
tool = plugin / "kit" / "kit.ts"
|
||||
tool.write_text("fetch('releases/download/1.0/tool.zip'); renameSync(a, b)\n", encoding="utf-8")
|
||||
other = plugin / "update.ts"
|
||||
other.write_text("fetch('releases/latest'); writeFileSync(self, body)\n", encoding="utf-8")
|
||||
allow = tmp_path / "allow.json"
|
||||
allow.write_text(json.dumps([{"repo": "https://x/y", "sha": SHA, "path": "kit/kit.ts",
|
||||
"sha256": hashlib.sha256(tool.read_bytes()).hexdigest()}]))
|
||||
monkeypatch.setattr(gate, "_SELF_UPDATER_ALLOWLIST", allow)
|
||||
|
||||
with pytest.raises(gate.EntryRejected) as hit:
|
||||
gate._check_self_updater(str(plugin), "https://x/y", SHA)
|
||||
assert "update.ts" in str(hit.value) and "kit.ts" not in str(hit.value)
|
||||
|
||||
other.unlink()
|
||||
gate._check_self_updater(str(plugin), "https://x/y", SHA)
|
||||
with pytest.raises(gate.EntryRejected, match="kit/kit.ts"):
|
||||
gate._check_self_updater(str(plugin), "https://x/y", "b" * 40)
|
||||
tool.write_text(tool.read_text() + "//\n", encoding="utf-8")
|
||||
with pytest.raises(gate.EntryRejected, match="kit/kit.ts"):
|
||||
gate._check_self_updater(str(plugin), "https://x/y", SHA)
|
||||
|
||||
@@ -81,7 +81,10 @@ the gallery. There is no separate listing to maintain.
|
||||
self-updater lets an installed copy move to a commit nobody reviewed.
|
||||
Updates reach users only through a SHA-bump PR here plus
|
||||
`hermes plugins update <name>`. Keep the updater in the standalone
|
||||
distribution if you want one; strip it from the catalog build.
|
||||
distribution if you want one; strip it from the catalog build. Downloading
|
||||
a separate third-party tool pinned by checksum is not a self-updater; a
|
||||
maintainer allows such a file by repo, pinned sha and file hash in
|
||||
`scripts/ci/catalog_self_updater_allowlist.json`.
|
||||
4. **SHA bumps are new PRs.** Updating an entry's pin is a new PR whose diff
|
||||
(old SHA → new SHA) is re-reviewed like any other change — reviewers are
|
||||
expected to look at the upstream commit range being adopted.
|
||||
|
||||
Reference in New Issue
Block a user