Repository navigation
Commit 6f50c51
authored
ci: pin pkg-pr-new to the lockfile; document why the pnpm toolchain cannot be integrity-pinned (#361)
Closes the last two unpinned executables in CI. **One is fixed. One
cannot be, and this PR says so with evidence instead of pretending
otherwise.**
## 1. `npx pkg-pr-new publish` — FIXED
`publish-commit.yml:20` ran `npx pkg-pr-new publish`, and `pkg-pr-new`
was in **neither `package.json` nor `pnpm-lock.yaml`** — so npx resolved
the `latest` dist-tag at run time and executed whatever the registry
served, unverified. It was the **only** `npx` target in the repo not
already a devDependency (`tsx` and `vitest`, the others, resolve from
the installed tree).
Not latent: `pkg-pr-new@0.0.87` was published **hours** before this
branch was cut. Every PR after that moment would have executed a build
nobody here had looked at.
**In scope in that job (honestly):** zero `secrets.` references;
`GITHUB_TOKEN` at `contents: read` on a **public** repo, so near-zero
value; and `pkg-pr-new` is handed no token at all (it authenticates via
GitHub App + run metadata). The real prize is the **pkg.pr.new publish
channel** — a substituted CLI publishes arbitrary tarballs under this
repo's preview URLs, which reviewers and users then `npm i`.
Actions-cache poisoning into `drift-live-pr` (7 live provider keys, same
PR scope) is a *possibility I did not test* and am **not** claiming.
Fix: exact-pinned devDependency + `pnpm exec`, so the preceding `pnpm
install --frozen-lockfile` verifies the tarball against a reviewed
sha512.
### Watched RED (sandboxed, `env -u`-scrubbed, no real credential
present)
Committed step body, verbatim, against a local registry serving
substituted bytes:
```
$ npx pkg-pr-new publish
npm warn exec The following package was not found and will be installed: pkg-pr-new@0.0.86
SUBSTITUTED-PKG-PR-NEW-RAN
STEP_EXIT=0
$ cat MARKER.txt
SUBSTITUTED pkg-pr-new EXECUTED argv=publish
```
Attacker code ran, wrote to disk, and **the step reported success**.
### Watched GREEN — refused
```
$ pnpm install --frozen-lockfile
ERR_PNPM_TARBALL_INTEGRITY Got unexpected checksum for ".../pkg-pr-new-0.0.86.tgz".
Wanted "sha512-BwPsw/e1Be…bmCk8A==" Got "sha512-3CDoOk/m0h0…XnS1NA=="
INSTALL_EXIT=1
$ ls MARKER.txt -> No such file or directory
$ ls node_modules/.bin/ -> No such file or directory
$ pnpm exec pkg-pr-new publish
ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL Command "pkg-pr-new" not found
```
The demonstrated **absence** of the payload at an executor — no marker,
no binary, the step cannot resolve its own command.
### Positive control — CI still works
```
$ pnpm install --frozen-lockfile -> INSTALL_EXIT=0, + pkg-pr-new 0.0.86
installed dist/index.js sha256 = d1f4c92bbfad12699f7046646082d4075d84161b3275f29d9a7f3fb3cadb9d31
independently downloaded 0.0.86 = d1f4c92bbfad12699f7046646082d4075d84161b3275f29d9a7f3fb3cadb9d31
$ pnpm exec pkg-pr-new publish
Continuous Releases are only available in GitHub Actions.
```
Byte-identical to the reviewed tarball, and that refusal is the **real**
CLI's own guard — my payload has no such message. "Refuse everything"
cannot satisfy this half.
### Positive control on the REAL path — this PR's own `preview` job
**passed**
```
Run pnpm install --frozen-lockfile -> + pkg-pr-new 0.0.86
Run pnpm exec pkg-pr-new publish -> ⚡️ Your npm packages are published.
{ owner: CopilotKit, repo: aimock, ref: 361 }
preview pass
```
The lockfile-verified binary published the previews exactly as the
unpinned `npx` used to. Nothing about CI's behaviour changed except what
governs the bytes.
### RE-BREAK — 5 mutations, all red, workspace md5 identical
before/after
| # | mutation | result |
|---|---|---|
| M1 | step reverted to today's `npx pkg-pr-new publish` | RED 1/21 |
| M2 | `pkg-pr-new` deleted from devDependencies | RED 2/21 |
| M3 | exact pin widened to `^0.0.86` | RED 2/21 |
| M4 | genuine corepack hash appended to `packageManager` | RED 1/21 |
| M5 | one `pnpm/action-setup@<sha>` unpinned to `@v6` | RED 1/21 |
M1 proves the guard reds on the state `main` is in **today** — the suite
is not vacuous.
### `package.json` / `pnpm-lock.yaml`
`package.json`: **one added line**, `"pkg-pr-new": "0.0.86"`. Exact, not
`^`, so Renovate cannot silently widen it. `pnpm-lock.yaml`: three
hunks, **purely additive**.
- **package `version` is UNCHANGED** — `git diff -U0 package.json | grep
-c '"version"'` → `0`; tree `1.38.0`, `HEAD~1` `1.38.0`.
- **No other dependency moved** — the lockfile diff contains **zero**
deletion lines.
`0.0.86` not `0.0.87`: `.87` was published minutes before the pin was
written, which reproduces in slow motion the window the pin exists to
close. `.86` has been public since 2026-07-30, has **zero runtime deps
and no install scripts**, and its integrity is agreed by three
independent sources (packument, my own sha512 over the tarball, the
lockfile).
## 2. The pnpm toolchain — **NOT PINNABLE**, evidence below
`"packageManager": "pnpm@10.28.2"` has no integrity hash. Corepack
**does** enforce a `+sha512.<hash>` suffix — a 128-zero hash gives
`Error: Mismatch hashes`, exit 1. But `pnpm/action-setup@0977fd99` (the
SHA all 16 call sites pin) **strips it**. Its own source:
```ts
// packageManager is always exact `pnpm@<version>[+<integrity>]` per spec.
// Strip the integrity hash for self-update.
? packageManager.slice('pnpm@'.length).split('+')[0]
```
and the shipped bundle agrees:
`startsWith("pnpm@")?i.slice(5).split("+")[0]:void 0`.
Proved by running that exact `dist/index.js` twice:
```
A) "pnpm@10.28.2+sha512." + "0"*128 (corepack REFUSES this) -> EXIT=0, installed 10.28.2
B) "pnpm@10.28.2+sha512.41872f03…" (the GENUINE hash) -> EXIT=0, installed 10.28.2
```
**Identical outcome with a right hash and a wrong one — the suffix is
never compared.** So I did **not** add one: it would read as an
integrity pin while verifying nothing, which is exactly the defect class
this repo has been deleting. **M4 now reds if anyone adds it.**
What *is* verified: the action bootstraps pnpm v11.19.0 via `npm ci`
against lockfiles committed inside the action (byte-pinned transitively,
since the action is SHA-pinned), then `pnpm self-update 10.28.2` fetches
from the npm registry verified against **registry-served** metadata.
That second hop is TOFU, not a hash reviewed here. The comment already
at `test-drift.yml:205-209` states this correctly and needed no change.
Real routes, both out of scope (16 call sites, two in files another
agent held this round): corepack (works, but is **removed in Node 25**,
so it acquires its own expiry) or fetch-and-sha256 the Ollama way.
Pinning one workflow and leaving fifteen would be an inconsistent
toolchain and a worse trap than a documented gap.
## Guard suite
`src/__tests__/ci-toolchain-pinning.test.ts`, 21 tests. Asserts the
**general** invariant — every package name any workflow hands to
`npx`/`pnpm dlx`/`npm exec` must be manifest-declared — so a future
unpinned executable anywhere reds too. `pnpm exec` is deliberately
excluded (resolves only from `node_modules`, fails loudly when absent —
as GREEN-A showed). Comment lines are stripped before matching; a
`workflows.length > 5` assertion prevents a silently empty sweep.
## Gates — real exit codes, read from logs, never through a pipe
`pnpm install --frozen-lockfile` 0 · `pnpm build` 0 · **`pnpm test` 0 —
173 files, 5087 tests, all passed** (no known flakes fired) · `pnpm
test:drift` 0 (18 passed/8 skipped files, 119/66 tests) · `tsc --noEmit`
0 · `pnpm lint` 0 · `prettier --check` on all 4 changed files 0 ·
`actionlint` 0 · `bash -n` on all 3 changed `run:` bodies 0 · `zizmor
--min-severity medium` 0, "No findings to report" · `pnpm test:exports`
0 (all four resolvers 🟢).
## Scope
`publish-release.yml` and `test-pytest.yml` **untouched**.
`CHANGELOG.md`, `.claude-plugin/*`, `charts/*`,
`packages/aimock-pytest/*` untouched. No credential
read/echoed/persisted; every sandbox run under `env -u` scrubbing. No
workflow run triggered. Explicit file list on commit, never `git add
-A`.4 files changed
Lines changed: 172 additions & 1 deletion
File tree
- .github/workflows
- src/__tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| 205 | + | |
205 | 206 | | |
206 | 207 | | |
207 | 208 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
0 commit comments