Skip to content

Commit f227e79

Browse files
cliffhallclaude
andcommitted
Never target below an affected copy; rank a SHA pin only by an exact # vX.Y.Z; scope the alert row to advisories with a fix
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
1 parent 21eb81b commit f227e79

5 files changed

Lines changed: 75 additions & 14 deletions

File tree

‎AGENTS.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ halves are replaced by scheduled workflows that file **issues**, and a
200200
maintainer writes each fix by hand against `v2/main`. Each script's header holds
201201
its reasoning; these are the rules.
202202

203-
| Sweep | Replaces | Files | Cadence |
204-
| ----------------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
205-
| `dependency-refresh.yml` → `scripts/dependency-refresh.mjs` | `.github/dependabot.yml` (deleted) | **One** tracking issue: `npm outdated` across the root and workspaces, each Python server's `uv lock --upgrade` dry run, and each workflow `uses:` ref against its action's highest release | Monthly |
206-
| `dependabot-alerts.yml` → `scripts/dependabot-alerts.mjs` | Security-update PRs (the `automated-security-fixes` **repo setting**, off) | One issue per vulnerable package per lockfile (npm and pip), targeting the lowest patched version outside every applicable range, or flagging that no listed fix clears them all | Daily |
207-
| `sdk-watch.yml` → `scripts/sdk-watch.mjs` | Nothing: SDK releases were watched by habit | One issue per MCP SDK group behind its registry (npm `@modelcontextprotocol/*`, PyPI `mcp`), plus a Claude analysis comment | Nightly |
203+
| Sweep | Replaces | Files | Cadence |
204+
| ----------------------------------------------------------- | -------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
205+
| `dependency-refresh.yml` → `scripts/dependency-refresh.mjs` | `.github/dependabot.yml` (deleted) | **One** tracking issue: `npm outdated` across the root and workspaces, each Python server's `uv lock --upgrade` dry run, and each workflow `uses:` ref against its action's highest release | Monthly |
206+
| `dependabot-alerts.yml` → `scripts/dependabot-alerts.mjs` | Security-update PRs (the `automated-security-fixes` **repo setting**, off) | One issue per vulnerable package per lockfile (npm and pip) that has a patched release, targeting the lowest patched version outside every applicable range, or flagging that no listed fix clears them all | Daily |
207+
| `sdk-watch.yml` → `scripts/sdk-watch.mjs` | Nothing: SDK releases were watched by habit | One issue per MCP SDK group behind its registry (npm `@modelcontextprotocol/*`, PyPI `mcp`), plus a Claude analysis comment | Nightly |
208208

209209
- **Never re-add `.github/dependabot.yml` or switch `automated-security-fixes`
210210
back on.** Keep Dependabot **alerts** on: the alert sweep consumes them. The

‎scripts/dependabot-alerts.mjs‎

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,12 @@ function versionCompare(ecosystem) {
392392
*
393393
* @param {string} ecosystem
394394
* @param {Array<{fixedIn: string, range: string}>} advisories
395+
* @param {string[]} [installed] the affected copies' versions; the target is
396+
* never below the newest of them
395397
* @returns {{fixedIn: string, verified: boolean, stillOpen: string[]}}
396398
* `stillOpen` names the advisories whose range still covers the target
397399
*/
398-
export function pickTarget(ecosystem, advisories) {
400+
export function pickTarget(ecosystem, advisories, installed = []) {
399401
const covers = (version) =>
400402
advisories.filter((a) => {
401403
try {
@@ -405,9 +407,27 @@ export function pickTarget(ecosystem, advisories) {
405407
return true;
406408
}
407409
});
408-
const candidates = [...new Set(advisories.map((a) => a.fixedIn))].sort(
409-
versionCompare(ecosystem),
410-
);
410+
const compare = versionCompare(ecosystem);
411+
// Never below an affected copy: a "bump" to an older version is a
412+
// downgrade, and raising a floor to it leaves the newer copy in range.
413+
const floor =
414+
installed.length > 0 ? highestVersion(ecosystem, installed) : null;
415+
const candidates = [...new Set(advisories.map((a) => a.fixedIn))]
416+
.filter((c) => floor === null || compare(c, floor) >= 0)
417+
.sort(compare);
418+
if (candidates.length === 0) {
419+
// Every listed fix is older than an affected copy: name the advisories
420+
// that still cover the newest one.
421+
return {
422+
fixedIn: highestVersion(
423+
ecosystem,
424+
advisories.map((a) => a.fixedIn),
425+
),
426+
verified: false,
427+
stillOpen: covers(floor).map((a) => a.ghsa),
428+
};
429+
}
430+
411431
for (const candidate of candidates) {
412432
if (covers(candidate).length === 0) {
413433
return { fixedIn: candidate, verified: true, stillOpen: [] };
@@ -535,7 +555,13 @@ export function narrowToApplicable(group, entries) {
535555
fixedIn,
536556
targetVerified: verified,
537557
targetStillOpen: stillOpen,
538-
}))(pickTarget(group.ecosystem, advisories)),
558+
}))(
559+
pickTarget(
560+
group.ecosystem,
561+
advisories,
562+
affected.map((e) => e.version),
563+
),
564+
),
539565
},
540566
affected,
541567
};

