From b6ac712a27914fa1cfbdfbaf1c393e2040c1411a Mon Sep 17 00:00:00 2001 From: cskwork <76669236+cskwork@users.noreply.github.com> Date: Wed, 18 Nov 2026 08:19:42 +0900 Subject: [PATCH 1/3] fix(report): reject inconsistent report bundles Implement the integrity checks proposed in #108 without importing the unverified vendor source. Verify Markdown totals and headings and validate optional appendix scores against their CVSS vectors. Refs #108 --- .github/workflows/ci.yml | 2 + scripts/report_integrity_check.py | 322 +++++++++++++++++++++++++ scripts/test_report_integrity_check.py | 171 +++++++++++++ 3 files changed, 495 insertions(+) create mode 100755 scripts/report_integrity_check.py create mode 100644 scripts/test_report_integrity_check.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2bf921e..a3b986c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -221,6 +221,8 @@ jobs: run: | bash e2e/package-notices.sh python3 -m unittest discover -s e2e -p 'test_release_notices.py' -v + - name: Test Markdown report integrity checks + run: python3 -m unittest discover -s scripts -p 'test_report_integrity_check.py' -v - name: Test patched Norma SDK working-directory: third_party/norma run: go test ./... -count=1 diff --git a/scripts/report_integrity_check.py b/scripts/report_integrity_check.py new file mode 100755 index 00000000..9f1c7d37 --- /dev/null +++ b/scripts/report_integrity_check.py @@ -0,0 +1,322 @@ +#!/usr/bin/env python3 +"""Check Markdown finding IDs, bold totals, and an optional JSON CVSS appendix. + +Use a separate Markdown heading for each finding (for example, ## KDT-01). +Totals can use English or Indonesian labels such as "Total findings", +"Confirmed findings", "Total temuan", or "Jumlah temuan", or bold counts +such as **2 findings** or **2 temuan**. A report without IDs needs a zero total. +Only IDs passed to --merged are excluded. Matching heading titles produce +a warning so a reviewer can check for duplicate coverage. +""" + +import argparse +from collections import defaultdict +from decimal import Decimal, InvalidOperation +import json +import math +from pathlib import Path +import re + + +FLAGS = re.IGNORECASE +TOTAL_LABEL = r"(?:(?:total|confirmed)\s+findings?|(?:total|jumlah)\s+temuan)" +FINDING_NOUN = r"(?:(?:(?:total|unique|confirmed)\s+)?findings?|temuan(?:\s+unik)?)" +TOTAL_PATTERNS = ( + re.compile(rf"\*\*\s*{TOTAL_LABEL}\s*[:=]\s*([^*]+?)\s*\*\*", FLAGS), + re.compile(rf"\*\*\s*{TOTAL_LABEL}\s*:?\s*\*\*\s*(?:[:=|]\s*)?" + r"(?:\*\*\s*([^*]+?)\s*\*\*|([^\s|*]+))", FLAGS), + re.compile(rf"(?" if comment else "", + " **0 findings**", "\t**0 findings**"): + with self.subTest(markdown=markdown): + self.check(markdown, error="no active finding IDs or explicit zero finding total") + self.check("# Report\n\n**0 findings**", appendix=[]) + self.check("**0 temuan**\n" + FINDING, error="finding total 0") + + def test_headings_for_each_active_id(self): + self.check(FINDING + "\nSee also KDT-02.", error="KDT-02 needs exactly one heading, found 0") + self.check(FINDING + FINDING, error="KDT-01 needs exactly one heading, found 2") + self.check("## KDT-01 and KDT-02", error="distinct headings required") + self.check("KDT-01 — Access policy\n=======================\n") + self.check("See KDT-01.\n\n KDT-01 — Example\n---", error="found 0") + self.check("See KDT-01.\n\n```markdown\n" + FINDING + "```", error="found 0") + + def test_examples_and_comments_do_not_count_as_findings(self): + self.check( + "**1 finding**\n" + "\n" + "````markdown