Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

ci: preserve highest native risk across ZAP variants (#8200)

LearningCircuit4c0165d1c096
diff --git a/.github/scripts/release_native_reports.py b/.github/scripts/release_native_reports.py
index d749a09f9f..7b09f75d11 100644
--- a/.github/scripts/release_native_reports.py
+++ b/.github/scripts/release_native_reports.py
@@ -216,7 +216,6 @@ def zap_report(data: object, rules: Path = Path(".zap/rules.tsv")) -> dict:
if not isinstance(sites, list) or not sites:
raise ValueError("ZAP scanned no target")
actions = zap_actions(rules)
- records = []
metadata = {}
for site in sites:
if not isinstance(site, dict) or not isinstance(
@@ -233,23 +232,50 @@ def zap_report(data: object, rules: Path = Path(".zap/rules.tsv")) -> dict:
):
raise ValueError("Invalid ZAP finding")
action = actions.get(rule, "WARN")
+ reference = finding.get("alertRef", rule)
+ if not isinstance(reference, str) or not re.fullmatch(
+ re.escape(rule) + r"(?:-[0-9]+)?", reference
+ ):
+ raise ValueError("Invalid ZAP alert reference")
risk = ("info", "low", "medium", "high")[int(risk)]
- metadata["ZAP-" + rule] = {
- "native-risk": risk,
- "configured-action": action,
- }
- # A configured FAIL rule always enforces the release policy: its
- # native Low/Informational risk is raised to the blocking (medium)
- # threshold so it is aged, never left as a permanent advisory note.
- # WARN/IGNORE rules and unlisted defaults remain advisory.
- if action == "FAIL":
- severity = risk if risk == "high" else "medium"
- else:
- severity = "info"
- records.append(("ZAP-" + rule, severity, ".zap/rules.tsv"))
+ details = metadata.setdefault(
+ "ZAP-" + rule,
+ {
+ "native-risk": risk,
+ "configured-action": action,
+ "native-alert-refs": [],
+ },
+ )
+ # One plugin can report several variants across several sites.
+ # Its highest native risk must survive regardless of report order.
+ if float(SCORES[risk]) > float(SCORES[details["native-risk"]]):
+ details["native-risk"] = risk
+ if reference not in details["native-alert-refs"]:
+ details["native-alert-refs"].append(reference)
+
+ records = []
+ for rule_id, details in metadata.items():
+ details["native-alert-refs"].sort()
+ # A configured FAIL rule always enforces the release policy: its
+ # native Low/Informational risk is raised to the blocking (medium)
+ # threshold so it is aged, never left as a permanent advisory note.
+ # WARN/IGNORE rules and unlisted defaults remain advisory.
+ if details["configured-action"] == "FAIL":
+ severity = "high" if details["native-risk"] == "high" else "medium"
+ else:
+ severity = "info"
+ records.append((rule_id, severity, ".zap/rules.tsv"))
report = sarif("ZAP", records)
for rule in report["runs"][0]["tool"]["driver"]["rules"]:
- rule["properties"].update(metadata[rule["id"]])
+ details = metadata[rule["id"]]
+ rule["properties"].update(details)
+ rule["shortDescription"] = {
+ "text": (
+ f"ZAP plugin {rule['id'].removeprefix('ZAP-')}: "
+ f"native {details['native-risk']} "
+ f"(configured {details['configured-action']})"
+ )
+ }
return report
diff --git a/tests/ci/test_release_native_reports.py b/tests/ci/test_release_native_reports.py
index 59fe9d8a7f..8a66e08bd3 100644
--- a/tests/ci/test_release_native_reports.py
+++ b/tests/ci/test_release_native_reports.py
@@ -329,6 +329,102 @@ def test_zap_configured_fail_rules_block_at_any_native_risk(
)
[email protected]("action", ["FAIL", "WARN", "IGNORE"])
+ "risks", [("1", "0"), ("0", "1"), ("3", "1"), ("1", "3")]
+)
+def test_zap_aggregates_variants_and_sites_without_lowering_native_risk(
+ tmp_path, action, risks
+):
+ path = tmp_path / "rules.tsv"
+ path.write_text(f"100000\t{action}\tSynthetic rule\n", encoding="utf-8")
+ sites = [
+ {
+ "alerts": [
+ {
+ "pluginid": "100000",
+ "alertRef": f"100000-{risk}",
+ "riskcode": risk,
+ }
+ ]
+ }
+ for risk in risks
+ ]
+ report = reports.zap_report({"@version": "synthetic", "site": sites}, path)
+ assert report == reports.zap_report(
+ {"@version": "synthetic", "site": list(reversed(sites))}, path
+ )
+ run = report["runs"][0]
+ assert len(run["results"]) == len(run["tool"]["driver"]["rules"]) == 1
+ rule = run["tool"]["driver"]["rules"][0]
+ highest = "high" if "3" in risks else "low"
+ assert rule["id"] == "ZAP-100000"
+ assert rule["properties"]["native-risk"] == highest
+ assert rule["properties"]["configured-action"] == action
+ assert rule["properties"]["native-alert-refs"] == sorted(
+ f"100000-{risk}" for risk in risks
+ )
+ assert highest in rule["shortDescription"]["text"]
+ assert run["results"][0]["locations"][0]["physicalLocation"] == {
+ "artifactLocation": {"uri": ".zap/rules.tsv"},
+ "region": {"startLine": 1},
+ }
+ findings = native.report_findings(report, tmp_path)
+ assert native.policy_module().blocking_severity(findings[0]) is (
+ action == "FAIL"
+ )
+ expected_score = (
+ ("8.0" if highest == "high" else "5.0") if action == "FAIL" else "0.0"
+ )
+ assert rule["properties"]["security-severity"] == expected_score
+
+
+def test_zap_variant_metadata_does_not_copy_native_diagnostics(tmp_path):
+ path = tmp_path / "rules.tsv"
+ path.write_text("10055\tWARN\tSynthetic rule\n", encoding="utf-8")
+ marker = "synthetic-private-response"
+ finding = {
+ "pluginid": "10055",
+ "alertRef": "10055-1",
+ "riskcode": "2",
+ "alert": marker,
+ "desc": marker,
+ "instances": [{"uri": marker, "evidence": marker}],
+ }
+ report = reports.zap_report(
+ {"@version": "synthetic", "site": [{"alerts": [finding, finding]}]},
+ path,
+ )
+ assert marker not in json.dumps(report)
+ rule = report["runs"][0]["tool"]["driver"]["rules"][0]
+ assert rule["properties"]["native-alert-refs"] == ["10055-1"]
+ assert len(report["runs"][0]["results"]) == 1
+
+
[email protected]("reference", [None, 12, "99999-1", "10055-text"])
+def test_zap_rejects_unstructured_variant_references(tmp_path, reference):
+ path = tmp_path / "rules.tsv"
+ path.write_text("10055\tWARN\tSynthetic rule\n", encoding="utf-8")
+ with pytest.raises(ValueError, match="^Invalid ZAP alert reference$"):
+ reports.zap_report(
+ {
+ "@version": "synthetic",
+ "site": [
+ {
+ "alerts": [
+ {
+ "pluginid": "10055",
+ "alertRef": reference,
+ "riskcode": "2",
+ }
+ ]
+ }
+ ],
+ },
+ path,
+ )
+
+
@pytest.mark.parametrize(
"configuration", ["10001\tOTHER\n", "10001\tFAIL\n10001\tIGNORE\n"]
)