Skip to content

Commit 6df1bc4

Browse files
committed
docs(security): re-sync published copies to the round-4 hardened revision
Re-synced from security-scanner#1004: - scan.sh reports on partial scans (records scan_errors) instead of aborting before the merge; report.py fails the run at the end so it still goes red. - a due review_after stamps the entry to needs-review and surfaces once, rather than re-filing an issue and advisory every run; a partial issue/advisory failure is no longer recorded as reported. - shared RESOLVED_STATUSES / age threshold constants, unparsable review_after fails toward review, and sync_issues.py writes review_after on label-driven accepted-risk. Signed-off-by: Timur Tukaev <[email protected]>
1 parent cfd96ce commit 6df1bc4

5 files changed

Lines changed: 81 additions & 26 deletions

File tree

‎docs/security/pipeline/scripts/backfill_issues.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
"LOW": "security/low",
3636
}
3737

38-
UNFIXED_AGE_THRESHOLD_DAYS = 365
39-
4038

4139

4240

‎docs/security/pipeline/scripts/report.py‎

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os
1313
import re
1414
import subprocess
15+
import sys
1516
from datetime import datetime, timedelta, timezone
1617

1718
from statelib import (
@@ -21,6 +22,8 @@
2122
review_after_passed,
2223
override_review_due,
2324
age_drops,
25+
RESOLVED_STATUSES,
26+
UNFIXED_AGE_THRESHOLD_DAYS,
2427
)
2528

2629

@@ -31,8 +34,8 @@
3134
PENDING_FILE = os.path.join(STATE_DIR, "pending-weekly.json")
3235
TRIAGE_FILE = os.path.join(STATE_DIR, "triage-overrides.json")
3336

34-
# Statuses that mean "already handled, skip in new reports"
35-
RESOLVED_STATUSES = {"false-positive", "accepted-risk", "fixed"}
37+
# RESOLVED_STATUSES and UNFIXED_AGE_THRESHOLD_DAYS are imported from statelib so the
38+
# filter functions there and classify_filter here compare against one definition.
3639

3740
# Build/dev image patterns — CVEs in these are informational only
3841
DEV_IMAGE_PATTERNS = [
@@ -55,9 +58,6 @@
5558
"e2e/",
5659
]
5760

58-
# How old an unfixed CVE must be (days) before we auto-demote it
59-
UNFIXED_AGE_THRESHOLD_DAYS = 365
60-
6161
# Repository where issues are created (this repo)
6262
ISSUES_REPO = os.environ.get("ISSUES_REPO", "cozystack/security-scanner")
6363

@@ -169,9 +169,22 @@ def classify_filter(vuln, triage_overrides):
169169
# branch, which is what made the check unreachable before.
170170
entry = triage_overrides.get(cve_id)
171171
if entry and entry.get("status") in RESOLVED_STATUSES:
172-
if review_after_passed(entry):
173-
return False, None
174-
return True, f"triaged as {entry['status']}"
172+
if not review_after_passed(entry):
173+
return True, f"triaged as {entry['status']}"
174+
# Due for re-review. Stamp the entry in this same run so the condition does
175+
# not stay true forever: move it to the non-resolved `needs-review` status
176+
# and clear the date. Without this the finding re-files an issue and a draft
177+
# advisory on every six-hourly tick, because nothing else writes the date
178+
# back (sync_issues.py only rewrites on a status change). It surfaces ONCE
179+
# for a maintainer; next run its status is no longer resolved, so the
180+
# already-reported guard skips it until the re-triage lands.
181+
entry["status"] = "needs-review"
182+
entry["review_after"] = None
183+
entry["decided_by"] = "pipeline-auto"
184+
# A due override still must not resurrect a dev/build-only finding.
185+
if is_dev_only(vuln):
186+
return True, "dev/build dependency only"
187+
return False, None
175188

176189
# Dev/build-only image or test component
177190
if is_dev_only(vuln):
@@ -500,13 +513,16 @@ def process_critical(scan_results, reported, triage_overrides):
500513
issue_url = create_issue(vuln, report_path)
501514
ghsa_url = create_ghsa_draft(vuln)
502515

