Skip to content

Commit 2b65349

Browse files
cliffhallclaude
andcommitted
Warn about vulnerable intervals above an alert target, and ask for the fix to be verified against every range
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent a969a9d commit 2b65349

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

‎scripts/dependabot-alerts.mjs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,9 @@ export function buildIssueBody(
737737
: []),
738738
...steps.map((step, i) => (steps.length > 1 ? `${i + 1}. ${step}` : step)),
739739
"",
740+
...disjointCaution(group),
741+
`**Then verify** before opening the PR: every locked copy must be outside every range in the Advisories table. \`node scripts/dependabot-alerts.mjs --dry-run\` against the branch should report this exposure cleared.`,
742+
"",
740743
"| Vulnerable copy | Version |",
741744
"| --- | --- |",
742745
...affected.map((e) => `| \`${cell(e.path)}\` | \`${cell(e.version)}\` |`),
@@ -772,6 +775,28 @@ export function buildIssueBody(
772775
].join("\n");
773776
}
774777

778+
/**
779+
* A warning when a vulnerable interval sits ABOVE the target: an advisory
780+
* patched later than the target, or a disjoint (`||`) range. A floor raised
781+
* to the target alone would let a later resolve land in that interval, so the
782+
* new range must also stay clear of it.
783+
*
784+
* @param {{ecosystem: string, fixedIn: string, targetVerified?: boolean, advisories: Array<{ghsa: string, range: string, fixedIn: string}>}} group
785+
* @returns {string[]} lines to add, or none
786+
*/
787+
export function disjointCaution(group) {
788+
if (group.targetVerified === false) return [];
789+
const compare = versionCompare(group.ecosystem);
790+
const above = group.advisories.filter(
791+
(a) => a.range.includes("||") || compare(a.fixedIn, group.fixedIn) > 0,
792+
);
793+
if (above.length === 0) return [];
794+
return [
795+
`⚠️ **Keep the new range clear of the higher vulnerable interval** of ${above.map((a) => `\`${a.ghsa}\` (\`${a.range}\`)`).join(", ")}: a bare floor at \`${group.fixedIn}\` can later resolve into it. Cap the range below it, or raise the floor past it.`,
796+
"",
797+
];
798+
}
799+
775800
/**
776801
* The date an already-cleared body records. Reused when the body is
777802
* regenerated, so a cleared issue, which stays open, is not edited daily for

‎scripts/dependabot-alerts.test.mjs‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
parseCommentMarker,
3636
parseMarker,
3737
pickTarget,
38+
disjointCaution,
3839
unverifiedReason,
3940
scopedOverrideExample,
4041
splitOwner,
@@ -439,6 +440,42 @@ test("pickTarget never targets below an affected copy", () => {
439440
);
440441
});
441442

443+
test("a vulnerable interval above the target is called out, and every fix is verified", () => {
444+
const group = {
445+
ecosystem: "npm",
446+
fixedIn: "1.4.0",
447+
targetVerified: true,
448+
advisories: [
449+
{ ghsa: "A", range: "< 1.4.0", fixedIn: "1.4.0" },
450+
{ ghsa: "B", range: ">= 2.0.0, < 2.1.0", fixedIn: "2.1.0" },
451+
],
452+
};
453+
const [caution] = disjointCaution(group);
454+
assert.match(caution, /`B` \(`>= 2\.0\.0, < 2\.1\.0`\)/);
455+
assert.ok(!caution.includes("`A`"));
456+
assert.deepEqual(
457+
disjointCaution({ ...group, advisories: [group.advisories[0]] }),
458+
[],
459+
);
460+
assert.equal(
461+
disjointCaution({
462+
...group,
463+
advisories: [
464+
{ ghsa: "C", range: "< 1.4.0 || >= 3.0.0, < 3.1.0", fixedIn: "1.4.0" },
465+
],
466+
}).length,
467+
2,
468+
);
469+
assert.deepEqual(disjointCaution({ ...group, targetVerified: false }), []);
470+
const body = buildIssueBody(npmGroup("hono", "4.13.7"), {
471+
affected: [
472+
{ path: "node_modules/hono", version: "4.12.0", topLevel: true },
473+
],
474+
declarers: ["package.json"],
475+
});
476+
assert.match(body, /\*\*Then verify\*\*/);
477+
});
478+
442479
test("an unverified target names the version it actually checked", () => {
443480
// Every fix is older than the installed copy: the body blames the copy,
444481
// not the fix, which no listed range covers.

0 commit comments

Comments
 (0)