‎scripts/dependabot-alerts.test.mjs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,30 @@ test("pickTarget names the lowest patched version outside every range", () => {
392392
);
393393
});
394394

395+
test("pickTarget never targets below an affected copy", () => {
396+
// Copilot's example: copies at 1.3.0 and 2.0.5. 1.4.0 clears every range,
397+
// but is a downgrade for the 2.0.5 copy; 2.1.0 is the answer.
398+
const advisories = [
399+
{ ghsa: "A", range: "< 1.4.0", fixedIn: "1.4.0" },
400+
{ ghsa: "B", range: ">= 2.0.0, < 2.1.0", fixedIn: "2.1.0" },
401+
];
402+
assert.deepEqual(pickTarget("npm", advisories, ["1.3.0", "2.0.5"]), {
403+
fixedIn: "2.1.0",
404+
verified: true,
405+
stillOpen: [],
406+
});
407+
// Every listed fix is older than an affected copy: unverified, naming the
408+
// advisory that still covers the newest copy.
409+
assert.deepEqual(
410+
pickTarget(
411+
"npm",
412+
[{ ghsa: "A", range: "< 1.4.0 || >= 3.0.0, < 3.2.0", fixedIn: "1.4.0" }],
413+
["3.0.5"],
414+
),
415+
{ fixedIn: "1.4.0", verified: false, stillOpen: ["A"] },
416+
);
417+
});
418+
395419
test("an unverified target is flagged in the body and the comment", () => {
396420
const [group] = groupAlerts([
397421
alert({

‎scripts/dependency-refresh.mjs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import { spawnSync } from "node:child_process";
4444
import { existsSync, readdirSync, readFileSync } from "node:fs";
4545
import path from "node:path";
4646
import { fileURLToPath, pathToFileURL } from "node:url";
47-
import { SHA_REF, parseUses } from "./lib/action-refs.mjs";
47+
import { EXACT_VERSION, SHA_REF, parseUses } from "./lib/action-refs.mjs";
4848
import {
4949
SERVERS,
5050
SWEEP_LABELS,
@@ -220,8 +220,13 @@ export function parseActionRefs(yaml) {
220220
if (!match) continue;
221221
const parsed = parseUses(match[1] ?? match[2] ?? match[3]);
222222
if (parsed === null) continue;
223-
const comment = /#\s*(v?\d+(?:\.\d+){0,2})\s*$/.exec(line);
224-
if (SHA_REF.test(parsed.ref) && comment) parsed.version = comment[1];
223+
// Only an exact `# vX.Y.Z` ranks a SHA pin (`EXACT_VERSION`, the guard's
224+
// own rule): `# v7` would compare at major precision and hide every patch
225+
// release, so a coarse comment leaves the pin unranked, and listed.
226+
const comment = /#\s*(\S+)\s*$/.exec(line)?.[1];
227+
if (SHA_REF.test(parsed.ref) && comment && EXACT_VERSION.test(comment)) {
228+
parsed.version = comment;
229+
}
225230
refs.push(parsed);
226231
}
227232
return refs;

‎scripts/dependency-refresh.test.mjs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ test("parseActionRefs reads tags, SHA pins with their release, and skips the res
200200
` - uses: "actions/setup-node@v7"`,
201201
" - uses: 'owner/repo/sub@v2' # a comment",
202202
` - uses: actions/cache@${SHA}`,
203+
` - uses: actions/coarse@${SHA} # v7`,
203204
" - uses: ./local-action",
204205
" - uses: docker://alpine:3",
205206
" - uses: no-ref",
@@ -212,8 +213,13 @@ test("parseActionRefs reads tags, SHA pins with their release, and skips the res
212213
{ action: "actions/setup-node", ref: "v7" },
213214
{ action: "owner/repo/sub", ref: "v2" },
214215
{ action: "actions/cache", ref: SHA },
216+
// `# v7` names no exact release, so it does not rank the pin.
217+
{ action: "actions/coarse", ref: SHA },
218+
]);
219+
assert.deepEqual(unrankedPins(refs), [
220+
"actions/cache@d23441a",
221+
"actions/coarse@d23441a",
215222
]);
216-
assert.deepEqual(unrankedPins(refs), ["actions/cache@d23441a"]);
217223
});
218224

219225
test("isActionStale compares at the precision the ref names", () => {

0 commit comments

Comments
 (0)