503-
# If both the issue and the advisory failed to create, do NOT record the
504-
# CVE as reported — otherwise the skip check passes over it forever, and a
505-
# CRITICAL is left with no issue, no advisory and no trace. Leave it out so
506-
# the next run retries it.
507-
if not issue_url and not ghsa_url:
508-
print(f" WARN: {cve_id} — both issue and advisory creation failed; "
509-
f"not recording as reported so the next run retries it")
516+
# If EITHER the issue or the advisory failed to create, do NOT record the
517+
# CVE as reported. A partial success (issue OK, advisory None, or the
518+
# reverse) is recorded with an empty URL and the skip check then passes over
519+
# it forever, so the missing half is never created and the CRITICAL has no
520+
# venue to be triaged in. Leave it out so the next run retries the missing
521+
# half.
522+
if not issue_url or not ghsa_url:
523+
print(f" WARN: {cve_id} — issue/advisory creation incomplete "
524+
f"(issue={'ok' if issue_url else 'FAILED'}, advisory={'ok' if ghsa_url else 'FAILED'}); "
525+
f"not recording as reported so the next run retries the missing half")
510526
continue
511527

512528
affected = vuln.get("affected_repos", [])
@@ -627,6 +643,15 @@ def main():
627643
with open(args.scan_results) as f:
628644
scan_results = json.load(f)
629645

646+
# scan.sh records how many targets it could not scan rather than aborting, so
647+
# the report is still produced from what succeeded. Surface it, and make the
648+
# run go red at the very end — after the reports and state are written — so an
649+
# incomplete run is visible without suppressing what was collected.
650+
scan_errors = scan_results.get("scan_errors", 0)
651+
if scan_errors:
652+
print(f"WARNING: scan was INCOMPLETE — {scan_errors} target(s) could not be "
653+
f"scanned; reports below cover only the targets that succeeded.")
654+
630655
triaged_count = len([v for v in triage_overrides.values() if v.get("status") in RESOLVED_STATUSES])
631656
print(f"Scan date: {scan_results.get('scan_date', 'unknown')}")
632657
print(f"Total CVEs in scan: {scan_results.get('total_vulnerabilities', 0)}")
@@ -649,6 +674,13 @@ def main():
649674
print(f"\nState saved. Reported: {len(reported)}, Pending: {len(pending)}, "
650675
f"Triage overrides: {len(triage_overrides)}")
651676

677+
# Now that the reports and state are written, fail the run if the scan was
678+
# incomplete, so it goes red without having suppressed what was collected.
679+
if scan_errors:
680+
print(f"\nFAILING: {scan_errors} scan target(s) could not be scanned — this "
681+
f"run's aggregate is incomplete.")
682+
sys.exit(1)
683+
652684

653685
if __name__ == "__main__":
654686
main()

‎docs/security/pipeline/scripts/scan.sh‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,15 @@ if [ -f "$IMAGES_FILE" ]; then
100100
fi
101101

102102
if [ "$SCAN_FAILURES" -gt 0 ]; then
103-
echo "ERROR: $SCAN_FAILURES scan target(s) failed — the aggregate is INCOMPLETE, not clean." >&2
104-
echo " Investigate the *.err files in $RESULTS_DIR before trusting this run." >&2
105-
exit 1
103+
# Do NOT abort here. On production data a fixed set of references is unscannable
104+
# by construction (Helm values parsed into names carrying no registry) and fails
105+
# every run; aborting before the merge would stop all CVE reporting for the whole
106+
# org, every scheduled run, until someone fixes them. Instead merge what
107+
# succeeded, record the failure count in scan-results.json, and let report.py
108+
# fail the run at the very end — so it still goes red without discarding the
109+
# aggregate (including the CRITICALs) that was collected.
110+
echo "WARNING: $SCAN_FAILURES scan target(s) failed — the aggregate will be marked INCOMPLETE." >&2
111+
echo " Investigate the *.err files in $RESULTS_DIR." >&2
106112
fi
107113

