The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(ci): close remaining pin-gate escapes found in review
beardthelion7e52bd0fa9e1
diff --git a/.github/workflows/plugin-catalog-ci.yml b/.github/workflows/plugin-catalog-ci.ymlindex df5ba2fcb3d..37d09d4ba3f 100644--- a/.github/workflows/plugin-catalog-ci.yml+++ b/.github/workflows/plugin-catalog-ci.yml@@ -24,6 +24,32 @@ jobs:timeout-minutes: 10steps:- uses: actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a # v7.0.1+ with:+ fetch-depth: 0 # need the merge-base to diff the PR's changed files+ persist-credentials: false # this job is read-only++ - name: Catalog PRs must only touch plugin-catalog/+ run: |+ set -euo pipefail+ # The gate's own enforcement code (this workflow, the validator, the+ # composite actions, the built hermes) resolves from the PR checkout,+ # so an admission PR must be data-only: a diff that also touches+ # tooling could neuter the gate vetting it. PRs that legitimately+ # change the gate itself get reviewed under the normal workflows,+ # which do not have this restriction.+ MERGE_BASE=$(git merge-base "origin/${{ github.base_ref }}" HEAD)+ # git diff runs on its own so its failure still fails the step+ # instead of looking like "nothing outside the catalog".+ NON_CATALOG=$(git diff --name-only "$MERGE_BASE"...HEAD)+ NON_CATALOG=$(printf '%s' "$NON_CATALOG" | grep -v '^plugin-catalog/' || true)+ if [ -n "$NON_CATALOG" ]; then+ echo "::error::catalog PRs must only touch plugin-catalog/**, found:"+ # Filenames are PR-controlled; a newline in one could smuggle a+ # workflow command into the log.+ printf '%s' "$NON_CATALOG" | tr '\0\n' ' '+ echo+ exit 1+ fi- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0with:@@ -48,6 +74,32 @@ jobs:- uses: actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a # v7.0.1with:fetch-depth: 0 # need the merge-base to diff changed catalog files+ # `hermes plugins validate` below runs pinned-repo code; keep the+ # job's token out of .git/config where that code could read it.+ persist-credentials: false++ - name: Catalog PRs must only touch plugin-catalog/+ run: |+ set -euo pipefail+ # The gate's own enforcement code (this workflow, the validator, the+ # composite actions, the built hermes) resolves from the PR checkout,+ # so an admission PR must be data-only: a diff that also touches+ # tooling could neuter the gate vetting it. PRs that legitimately+ # change the gate itself get reviewed under the normal workflows,+ # which do not have this restriction.+ MERGE_BASE=$(git merge-base "origin/${{ github.base_ref }}" HEAD)+ # git diff runs on its own so its failure still fails the step+ # instead of looking like "nothing outside the catalog".+ NON_CATALOG=$(git diff --name-only "$MERGE_BASE"...HEAD)+ NON_CATALOG=$(printf '%s' "$NON_CATALOG" | grep -v '^plugin-catalog/' || true)+ if [ -n "$NON_CATALOG" ]; then+ echo "::error::catalog PRs must only touch plugin-catalog/**, found:"+ # Filenames are PR-controlled; a newline in one could smuggle a+ # workflow command into the log.+ printf '%s' "$NON_CATALOG" | tr '\0\n' ' '+ echo+ exit 1+ fi- name: Find changed catalog entriesid: changed@@ -194,14 +246,16 @@ jobs:echo "::error file=$entry::subdir '$SUBDIR' resolves outside the pinned clone"FAILED=1; echo "::endgroup::"; continuefi- # Confinement is per-symlink too: a committed link inside the plugin- # dir must resolve inside the clone, or the manifest check and- # `hermes plugins validate` read non-pinned files.- if [ -d "$PLUGIN_DIR" ] && ! find "$PLUGIN_DIR" -type l -print0 | while IFS= read -r -d '' link; do+ # Confinement is per-symlink too, across the whole clone: find does+ # not descend into a symlinked directory, so an allowed in-clone+ # link like plugin/ext -> ../lib would otherwise hide lib/evil ->+ # /outside from a PLUGIN_DIR-only scan while reads through it still+ # escape the pin.+ if ! find "$CLONE_DIR" -path "$CLONE_DIR/.git" -prune -o -type l -print0 | while IFS= read -r -d '' link; dotarget=$(realpath -m -- "$link")case "$target" in "$CLONE_DIR"|"$CLONE_DIR"/*) ;; *) exit 1 ;; esacdone; then- echo "::error file=$entry::a symlink inside the plugin dir resolves outside the pinned clone"+ echo "::error file=$entry::a symlink in the repo resolves outside the pinned clone"FAILED=1; echo "::endgroup::"; continuefi# Native plugin.yaml OR portable Agent Plugins v1 plugin.json@@ -223,11 +277,11 @@ jobs:# plugin may read the API, or manage its own data files).# NUL-delimited both ways: committed filenames with spaces or# newlines must not split into grep options or forged log lines.- SELF_UPDATE=$(grep -rlZE 'releases/latest|raw\.githubusercontent\.com' \+ SELF_UPDATE=$(grep -rlZE 'releases/latest|releases/download|raw\.githubusercontent\.com|codeload\.github\.com' \--include='*.js' --include='*.mjs' --include='*.cjs' --include='*.ts' \--include='*.jsx' --include='*.tsx' --include='*.mts' --include='*.cts' \"$PLUGIN_DIR" \- | xargs -r0 grep -lZE 'writeTextFile|renamePath|writeFile\(' || true)+ | xargs -r0 grep -lZE 'writeTextFile|renamePath|writeFile\(|writeFileSync|renameSync|copyFileSync|cpSync|createWriteStream' || true)SELF_UPDATE=$(printf '%s' "$SELF_UPDATE" | tr '\0\n' ' ')if [ -n "$SELF_UPDATE" ]; thenecho "::error file=$entry::self-updating code in catalog build (fetches GitHub AND writes plugin files): $SELF_UPDATE"diff --git a/tests/ci/test_plugin_catalog_ci_confinement.py b/tests/ci/test_plugin_catalog_ci_confinement.pyindex c35327b62af..31e6528ca0c 100644--- a/tests/ci/test_plugin_catalog_ci_confinement.py+++ b/tests/ci/test_plugin_catalog_ci_confinement.py@@ -299,7 +299,7 @@ def test_symlink_inside_plugin_dir_escaping_clone_fails(tmp_path, fixture):repo="https://fixture.invalid/repo", sha=sha, subdir="plugin")res = _run_gate(_env(tmp_path, origin, entry, tmpdir), tmp_path)assert res.returncode != 0, res.stdout + res.stderr- assert "symlink inside the plugin dir resolves outside" in res.stdout + res.stderr+ assert "symlink in the repo resolves outside" in res.stdout + res.stderrassert "PASS" not in res.stdout@@ -323,7 +323,7 @@ def test_plugin_yaml_as_symlink_to_outside_file_fails(tmp_path, fixture):repo="https://fixture.invalid/repo", sha=sha, subdir="plugin")res = _run_gate(_env(tmp_path, origin, entry, tmpdir), tmp_path)assert res.returncode != 0, res.stdout + res.stderr- assert "symlink inside the plugin dir resolves outside" in res.stdout + res.stderr+ assert "symlink in the repo resolves outside" in res.stdout + res.stderrassert "PASS" not in res.stdout@@ -527,3 +527,126 @@ def test_changed_files_step_reports_renamed_and_typechanged_entries(tmp_path):files = out.read_text(encoding="utf-8")assert "plugin-catalog/renamed.yaml" in filesassert "plugin-catalog/b.yaml" in files++[email protected]("linux")+def test_symlink_hidden_behind_in_clone_dir_link_is_caught(tmp_path, fixture):+ """find does not descend into a symlinked directory: plugin/ext -> ../lib is+ itself in-clone and passes, while lib/evil -> outside is only reachable+ through it. A PLUGIN_DIR-only scan enumerates ext but never sees lib/evil,+ so the scan must cover the whole clone."""+ origin, sha, tmpdir = fixture+ planted = tmp_path / "planted"+ planted.mkdir()+ (planted / "plugin.yaml").write_text("name: planted\n", encoding="utf-8")+ (origin / "lib").mkdir()+ (origin / "lib" / "evil").symlink_to(planted / "plugin.yaml")+ (origin / "plugin" / "ext").symlink_to("../lib")+ subprocess.run(["git", "add", "-A"], cwd=origin, check=True)+ subprocess.run(+ ["git", "-c", "user.email=t@t", "-c", "user.name=t", "commit", "-qm", "evil"],+ cwd=origin, check=True)+ sha = subprocess.check_output(+ ["git", "rev-parse", "HEAD"], cwd=origin, text=True).strip()+ entry = _write_entry(tmp_path, "evil.yaml",+ repo="https://fixture.invalid/repo", sha=sha, subdir="plugin")+ res = _run_gate(_env(tmp_path, origin, entry, tmpdir), tmp_path)+ assert res.returncode != 0, res.stdout + res.stderr+ assert "resolves outside the pinned clone" in res.stdout + res.stderr+ assert "PASS" not in res.stdout++[email protected]("linux")+def test_self_updater_via_release_download_and_writefilesync(tmp_path, fixture):+ """Neither releases/latest nor raw.githubusercontent covers a tarball pull+ from releases/download or codeload, and the Node fs.* write sinks were+ missing beside the Tauri plugin names."""+ origin, sha, tmpdir = fixture+ (origin / "plugin" / "dl.js").write_text(+ "releases/download fs.writeFileSync(", encoding="utf-8")+ subprocess.run(["git", "add", "-A"], cwd=origin, check=True)+ subprocess.run(+ ["git", "-c", "user.email=t@t", "-c", "user.name=t", "commit", "-qm", "evil"],+ cwd=origin, check=True)+ sha = subprocess.check_output(+ ["git", "rev-parse", "HEAD"], cwd=origin, text=True).strip()+ entry = _write_entry(tmp_path, "evil.yaml",+ repo="https://fixture.invalid/repo", sha=sha, subdir="plugin")+ res = _run_gate(_env(tmp_path, origin, entry, tmpdir), tmp_path)+ assert res.returncode != 0, res.stdout + res.stderr+ assert "self-updating code" in res.stdout + res.stderr+ assert "PASS" not in res.stdout+++def _guard_block(job: str) -> str:+ data = yaml.safe_load(WORKFLOW.read_text(encoding="utf-8"))+ step = next(s for s in data["jobs"][job]["steps"]+ if s.get("name", "").startswith("Catalog PRs must only touch"))+ # The workflow expands ${{ github.base_ref }} before bash ever sees it.+ return step["run"].replace("${{ github.base_ref }}", "main")+++def test_data_only_guard_is_identical_in_both_jobs():+ """Both jobs run the same guard text; drift between them would let a+ tooling change slip into a 'catalog' PR through one job."""+ assert _guard_block("structural") == _guard_block("pinned-source-validate")+++def _guard_pr_repo(tmp_path: Path, extra_files: dict[str, str]) -> Path:+ """Fixture: main has a catalog entry; the PR commit adds a catalog entry+ plus whatever extra files the caller gives ({} means a clean diff)."""+ repo = tmp_path / "pr"+ (repo / "plugin-catalog").mkdir(parents=True)+ (repo / "plugin-catalog" / "old.yaml").write_text("name: old\n", encoding="utf-8")+ subprocess.run(["git", "init", "-qb", "main", str(repo)], check=True)+ for args in (["config", "user.email", "t@t"], ["config", "user.name", "T"],+ ["add", "-A"], ["commit", "-qm", "base"],+ ["update-ref", "refs/remotes/origin/main", "HEAD"]):+ subprocess.run(["git", *args], cwd=repo, check=True)+ (repo / "plugin-catalog" / "new.yaml").write_text("name: new\n", encoding="utf-8")+ for name, content in extra_files.items():+ path = repo / name+ path.parent.mkdir(parents=True, exist_ok=True)+ path.write_text(content, encoding="utf-8")+ subprocess.run(["git", "add", "-A"], cwd=repo, check=True)+ subprocess.run(+ ["git", "-c", "user.email=t@t", "-c", "user.name=t", "commit", "-qm", "pr"],+ cwd=repo, check=True)+ return repo++[email protected]("linux")+def test_data_only_guard_rejects_mixed_diff(tmp_path):+ """A PR adding an entry AND touching gate tooling must fail before any+ clone happens."""+ repo = _guard_pr_repo(tmp_path, {"scripts/tool.py": "x = 2\n"})+ script = tmp_path / "guard-step.sh"+ script.write_text(_guard_block("structural"), encoding="utf-8")+ res = subprocess.run(+ ["bash", str(script)], cwd=repo,+ capture_output=True, text=True, timeout=60)+ assert res.returncode == 1, res.stdout + res.stderr+ assert "must only touch plugin-catalog" in res.stdout+ assert "scripts/tool.py" in res.stdout++[email protected]("linux")+def test_data_only_guard_passes_clean_catalog_diff(tmp_path):+ repo = _guard_pr_repo(tmp_path, {})+ script = tmp_path / "guard-step.sh"+ script.write_text(_guard_block("structural"), encoding="utf-8")+ res = subprocess.run(+ ["bash", str(script)], cwd=repo,+ capture_output=True, text=True, timeout=60)+ assert res.returncode == 0, res.stdout + res.stderr+++def test_checkouts_do_not_persist_credentials():+ """Pinned-repo code runs under `hermes plugins validate`; the job token must+ not sit in .git/config where that code could read it."""+ data = yaml.safe_load(WORKFLOW.read_text(encoding="utf-8"))+ checkouts = [s for job in data["jobs"].values() for s in job["steps"]+ if "actions/checkout@" in s.get("uses", "")]+ assert checkouts+ for step in checkouts:+ assert step.get("with", {}).get("persist-credentials") is False