Repository navigation
Expand file tree
/
Copy pathwiki_watch.py
More file actions
executable file
·559 lines (498 loc) · 24.5 KB
/
Copy pathwiki_watch.py
File metadata and controls
executable file
·559 lines (498 loc) · 24.5 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
#!/usr/bin/env python3
"""Watch ADR-0089's triggers for leaving Wiki.js 2.x, weekly, off-host.
WHAT THIS IS FOR. ADR-0089 keeps the household wiki on Wiki.js 2.x until one
of three triggers fires:
1. a published `requarks/wiki` advisory affects the pinned version and has no
2.x fix 30 days after publication;
2. no 2.x release for six months;
3. 3.0 reaches a stable release.
Nothing read the project's own advisories. The weekly CVE scan reads the
image's packages, a different list. And an advisory that is never fixed
produces neither a release nor a pin bump, so nothing would ever have
prompted a reading. This is that reading, every Monday.
WHAT IT REPORTS, in the job summary and in one issue (`security`, `wiki`):
* an advisory that affects the pin and HAS a fix: bump the pin. Not a
trigger: the fix exists, and Dependabot or a person should take it.
* an advisory that affects the pin with NO 2.x fix: the trigger 1 clock,
in days, and FIRED from day 30;
* an advisory whose version range this cannot read: a person reads it.
Never silently passed;
* trigger 2 and trigger 3 when they fire.
The issue is created when there is something to report, rewritten each week,
and closed by the run that finds nothing. It is keyed on a hidden marker.
ON A 3.x PIN (ADR-0108, #1339). Triggers 2 and 3 are about leaving 2.x, so
they are read only while the pin is 2.x; once the pin is 3.x they are spent
and not reported. The advisory reading stays, because it was never about 2.x:
"a fix" means a fix in the pin's own major, so on 3.x an advisory fixed in a
later 3.x is a bump, and one with no 3.x fix runs the same 30-day clock for a
person to act on. 3.x ships its fixes as `>=3.3.0`, so a patched version is
read out of whatever operator it carries.
THE RANGES ARE UPSTREAM'S, AND MESSY. Seen in the real list: `<2.5.314`,
`<= v2.5.314`, a bare `2.5.303`, `>=2.5.80 <2.5.151`, and `> 2.4.17` patched
in 2.4.107, which read literally flags every later 2.x. So the order is:
- a listed patched version at or below the pin means the pin carries the
fix;
- only otherwise is the range asked;
- and a range this cannot parse is reported for a person to read, not
guessed at.
A failure to read the advisories or the releases fails the run. A finding
does not: the issue is the notification, as in cve-scan.yml.
Usage: scripts/wiki_watch.py summary to stdout
scripts/wiki_watch.py --sync-issue also create/edit/close the issue
scripts/wiki_watch.py --sync-issue --dry-run
scripts/wiki_watch.py --self-test
Environment:
GH_TOKEN for the API reads and --sync-issue (issues: write)
GITHUB_REPOSITORY the repo the issue lives in (default Gerrrt/HomeLab)
GITHUB_SERVER_URL, GITHUB_RUN_ID link the issue to the run that wrote it
"""
from __future__ import annotations
import calendar
import datetime as dt
import json
import os
import pathlib
import re
import subprocess
import sys
import urllib.request
from dataclasses import dataclass, field
RED = "\033[0;31m"
GREEN = "\033[0;32m"
OFF = "\033[0m"
UPSTREAM = "requarks/wiki"
COMPOSE = pathlib.Path(__file__).resolve().parent.parent / "stacks" / "wiki" / "compose.yaml"
PIN = re.compile(r"image:\s*ghcr\.io/requarks/wiki:v?(\d+\.\d+\.\d+)@sha256:")
MARKER = "<!-- wiki-watch: requarks/wiki -->"
CLOCK_DAYS = 30 # ADR-0089 trigger 1
STALE_MONTHS = 6 # ADR-0089 trigger 2, calendar months, not days
VERSION = re.compile(r"v?(\d+)\.(\d+)\.(\d+)")
STABLE_3 = re.compile(r"^v?3\.\d+\.\d+$")
TWO_X = re.compile(r"^v?2\.\d+\.\d+$")
CLAUSE = re.compile(r"(<=|>=|<|>|=)?\s*v?(\d+\.\d+\.\d+)")
PATCHED = re.compile(r"v?\d+\.\d+\.\d+")
def ver(text: str) -> tuple[int, int, int] | None:
m = VERSION.fullmatch(text.strip())
return (int(m[1]), int(m[2]), int(m[3])) if m else None
def in_range(pin: tuple[int, int, int], spec: str) -> bool | None:
"""True/False for a range this can read, None for one it cannot.
Clauses are ANDed, separated by commas or spaces. A bare version is an exact
match, as in the real `2.5.303`.
"""
spec = spec.strip()
if not spec:
return None
clauses = CLAUSE.findall(spec)
# Everything in the range must be a clause: refuse a range with leftover text
# (`all`, `*`, an `||`) rather than ignore the part that was not understood.
if not clauses or re.sub(r"[\s,]", "", CLAUSE.sub("", spec)):
return None
for op, v in clauses:
bound = ver(v)
if bound is None:
return None
ok = {
"<": pin < bound,
"<=": pin <= bound,
">": pin > bound,
">=": pin >= bound,
"=": pin == bound,
"": pin == bound,
}[op]
if not ok:
return False
return True
@dataclass
class Finding:
ghsa: str
severity: str
published: dt.datetime
url: str
summary: str
kind: str # "bump", "clock", "fired", "unreadable"
detail: str = ""
age_days: int = 0
@dataclass
class Report:
pin: str
findings: list[Finding] = field(default_factory=list)
latest_2x: tuple[str, dt.datetime] | None = None
stable_3: str | None = None
stale: bool = False
@property
def anything(self) -> bool:
return bool(self.findings or self.stale or self.stable_3)
def add_months(when: dt.datetime, months: int) -> dt.datetime:
"""The same day `months` calendar months on, clamped to the end of a shorter
month: 08-31 plus six months is 02-28 (or 29), not March."""
month = when.month - 1 + months
year, month = when.year + month // 12, month % 12 + 1
day = min(when.day, calendar.monthrange(year, month)[1])
return when.replace(year=year, month=month, day=day)
def parse_time(text: str) -> dt.datetime:
return dt.datetime.fromisoformat(text)
def assess(pin_text: str, advisories: list[dict], releases: list[dict], now: dt.datetime) -> Report:
pin = ver(pin_text)
if pin is None:
raise ValueError(f"pinned version {pin_text!r} is not x.y.z")
report = Report(pin=pin_text)
for a in advisories:
published = parse_time(a["published_at"])
age = (now - published).days
base = {
"ghsa": a.get("ghsa_id", "?"),
"severity": a.get("severity") or "unknown",
"published": published,
"url": a.get("html_url", ""),
"summary": a.get("summary", ""),
"age_days": age,
}
for v in a.get("vulnerabilities") or []:
# `2.5.315`, `3.1.0, 3.0.3` and `>=3.3.0` all occur: take the versions, not the operators.
patched = [p for p in (ver(x) for x in PATCHED.findall(v.get("patched_versions") or "")) if p]
rng = v.get("vulnerable_version_range") or ""
# An entry that names only an older major (`> 2.4.17` patched in 2.4.107) is about that
# line. Read literally against a 3.x pin it would match, and it is not a 3.x advisory.
named = [p for p in (ver(x) for x in PATCHED.findall(rng)) if p] + patched
if named and max(p[0] for p in named) < pin[0]:
continue
# Only a fix on the pin's own line is carried by it: 2.5.318 is not in 3.3.0.
if any(p[0] == pin[0] and p <= pin for p in patched):
continue # the pin carries a listed fix
hit = in_range(pin, rng)
if hit is False:
continue
if hit is None:
report.findings.append(
Finding(**base, kind="unreadable", detail=f"range `{v.get('vulnerable_version_range')}`")
)
continue
fix_same = sorted(p for p in patched if p[0] == pin[0] and p > pin)
if fix_same:
report.findings.append(
Finding(**base, kind="bump", detail="fixed in " + ".".join(map(str, fix_same[0])))
)
else:
report.findings.append(Finding(**base, kind="fired" if age >= CLOCK_DAYS else "clock"))
break # one finding per advisory
if pin[0] != 2:
return report # triggers 2 and 3 are about leaving 2.x, and are spent (ADR-0108)
for r in releases:
tag = r.get("tag_name", "")
if r.get("draft") or not r.get("published_at"):
continue
when = parse_time(r["published_at"])
if TWO_X.match(tag) and (report.latest_2x is None or when > report.latest_2x[1]):
report.latest_2x = (tag, when)
if STABLE_3.match(tag) and not r.get("prerelease"):
report.stable_3 = report.stable_3 or tag
if report.latest_2x is None or now >= add_months(report.latest_2x[1], STALE_MONTHS):
report.stale = True
return report
def render(report: Report, now: dt.datetime) -> str:
major = report.pin.split(".")[0]
on_2x = major == "2"
if on_2x:
out = [f"## Wiki.js: ADR-0089's triggers, against the pinned {report.pin}", ""]
labels = {
"fired": "**Trigger 1 FIRED**: no 2.x fix after 30 days",
"clock": "Trigger 1 clock running: no 2.x fix yet",
"bump": "Affects the pin, and a 2.x fix exists: bump the pin",
"unreadable": "Range not understood: read it",
}
else:
out = [f"## Wiki.js: published advisories, against the pinned {report.pin}", ""]
labels = {
"fired": f"**No {major}.x fix after 30 days**: decide what to do",
"clock": f"No {major}.x fix yet",
"bump": f"Affects the pin, and a {major}.x fix exists: bump the pin",
"unreadable": "Range not understood: read it",
}
if report.findings:
out += ["| Advisory | Severity | Published | Days | State |", "| --- | --- | --- | --- | --- |"]
for f in sorted(report.findings, key=lambda f: f.published):
state = labels[f.kind] + (f" ({f.detail})" if f.detail else "")
out.append(
f"| [{f.ghsa}]({f.url}) {f.summary} | {f.severity} | {f.published:%Y-%m-%d} | {f.age_days} | {state} |"
)
else:
out.append(f"No published `{UPSTREAM}` advisory affects {report.pin}.")
out.append("")
if not on_2x:
out.append("ADR-0089's triggers 2 and 3 were about leaving 2.x, and are spent (ADR-0108).")
return "\n".join(out) + "\n"
if report.latest_2x:
tag, when = report.latest_2x
days = (now - when).days
line = f"Latest 2.x release: `{tag}`, {when:%Y-%m-%d}, {days} days ago."
out.append(line + (" **Trigger 2 FIRED**: six months without a 2.x release." if report.stale else ""))
else:
out.append("**Trigger 2 FIRED**: no 2.x release was found at all.")
if report.stable_3:
out.append(f"**Trigger 3 FIRED**: `{report.stable_3}` is a stable 3.x release.")
out += [
"",
("When a trigger fires, the move is its own issue, with a restore rehearsal (ADR-0089, Consequences)."),
]
return "\n".join(out) + "\n"
def gh(*args: str, stdin: str | None = None) -> str:
proc = subprocess.run(["gh", *args], input=stdin, text=True, capture_output=True, check=False)
if proc.returncode != 0:
sys.exit(f"{RED}error:{OFF} gh {' '.join(args[:2])} failed: {proc.stderr.strip()}")
return proc.stdout
def fetch() -> tuple[list[dict], list[dict]]:
"""Both lists, through gh and the run's token, or without a token if that is
refused. A workflow's GITHUB_TOKEN is scoped to its own repository, and
whether it may read another repository's advisory list is not something to
find out on the Monday it matters. Published advisories and releases of a
public repository need no token at all. Both failing exits non-zero."""
def with_gh(endpoint: str) -> list[dict] | None:
# One object per line from `--jq '.[]'`, which works on any gh; --slurp
# is newer than some hosts' gh.
proc = subprocess.run(
["gh", "api", "--paginate", "--jq", ".[]", endpoint], text=True, capture_output=True, check=False
)
if proc.returncode != 0:
print(f"gh api {endpoint} refused ({proc.stderr.strip()}); trying without a token", file=sys.stderr)
return None
return [json.loads(line) for line in proc.stdout.splitlines() if line.strip()]
def without_token(endpoint: str) -> list[dict]:
items: list[dict] = []
for page in range(1, 11): # 1,000 items: an order more than either list holds
req = urllib.request.Request(
f"https://api.github.com/{endpoint}&page={page}",
headers={"Accept": "application/vnd.github+json", "User-Agent": "wiki-watch"},
)
try:
with urllib.request.urlopen(req, timeout=30) as resp:
batch = json.load(resp)
except OSError as e:
sys.exit(f"{RED}error:{OFF} {endpoint}: {e}")
items += batch
if len(batch) < 100:
return items
sys.exit(f"{RED}error:{OFF} {endpoint}: more than 1,000 items, which is not this list")
def every(endpoint: str) -> list[dict]:
got = with_gh(endpoint)
return got if got is not None else without_token(endpoint)
return (
every(f"repos/{UPSTREAM}/security-advisories?state=published&per_page=100"),
every(f"repos/{UPSTREAM}/releases?per_page=100"),
)
def title(report: Report) -> str:
fired = [f for f in report.findings if f.kind == "fired"]
if fired and not report.pin.startswith("2."):
return f"Wiki.js {report.pin}: an advisory has had no fix for 30 days"
if fired or report.stale or report.stable_3:
return "Wiki.js: an ADR-0089 trigger has fired"
return f"Wiki.js {report.pin}: advisories to act on"
def sync(report: Report, body: str, dry_run: bool) -> None:
repo = os.environ.get("GITHUB_REPOSITORY", "Gerrrt/HomeLab")
run = ""
if os.environ.get("GITHUB_RUN_ID"):
run = f"\n\nWritten by {os.environ.get('GITHUB_SERVER_URL', 'https://github.com')}/{repo}/actions/runs/{os.environ['GITHUB_RUN_ID']}."
full = f"{MARKER}\n{body}{run}"
issues = json.loads(
gh("issue", "list", "-R", repo, "--state", "open", "--label", "wiki", "--limit", "200", "--json", "number,body")
)
mine = [i for i in issues if MARKER in (i.get("body") or "")]
if report.anything:
if mine:
print(f"edit #{mine[0]['number']}")
if not dry_run:
gh(
"issue",
"edit",
str(mine[0]["number"]),
"-R",
repo,
"--title",
title(report),
"--body-file",
"-",
stdin=full,
)
else:
print("create")
if not dry_run:
gh(
"issue",
"create",
"-R",
repo,
"--title",
title(report),
"--label",
"security",
"--label",
"wiki",
"--body-file",
"-",
stdin=full,
)
elif mine:
print(f"close #{mine[0]['number']}")
if not dry_run:
gh(
"issue",
"close",
str(mine[0]["number"]),
"-R",
repo,
"--comment",
"Nothing to report against the pinned version this week.",
)
def self_test() -> int:
fail = 0
def check(name: str, got, want) -> None:
nonlocal fail
ok = got == want
fail += not ok
print(
f" {GREEN + 'PASS' if ok else RED + 'FAIL'}{OFF} {name}"
+ ("" if ok else f"\n got {got!r}, want {want!r}")
)
pin = (2, 5, 316)
# Every range shape in requarks/wiki's real list, 2026-10-07.
check("<2.5.314 excludes a later pin", in_range(pin, "<2.5.314"), False)
check("<= v2.5.314 reads the v", in_range((2, 5, 314), "<= v2.5.314"), True)
check("a bare version is exact", in_range((2, 5, 303), "2.5.303"), True)
check("a bare version is not a floor", in_range(pin, "2.5.303"), False)
check("two clauses are ANDed", in_range((2, 5, 100), ">=2.5.80 <2.5.151"), True)
check("and both must hold", in_range(pin, ">=2.5.80 <2.5.151"), False)
check("a comma separates clauses too", in_range((2, 5, 100), ">= 2.5.80, < 2.5.151"), True)
check("an open range matches, read literally", in_range(pin, "> 2.4.17"), True)
check("text it does not understand is unreadable", in_range(pin, "all versions"), None)
check("a wildcard is unreadable", in_range(pin, "*"), None)
check("an empty range is unreadable", in_range(pin, ""), None)
check("an alternative is unreadable, not half-read", in_range(pin, "<2.5.100 || >2.6.0"), None)
now = dt.datetime(2026, 10, 7, tzinfo=dt.UTC)
def adv(ghsa, published, rng, patched):
return {
"ghsa_id": ghsa,
"published_at": published,
"severity": "high",
"html_url": f"https://github.com/{UPSTREAM}/security/advisories/{ghsa}",
"summary": ghsa,
"vulnerabilities": [{"vulnerable_version_range": rng, "patched_versions": patched}],
}
releases = [
{"tag_name": "v2.5.316", "published_at": "2026-09-28T00:00:00Z", "prerelease": False},
{"tag_name": "3.0.0-beta.628", "published_at": "2026-10-04T00:00:00Z", "prerelease": False},
]
real = [
adv("GHSA-old-open", "2022-01-01T00:00:00Z", "> 2.4.17", "2.4.107"),
adv("GHSA-fixed", "2026-09-21T07:51:15Z", "<2.5.314", "2.5.315"),
adv("GHSA-exact", "2024-09-18T00:00:00Z", "2.5.303", "2.5.304"),
]
r = assess("2.5.316", real, releases, now)
check("today's real list affects 2.5.316 with nothing", [f.ghsa for f in r.findings], [])
check("the open-ended range is answered by its patched version", r.anything, False)
check("a 3.0 beta is not trigger 3, even unmarked as prerelease", r.stable_3, None)
check("a 2.x release nine days ago is not trigger 2", r.stale, False)
r = assess("2.5.316", [adv("GHSA-new", "2026-09-30T00:00:00Z", "<= 2.5.316", "")], releases, now)
check("an unfixed advisory at 7 days runs the clock", [(f.kind, f.age_days) for f in r.findings], [("clock", 7)])
r = assess("2.5.316", [adv("GHSA-new", "2026-09-01T00:00:00Z", "<= 2.5.316", "")], releases, now)
check("at 36 days trigger 1 has fired", [f.kind for f in r.findings], ["fired"])
r = assess("2.5.316", [adv("GHSA-3only", "2026-08-01T00:00:00Z", "<= 2.5.316", "3.0.1")], releases, now)
check("a fix only in 3.x is no 2.x fix", [f.kind for f in r.findings], ["fired"])
r = assess("2.5.316", [adv("GHSA-bump", "2026-08-01T00:00:00Z", "<= 2.5.316", "2.5.317")], releases, now)
check(
"a 2.x fix above the pin is a bump, not a trigger",
[(f.kind, f.detail) for f in r.findings],
[("bump", "fixed in 2.5.317")],
)
r = assess("2.5.316", [adv("GHSA-odd", "2026-08-01T00:00:00Z", "every release", "")], releases, now)
check("an unreadable range is reported, not passed", [f.kind for f in r.findings], ["unreadable"])
old = [{"tag_name": "v2.5.316", "published_at": "2026-03-01T00:00:00Z", "prerelease": False}]
check("220 days without a 2.x release is trigger 2", assess("2.5.316", [], old, now).stale, True)
check("no 2.x release at all is trigger 2", assess("2.5.316", [], [], now).stale, True)
# Calendar months, not 183 days (#1057 review). 2026-03-01 plus 183 days is
# Monday 2026-08-31, a day early; the anniversary is 09-01.
mar1 = [{"tag_name": "v2.5.316", "published_at": "2026-03-01T00:00:00Z", "prerelease": False}]
at = dt.datetime(2026, 8, 31, tzinfo=dt.UTC)
check("the day before the six-month anniversary is not trigger 2", assess("2.5.316", [], mar1, at).stale, False)
at = dt.datetime(2026, 9, 1, tzinfo=dt.UTC)
check("the anniversary itself is trigger 2", assess("2.5.316", [], mar1, at).stale, True)
aug31 = dt.datetime(2025, 8, 31, tzinfo=dt.UTC)
check("six months from 08-31 clamps to the end of February", add_months(aug31, 6).date(), dt.date(2026, 2, 28))
check("and to the 29th in a leap year", add_months(aug31.replace(year=2027), 6).date(), dt.date(2028, 2, 29))
check(
"months carry into the next year",
add_months(dt.datetime(2026, 10, 7, tzinfo=dt.UTC), 6).date(),
dt.date(2027, 4, 7),
)
ga = releases + [{"tag_name": "v3.0.0", "published_at": "2026-10-05T00:00:00Z", "prerelease": False}]
check("a stable v3.0.0 is trigger 3", assess("2.5.316", [], ga, now).stable_3, "v3.0.0")
pre = releases + [{"tag_name": "v3.0.0", "published_at": "2026-10-05T00:00:00Z", "prerelease": True}]
check("a v3.0.0 marked prerelease is not", assess("2.5.316", [], pre, now).stable_3, None)
# On a 3.x pin (ADR-0108). The advisories are the real list of 2026-11-09.
nov9 = dt.datetime(2026, 11, 9, tzinfo=dt.UTC)
real3 = [
adv("GHSA-35r7-33j8-ghwg", "2026-11-05T00:00:00Z", "<= 2.5.317", "3.1.0"),
adv("GHSA-3c74-j8g3-p255", "2026-11-05T00:00:00Z", "<=3.0.2", "3.1.0"),
adv("GHSA-2rx3-7vrr-h3gv", "2026-11-08T00:00:00Z", ">=3.0.0,<=3.1.1", ">=3.2.0"),
adv("GHSA-pq85-v5r4-w5xj", "2026-11-09T00:00:00Z", "=3.2.0", ">=3.3.0"),
]
stable = [{"tag_name": "3.3.0", "published_at": "2026-11-09T00:00:00Z", "prerelease": False}]
r = assess("3.3.0", real3, stable, nov9)
check("3.3.0 carries every fix published by 2026-11-09", r.findings, [])
check("on 3.x a stable 3.x release is not trigger 3", r.stable_3, None)
check("on 3.x the 2.x release history is not trigger 2", r.stale, False)
check("so on 3.3.0 there is nothing to report", r.anything, False)
check("and the summary says the triggers are spent", "spent" in render(r, nov9), True)
r = assess("2.5.317", real3, stable, nov9)
# `<=3.0.2` read literally includes every 2.x, and #1298 reported it so; that is unchanged.
check(
"the same list against 2.5.317: a fix only in 3.x is the clock",
[(f.ghsa, f.kind) for f in r.findings],
[("GHSA-35r7-33j8-ghwg", "clock"), ("GHSA-3c74-j8g3-p255", "clock")],
)
r = assess("3.2.0", real3, stable, nov9)
check(
"a `>=3.3.0` fix above a 3.2.0 pin is a bump",
[(f.kind, f.detail) for f in r.findings],
[("bump", "fixed in 3.3.0")],
)
r = assess("3.3.0", [adv("GHSA-3open", "2026-10-01T00:00:00Z", "<= 3.3.0", "")], stable, nov9)
check("on 3.x, no fix after 30 days still fires", [f.kind for f in r.findings], ["fired"])
check("and its title does not claim an ADR-0089 trigger", "ADR-0089" in title(r), False)
r = assess("3.3.0", [adv("GHSA-4only", "2026-11-01T00:00:00Z", "<= 3.3.0", "4.0.0")], stable, nov9)
check("on 3.x, a fix only in 4.x is no 3.x fix", [f.kind for f in r.findings], ["clock"])
# #1345 review: a fix on another line must not count as carried by the pin.
r = assess("3.3.0", [adv("GHSA-mixed", "2026-11-08T00:00:00Z", "<= 3.3.0", "2.5.318, 3.3.1")], stable, nov9)
check(
"a 2.x fix below a 3.x pin does not hide the advisory",
[(f.kind, f.detail) for f in r.findings],
[("bump", "fixed in 3.3.1")],
)
r = assess("3.3.0", [adv("GHSA-mixed2", "2026-11-08T00:00:00Z", "<= 3.3.0", "2.5.318")], stable, nov9)
check("and with only a 2.x fix listed, it runs the 3.x clock", [f.kind for f in r.findings], ["clock"])
r = assess("3.3.0", real, stable, nov9)
check("2.x's legacy open-ended ranges are not 3.x advisories", r.findings, [])
r = assess("2.5.316", [adv("GHSA-mixed3", "2026-11-08T00:00:00Z", "<= 2.5.316", "3.0.1, 2.5.317")], releases, now)
check(
"a 3.x fix above a 2.x pin is no reason to skip a 2.x bump",
[f.detail for f in r.findings],
["fixed in 2.5.317"],
)
text = COMPOSE.read_text() if COMPOSE.exists() else ""
check("the pin is read from stacks/wiki/compose.yaml", bool(PIN.search(text)), True)
print(f"{fail} failed" if fail else "all cases held")
return 1 if fail else 0
def main(argv: list[str]) -> int:
if "--self-test" in argv:
return self_test()
m = PIN.search(COMPOSE.read_text())
if not m:
sys.exit(f"{RED}error:{OFF} no ghcr.io/requarks/wiki:x.y.z@sha256 pin in {COMPOSE}")
now = dt.datetime.now(dt.UTC)
advisories, releases = fetch()
report = assess(m[1], advisories, releases, now)
body = render(report, now)
print(body)
if "--sync-issue" in argv:
sync(report, body, "--dry-run" in argv)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))