108114
# --- Phase 3: Merge all results into one file ---
@@ -146,6 +152,7 @@ for repo in discovery["repos"]:
146152
dev_only_images.add(pkg["image"])
147153
148154
all_vulns = {} # CVE-ID -> details
155+
scan_errors = 0 # targets that failed to scan (marker files), carried into the output
149156
150157
for filename in sorted(os.listdir(results_dir)):
151158
if not filename.endswith(".json"):
@@ -158,10 +165,10 @@ for filename in sorted(os.listdir(results_dir)):
158165
except (json.JSONDecodeError, FileNotFoundError):
159166
continue
160167
161-
# A failed scan writes {"__scan_error__": true, "Results": []}. The run aborts
162-
# before this stage when a target fails, so reaching here with the marker means
163-
# a stale error file from an earlier run; do not merge it as a clean target.
168+
# A failed scan writes {"__scan_error__": true, "Results": []}. Count it and do
169+
# NOT merge it as a clean target — a failed scan is not "zero findings".
164170
if data.get("__scan_error__"):
171+
scan_errors += 1
165172
print(f" WARN: skipping errored scan result {filename}", file=sys.stderr)
166173
continue
167174
@@ -249,6 +256,7 @@ vulns_list = sorted(all_vulns.values(), key=lambda v: (sev_order.get(v["severity
249256
output = {
250257
"scan_date": __import__("datetime").datetime.utcnow().isoformat() + "Z",
251258
"total_vulnerabilities": len(vulns_list),
259+
"scan_errors": scan_errors,
252260
"by_severity": {},
253261
"vulnerabilities": vulns_list,
254262
}
@@ -264,6 +272,8 @@ for sev in ["CRITICAL", "HIGH", "MEDIUM", "LOW"]:
264272
count = output["by_severity"].get(sev, 0)
265273
if count:
266274
print(f" {sev}: {count}")
275+
if scan_errors:
276+
print(f"INCOMPLETE: {scan_errors} target(s) failed to scan (recorded as scan_errors)")
267277
PYEOF
268278

269279
echo "==> Scan complete: $OUTFILE"

‎docs/security/pipeline/scripts/statelib.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import json
1414
import os
1515
import re
16+
import sys
1617
import tempfile
1718
from datetime import datetime, timezone
1819

@@ -88,7 +89,12 @@ def review_after_passed(entry):
8889
try:
8990
due = datetime.fromisoformat(str(raw).replace("Z", "+00:00"))
9091
except ValueError:
91-
return False
92+
# review_after is hand-edited by maintainers, so "2026-13-01" is ordinary
93+
# input. Fail toward review: surface the finding rather than letting a
94+
# typo turn a time-boxed acceptance into a silent permanent one.
95+
print(f"WARNING: unparsable review_after {raw!r} on a triage override — "
96+
f"treating as due so the finding surfaces for review", file=sys.stderr)
97+
return True
9298
if due.tzinfo is None:
9399
due = due.replace(tzinfo=timezone.utc)
94100
return datetime.now(timezone.utc) >= due

‎docs/security/pipeline/scripts/sync_issues.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import os
1313
import re
1414
import subprocess
15-
from datetime import datetime, timezone
15+
from datetime import datetime, timedelta, timezone
1616

1717
from statelib import load_json, save_json
1818

@@ -122,14 +122,23 @@ def main():
122122
assignees = [a["login"] for a in issue.get("assignees", [])]
123123
decided_by = assignees[0] if assignees else "unknown"
124124

125-
triage[cve_id] = {
125+
entry = {
126126
"status": status,
127127
"reason": f"Triaged via issue #{issue['number']}",
128128
"decided_by": decided_by,
129129
"decided_at": datetime.now(timezone.utc).strftime("%Y-%m-%d"),
130130
"issue_number": issue["number"],
131131
"issue_url": f"https://github.com/{ISSUES_REPO}/issues/{issue['number']}",
132132
}
133+
# accepted-risk carries a 90-day re-review: without a review_after date the
134+
# label-driven acceptance (the main triage channel) would be permanent, the
135+
# same gap report.py's age filter now avoids. false-positive is terminal and
136+
# gets none.
137+
if status == "accepted-risk":
138+
entry["review_after"] = (
139+
datetime.now(timezone.utc) + timedelta(days=90)
140+
).strftime("%Y-%m-%d")
141+
triage[cve_id] = entry
133142
updated += 1
134143
print(f" {cve_id}: {status} (issue #{issue['number']}, by {decided_by})")
135144

0 commit comments

Comments
 (0)