~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
ci: give noncritical release findings a 14-day grace period (#8141)
LearningCircuit8013a9b0bf8e
diff --git a/.github/SECURITY_ALERTS.md b/.github/SECURITY_ALERTS.mdindex 9d13e6cdfa..eb89a6dcc3 100644--- a/.github/SECURITY_ALERTS.md+++ b/.github/SECURITY_ALERTS.md@@ -4,151 +4,174 @@ This document explains the security scanning alerts that have been assessedand determined to be false positives, intentionally suppressed, or temporarilyaccepted for release.-## Temporary release exceptions--The release gate's alert checks block on every open critical, high, or medium-code scanning alert, whichever tool raised it. For a finding that only these-alert checks block, **the preferred temporary approach while waiting for an-upstream fix is a narrowly scoped, expiring release exception**, provided-reviewers accept the documented risk for that specific alert. Record it in-[release-security-exceptions.json](release-security-exceptions.json), then review-and merge the policy change through a PR before using it for a release. This-accepts the risk temporarily; it does not fix the vulnerability or automatically-authorize exceptions for other alerts.--Exactly two steps read the policy, both in the `Check Code Scanning Alerts` job-of `release-gate.yml`: `Validate fresh analyses and open alerts`-(`check_release_scan_evidence.py`) and `Check open alerts and reviewed-exceptions` (`check_code_scanning_alerts.py`). `Release Gate Summary` still-requires every other gate job to succeed, and the Trivy scans during Docker-publication do not read the policy. An exception therefore cannot unblock a-scanner job that fails on its own findings; see-[Scanners that fail on findings](#scanners-that-fail-on-findings).--Keep scanners running and the finding visible while the exception is active.-For a finding that only the alert checks block, use this reviewed policy for-the waiting period instead of dismissing a valid alert, suppressing the finding-in the scanner's configuration, bypassing the release gate, or carrying a local-dependency backport solely to unblock a release. If reviewers cannot accept the-risk, the alert continues to block. Once a verified upstream fix is available,-deploy it, rebuild and scan, and remove the exception. Any extension requires a-fresh review of the risk and expiry.--Each entry must identify an exact alert number, rule ID, tool, scan category,-file path, and severity, together with a rationale, tracking link, and expiry.-The repository must also match. There are no wildcard matches: a new alert or-severity increase still blocks. The checker rejects missing or malformed policy-files and API responses, and queries all pages before deciding whether to pass.-An empty `exceptions` list restores the normal policy without exceptions.-The final check, which reads the default branch's open alerts, does not block-low or unscored alerts. The fresh-evidence check additionally blocks unscored-error/warning findings on the release ref. An invalid supplied severity fails-the gate.--`expires_on` is an exclusive UTC date: an entry with `2026-10-13` stops applying-at **00:00 UTC on October 13, 2026**. An expired entry with an open matching alert-blocks release again. An entry for an alert that is no longer open (fixed,-closed or dismissed) grants nothing: it is dormant, kept only as an expiring-audit record, and should be removed at expiry. Extensions require another-reviewed policy change.--The gate retains the earliest **applied** expiry from both the fresh-evidence-check on the release ref and the later default-branch alert check, even if an-alert is absent from the later response. It carries that expiry through Docker-publication and GitHub Release creation. The successful release build records it in an-immutable `release-security-decision-<attempt>` artifact, bound to the repository,-release commit, workflow run, and build attempt. PyPI dispatches carry the-artifact ID. The verifier checks GitHub's artifact/run metadata, main ancestry,-the successful build and upload time, and the archive digest before reading its-deadline. A caller-supplied `release_deadline` is never used. Missing, expired,-tampered, or unrelated artifacts fail closed. A partial rerun that carries over-the original successful build keeps its artifact ID, even when the parent run's-attempt changes. Once a rerun runs the build again, the publisher accepts only-the decision that new build records.--Each publication checks the original deadline after environment approval,-including publish-job reruns. The explicit value `none` is recorded only when-no exception applied. Expired decisions require a fix or a reviewed policy-update and a new release run; editing `main` does not renew an old decision.-The decision artifact is retained for 30 days, without extending its deadline.-Native Docker builds load their images locally; a separate push step checks-expiry again after the build. Signed SLSA provenance and per-platform SBOM-attestations are still added by `create-manifest`; BuildKit's additional inline-provenance is disabled for compatibility with the local Docker image store.-An upload already started or an artifact already published is not rolled back.--The policy and gate come from the triggering release commit. The build must-prove that commit is an ancestor of `main`; PyPI verifies its dispatched SHA-against `main` too. PyPI loads its decision verifier from the default-branch-commit that supplies the publishing workflow. The `release` environment restricts-deployments to `main`-and `v*` tags and requires reviewer approval (verified September 27, 2026).-Keep those environment restrictions in place: a branch-only gate run is for-validation and does not authorize publication.--The exception applies only to those two alert checks. Scanners still run,-failing scanner jobs still block, SARIF uploads are unchanged, and the alert-stays open in GitHub Security. The job summary lists open, excepted, and-blocking counts, plus each applied exception's reason and expiry. The overall-release summary explicitly reports when it passes with exceptions. Publishing-still uses the existing release approvals; the checker has no permission to-dismiss alerts. API failures report a bounded, workflow-command-escaped error-body for diagnosis.--Before reading alerts, the gate polls every 15 seconds until every required-analysis category has a fresh successful analysis, for at most 300 seconds in-total. Evidence must match the release commit, ref, workflow and job, and be no-older than the workflow run. Missing, failed or unverifiable analyses block-release. The exception policy cannot replace this fresh evidence. Hosted-release qualification is tracked in-[issue #4823](https://github.com/LearningCircuit/local-deep-research/issues/4823).--### Scanners that fail on findings--The jobs below fail on their own findings, not only through code scanning-alerts, so a release exception cannot unblock them. Each keeps its own-suppression. Change one only through a reviewed PR that records the reason and-a tracking link beside the entry, and remove the entry once the fix ships.--- **OSV-Scanner** (`osv-scan`): any vulnerability in a completed scan fails the- job in the release gate, the weekly schedule and pushes. On pull requests and- in the merge queue only a vulnerability the change introduces fails it; one- already on the base branch is reported as a warning and still uploaded.- Findings are compared by advisory, lockfile and package name, not version:- moving an already-vulnerable package to another vulnerable version does not- fail, while the same advisory in a new package does. Add an- `[[IgnoredVulns]]` entry with `id`, `ignoreUntil`, and `reason`- to the `osv-scanner.toml` in the affected lockfile's directory. `ignoreUntil`- is a native expiry: afterwards the finding fails the scan again. The two v2- release entries in [osv-scanner.toml](../osv-scanner.toml)- (`GHSA-4mvj-m6j5-pmf7` and `GHSA-v5mq-3xhg-98m9`,- `ignoreUntil = 2026-12-19`) are the model.-- **Trivy during Docker publication**: the `Security Scan` job in- `prerelease-docker.yml` and the digest rescan in `docker-publish.yml` fail on- fixable critical or high image findings, after release approval. Both read- [.trivyignore](../.trivyignore), not the exception policy, so an exception- for such a `container-security` alert passes the gate but not publication.- Add the ID with Trivy's native `exp:YYYY-MM-DD` expiry and a comment like the- existing entries. The gate's `container-security` scan reads the same file,- so it stops reporting the finding too. Medium findings only raise- `container-security` alerts, which an exception can cover.-- **npm audit** (`npm-audit`): a moderate or higher advisory fails the job- unless its GHSA ID is in `AUDIT_ALLOWLIST`, the environment variable that+## Release finding policy++Critical code-scanning findings and detected secrets block releases immediately.+Secrets are never aged: Gitleaks fails on any detection, and Trivy image scans+run a separate secret-only check that fails on medium, high or critical secret+rules (low-rated pattern matches stay advisory).+Other blocking findings, including high, medium and unscored SARIF errors or+warnings, receive **14 days from their first detection in this repository**.+Low and informational findings remain advisory. This window does not suppress,+dismiss or close a finding; maintainers should still triage and fix it.++The clock uses GitHub's original `created_at`, never an advisory publication+date, a rescan date or `updated_at`. Fixed and dismissed history is consulted+before granting time. The same scanner/advisory retains its earliest repository+detection even across changed image paths or reopening; other rules retain their+scanner, rule and source identity. Missing, malformed, future or unverifiable+dates cannot grant a grace period. A finding blocks at exactly first detection+plus 14 days, with UTC timestamp precision. Reruns do not renew this deadline.++Build failures, failing security tests, scanner execution errors, incomplete+reports and missing or failed processed analyses continue to block immediately.+The gate requires fresh analyses matching the release commit, ref, workflow and+job; a successful upload alone is insufficient. It waits at most 300 seconds+for the configured analysis categories. Native report checks also verify the+exact upload receipt. Missing history or an API failure fails closed. Diagnostics+do not echo native API response bodies.++### Native scanners and publication++Release calls to OSV, npm audit, Retire.js, Hadolint, Checkov and ZAP use the same+age policy instead of failing solely on every new noncritical finding. Their+normal pull-request and standalone behavior remains unchanged. OSV's+pull-request baseline comparison remains separate from the release policy.+The exact installed Python distributions are still inventoried and scanned;+their complete SARIF reports are uploaded and required by the final gate for+every package/Python matrix leg. Gitleaks remains immediately blocking.++npm audit and ZAP publish minimal SARIF so the repository retains detection+history. ZAP SARIF contains rule identities, without HTTP samples, URLs or+request/response bodies. ZAP rules configured as `FAIL` in `.zap/rules.tsv`+always enforce the age policy: a native High risk stays high, and a native+Medium, Low or Informational risk is raised to medium, so the finding blocks at+first detection plus 14 days instead of becoming advisory. ZAP's configured+`WARN` and `IGNORE` rules, and its default warnings, stay visible as advisory+notes. The native risk remains report metadata. Those upload jobs receive scoped `security-events:+write` permission. No repository protection, review requirement or release+approval is changed.++Trivy scans of prerelease images and immutable promotion digests also apply+the age policy before final tag publication. Critical native image findings,+detected image secrets, scanner failures and failed analyses still block+immediately. Their SARIF covers every severity of fixable findings, so high+and medium image findings, including medium ones that never blocked+publication before, block once 14 days have passed since first detection; low+findings stay advisory.+These scans run after the release gate and are aged in their own job against+the exact upload. Their `trivy-prerelease` and `trivy-promotion`+categories are therefore excluded from both gate alert checks. Each check reads+an alert's instances on the ref its alert list represents: the release ref for+the fresh-evidence check and the default branch for the final check. Instances+on other refs, such as tags or rehearsal branches, are ignored. An alert whose+open instances on that ref are all in those two categories cannot block the+gate, because only a later publication could refresh or close it. An instance+counts as closed only when its state is `fixed` or `dismissed`. Excluded alerts+still back-date the same finding in the remaining alerts, and an alert that is+also open on that ref in a gate-time category, such as `container-security`,+still blocks. Existing scanner-specific+reviewed suppressions are retained; this policy adds no suppression entries.++### Scanner-native suppressions++A release exception (below) is read only by the two alert checks. It cannot+unblock a native release scan, a Docker publication scan or a scanner job that+fails on its own findings. Each scanner keeps its own suppression mechanism.+Change one only through a reviewed PR that records the reason and a tracking+link beside the entry, and remove the entry once the fix ships. A suppressed+finding disappears from the native report, so prefer the age window or a+release exception whenever they are sufficient.++- **OSV-Scanner** (`osv-scan` and the installed-dependency audits): add an+ `[[IgnoredVulns]]` entry with `id`, `ignoreUntil` and `reason` to the+ `osv-scanner.toml` in the affected lockfile's directory. The installed+ distribution audits copy the root [osv-scanner.toml](../osv-scanner.toml).+ `ignoreUntil` is a native expiry; afterwards the finding is reported again+ and its original detection date decides whether it blocks. Pull requests and+ the merge queue still fail only on vulnerabilities the change introduces+ (compared by advisory, lockfile and package name); scheduled scans keep+ strict native exits.+- **Trivy** (`container-security` in the gate, plus the `Security Scan` job in+ `prerelease-docker.yml` and the digest rescan in `docker-publish.yml`): all+ read [.trivyignore](../.trivyignore), not the exception policy. Add the ID+ with Trivy's native `exp:YYYY-MM-DD` expiry and a comment like the existing+ entries. Every Trivy scan reads the same file, including the immediate+ critical and secret checks, so new scans stop reporting the finding. Alerts+ already open in the post-gate `trivy-prerelease` or `trivy-promotion`+ categories stay open until the next publication uploads to that category;+ the release gate does not block on them (see+ [Native scanners and publication](#native-scanners-and-publication) above).+- **npm audit** (`npm-audit`): standalone runs fail on a moderate or higher+ advisory unless its GHSA ID is in `AUDIT_ALLOWLIST`, the environment variable`.github/scripts/npm_audit_allowlist.py` reads. The allowlist is only for- advisories with no available fix in dev or test-only tooling. It has no- expiry: remove the ID in a follow-up PR.-- **Retire.js** (`retirejs-scan`): a medium or higher finding fails release- runs. No Retire.js ignore file is checked in; update or replace the library.-- **Gitleaks** (`gitleaks-scan`): any detected secret fails the job. Rotate a- real secret. Record a reviewed false positive as a rule-scoped allowlist in- `.gitleaks.toml` or a fingerprint in `.gitleaksignore`; neither expires.--Any other gate job that fails blocks the release the same way. Hadolint,-Checkov, and the ZAP baseline, for example, fail on findings in this-repository's own Dockerfile, compose files, workflows, or running app. One-finding can also block through several scanners: a Python dependency-vulnerability can fail OSV-Scanner and raise Grype or Trivy alerts as well.-Cover every path that blocks.+ advisories with no available fix in dev or test-only tooling and has no+ expiry; remove the ID in a follow-up PR. Release runs do not read it: they+ report every advisory and apply the age policy.+- **Retire.js** (`retirejs-scan`): no ignore file is checked in; update or+ replace the library.+- **Gitleaks** (`gitleaks-scan`): any detected secret fails the job+ immediately. Rotate a real secret. Record a reviewed false positive as a+ rule-scoped allowlist in `.gitleaks.toml` or a fingerprint in+ `.gitleaksignore`; neither expires.++One finding can block through several scanners: a Python dependency+vulnerability can appear in OSV-Scanner, the installed-dependency audits, Grype+and Trivy. Its earliest detection in each scanner's history applies; cover+every path that blocks.++### Publication deadlines++Every applied grace period contributes its exact expiry to the release decision.+The earliest expiry survives later queries even if the finding disappears.+Reviewed exception dates also contribute their exclusive UTC expiry. The explicit+value `none` is recorded only when no time-limited decision applies; missing or+malformed outputs never mean unlimited time.++The successful release build records the deadline in an immutable+`release-security-decision-<attempt>` artifact, bound to the repository, release+commit, workflow run and build attempt. PyPI receives the artifact ID, verifies+its trusted run/build metadata and archive digest, and reads that deadline.+A caller-supplied deadline cannot replace it. Partial reruns retain the decision+of the original successful build. Rebuilding creates a new bound decision.+Artifact retention does not extend its expiry.++Publication checks the deadline after environment approval and immediately+before publishing, including publish-job reruns. Docker publication combines+the original gate deadline with later image-scan deadlines, always taking the+earliest, and carries it into GitHub Release creation. Python package publishing+uses its authenticated source-gate decision. Approval delays do not extend the+applicable window. An expired decision requires+remediation or a reviewed policy change and a new release run. Already published+artifacts are not rolled back.++The gate and policy come from the triggering release commit. That commit must+be an ancestor of `main`; PyPI also verifies its dispatched SHA against `main`.+The existing `release` environment approval and deployment restrictions remain+in force. A branch-only validation run does not authorize publication.++### Temporary release exceptions++A reviewed exception may extend a specific **noncritical** alert's deadline when+maintainers accept its risk. Record the exact alert number, rule, tool, category,+path and severity in+[release-security-exceptions.json](release-security-exceptions.json), with a+rationale, tracking link and exclusive UTC `expires_on` date. There are no+wildcards. Critical findings cannot use an exception. Any extension requires+a reviewed policy PR; it does not automatically apply to another finding.++Both alert checks read this policy. Native report checks do not use it, so an+exception alone cannot unblock their findings. Scanners and their operational+checks still run. The job summaries list graced, excepted and blocking findings+with their deadlines. The checker uses only GET requests and never dismisses+alerts. Once a verified fix is available, deploy it, rebuild and scan, then+remove the exception.++An expired exception matching an open alert blocks again and cannot fall back+to a fresh automatic grace period. An entry for a fixed or dismissed alert is+a dormant audit record and grants no time. An empty exception list retains the+normal age policy. Hosted release qualification is tracked in+[issue #4823](https://github.com/LearningCircuit/local-deep-research/issues/4823).### Current exception policy@@ -167,7 +190,7 @@ policy change.GHSA-v5mq-3xhg-98m9 / CVE-2026-104250 (unstructured) is alsosuppressed in the scanner configuration. This is an exception to the ruleabove about keeping the finding visible. Every fixed release currently-requires Python <3.14, while the production image uses Python 3.14.9.+requires Python <3.14, while the production image uses Python 3.14.The existing loader regression contract remains in`tests/security/test_unstructured_html_output_tripwire.py` and must beretained while these entries are present.@@ -187,7 +210,8 @@ the normal gate policy.Trivy drops expired ignore lines without failing the scan solely becausean entry expired. The existing `osv-scanner.toml` `ignoreUntil = 2026-12-19`is the enforced review date for this advisory: once it expires, a completed-release scan fails if the finding remains.+release scanner reports the finding again; its original age then determines+whether the release gate blocks.CVE-2026-12345 (CPython) is suppressed in `.grype.yaml` only, as ascanner-metadata false positive rather than an accepted risk. The issuediff --git a/.github/release-scan-policy.json b/.github/release-scan-policy.jsonindex 54fb1c7dcd..e5f764ca2f 100644--- a/.github/release-scan-policy.json+++ b/.github/release-scan-policy.json@@ -15,5 +15,13 @@"checkov-workflows": "checkov","retirejs": "retirejs","zizmor": "zizmor-scan",- "gitleaks-release": "gitleaks-scan"+ "gitleaks-release": "gitleaks-scan",+ "npm-audit-release": "npm-audit",+ "zap-baseline-release": "zap-baseline-scan",+ "zap-api-release": "zap-api-scan",+ "installed-python-3.12-wheel": "pip-install-check",+ "installed-python-3.12-wheel-mcp": "pip-install-check",+ "installed-python-3.13-wheel": "package-install-matrix",+ "installed-python-3.14-wheel": "package-install-matrix",+ "installed-python-3.12-sdist": "package-install-matrix"}diff --git a/.github/scripts/audit_installed_dependencies.py b/.github/scripts/audit_installed_dependencies.pyindex 005dc03c01..ed0263afcc 100644--- a/.github/scripts/audit_installed_dependencies.py+++ b/.github/scripts/audit_installed_dependencies.py@@ -80,16 +80,22 @@ def inventory(python, expected_version):}-def scan(scanner, output):+def scan(scanner, output, *, release_policy=False):# Reuse the repository's native exit-status, diagnostic and report policy.path = Path(__file__).with_name("run_osv_scan.py")spec = importlib.util.spec_from_file_location("installed_osv_policy", path)policy = importlib.util.module_from_spec(spec)spec.loader.exec_module(policy)- return policy.scan(scanner, output, output / "results.sarif", resolve=False)+ return policy.scan(+ scanner,+ output,+ output / "results.sarif",+ resolve=False,+ release_policy=release_policy,+ )-def audit(python, scanner, manifest, policy, output):+def audit(python, scanner, manifest, policy, output, *, release_policy=False):expected_version = json.loads(manifest.read_text(encoding="utf-8"))["version"]@@ -113,7 +119,7 @@ def audit(python, scanner, manifest, policy, output):# Native OSV discovers this policy beside the generated requirements.# Keep the existing narrow, expiring exceptions; add none automatically.shutil.copyfile(policy, output / "osv-scanner.toml")- status = scan(scanner, output)+ status = scan(scanner, output, release_policy=release_policy)print(f"Audited {len(data['packages'])} installed distributions "f"on Python {data['python_version']} (scanner status {status})"@@ -128,10 +134,16 @@ def main():parser.add_argument("--manifest", required=True, type=Path)parser.add_argument("--policy", required=True, type=Path)parser.add_argument("--output", required=True, type=Path)+ parser.add_argument("--release-policy", action="store_true")args = parser.parse_args()try:return audit(- args.python, args.scanner, args.manifest, args.policy, args.output+ args.python,+ args.scanner,+ args.manifest,+ args.policy,+ args.output,+ release_policy=args.release_policy,)except (OSError,diff --git a/.github/scripts/check_code_scanning_alerts.py b/.github/scripts/check_code_scanning_alerts.pyindex 671fb877eb..c4ea75dbea 100644--- a/.github/scripts/check_code_scanning_alerts.py+++ b/.github/scripts/check_code_scanning_alerts.py@@ -1,27 +1,34 @@#!/usr/bin/env python3"""Enforce the release alert gate without closing temporarily excepted alerts.-Only GET requests are made. A reviewed, expiring policy can exempt an exact-alert from this check and the fresh-evidence check; scanner results and GitHub-alert state stay intact. It cannot unblock a scanner job that fails on its own-findings. Deploy the verified fix and remove the exception once available; see-.github/SECURITY_ALERTS.md for the policy.+Only GET requests are made. Noncritical blocking findings receive fourteen+days from their original repository detection; critical findings block+immediately. Reviewed exceptions can extend a specific noncritical finding's+deadline. Scanner results and GitHub alert state stay intact. See+.github/SECURITY_ALERTS.md for the complete policy."""from __future__ import annotationsimport argparsefrom collections import Counter-from datetime import date, datetime, timezone+from datetime import date, datetime, timedelta, timezoneimport htmlimport jsonimport osfrom pathlib import Pathimport reimport subprocess+from urllib.parse import unquote, urlencodeSEVERITIES = ("critical", "high", "medium")+# Docker publication runs after the release gate and ages its own Trivy uploads+# against the exact upload receipt. Alerts open only in these categories can be+# refreshed or closed only by a later publication, so the gate must not block+# on them; otherwise a stale post-gate alert could stop every later release.+POST_GATE_CATEGORIES = frozenset({"trivy-prerelease", "trivy-promotion"})+GRACE_PERIOD = timedelta(days=14)POLICY_PATH = (Path(__file__).resolve().parents[1] / "release-security-exceptions.json")@@ -77,7 +84,9 @@ def load_exceptions(path: Path, repository: str) -> dict[int, dict]:return exceptions-def validate_alerts(alerts: object) -> None:+def validate_alerts(+ alerts: object, states: tuple[str, ...] = ("open",)+) -> None:if not isinstance(alerts, list):raise ValueError("Code scanning API response must be a JSON array")for alert in alerts:@@ -85,7 +94,7 @@ def validate_alerts(alerts: object) -> None:not isinstance(alert, dict)or type(alert.get("number")) is not intor alert["number"] <= 0- or alert.get("state") != "open"+ or alert.get("state") not in statesor not isinstance(alert.get("rule"), dict)or not isinstance(alert["rule"].get("id"), str)or alert["rule"].get("security_severity_level")@@ -94,11 +103,21 @@ def validate_alerts(alerts: object) -> None:raise ValueError("Malformed open code scanning alert")-def fetch_alerts(repository: str) -> list[dict]:+def fetch_alerts(+ repository: str,+ state: str = "open",+ ref: str | None = None,+ tool_name: str | None = None,+) -> list[dict]:alerts = []page = 1while True:# Explicit GET and argv (no shell): this gate cannot dismiss alerts.+ query = {"state": state, "per_page": 100, "page": page}+ if ref:+ query["ref"] = ref+ if tool_name:+ query["tool_name"] = tool_nameresult = subprocess.run(["gh",@@ -109,8 +128,7 @@ def fetch_alerts(repository: str) -> list[dict]:"Accept: application/vnd.github+json","-H","X-GitHub-Api-Version: 2022-11-28",- f"/repos/{repository}/code-scanning/alerts"- f"?state=open&per_page=100&page={page}",+ f"/repos/{repository}/code-scanning/alerts?{urlencode(query)}",],check=True,capture_output=True,@@ -118,13 +136,203 @@ def fetch_alerts(repository: str) -> list[dict]:timeout=60,)batch = json.loads(result.stdout)- validate_alerts(batch)+ validate_alerts(batch, (state,))if not batch:return alertsalerts.extend(batch)page += 1+def fetch_instances(+ repository: str, number: int, ref: str | None = None+) -> list[dict]:+ instances = []+ page = 1+ while True:+ query = {"per_page": 100, "page": page}+ if ref:+ query["ref"] = ref+ result = subprocess.run(+ [+ "gh",+ "api",+ "--method",+ "GET",+ "-H",+ "Accept: application/vnd.github+json",+ "-H",+ "X-GitHub-Api-Version: 2022-11-28",+ f"/repos/{repository}/code-scanning/alerts/{int(number)}"+ f"/instances?{urlencode(query)}",+ ],+ check=True,+ capture_output=True,+ text=True,+ timeout=60,+ )+ batch = json.loads(result.stdout)+ if not isinstance(batch, list) or any(+ not isinstance(row, dict) for row in batch+ ):+ raise ValueError("Malformed code scanning alert instances")+ if not batch:+ return instances+ # Rows for another ref (tags, rehearsal branches) say nothing about+ # the ref this alert list represents.+ instances.extend(+ row for row in batch if ref is None or row.get("ref") in (None, ref)+ )+ page += 1+++def default_branch_ref(repository: str) -> str:+ """The ref that an alert list fetched without `ref` represents."""+ branch = None+ if event := os.environ.get("GITHUB_EVENT_PATH"):+ try:+ payload = json.loads(Path(event).read_text(encoding="utf-8"))+ branch = payload["repository"]["default_branch"]+ except (OSError, ValueError, KeyError, TypeError):+ branch = None+ if not branch:+ result = subprocess.run(+ [+ "gh",+ "api",+ "--method",+ "GET",+ "-H",+ "Accept: application/vnd.github+json",+ "-H",+ "X-GitHub-Api-Version: 2022-11-28",+ f"/repos/{repository}",+ ],+ check=True,+ capture_output=True,+ text=True,+ timeout=60,+ )+ data = json.loads(result.stdout)+ branch = data.get("default_branch") if isinstance(data, dict) else None+ if (+ not isinstance(branch, str)+ or not re.fullmatch(r"[\w./-]+", branch)+ or ".." in branch+ ):+ raise ValueError("Invalid default branch")+ return f"refs/heads/{branch}"+++def _category(value: object) -> object:+ return value.rstrip("/") if isinstance(value, str) else value+++def post_gate_only(alert: dict, instances) -> bool:+ """True only when every open instance is in a post-gate category.++ ``instances(number)`` returns the alert's instances on the queried ref.+ Alerts whose most recent instance is an open gate-time category never+ need the lookup. Anything unprovable stays in the gate's blocking set.+ """+ latest = alert.get("most_recent_instance")+ if not isinstance(latest, dict) or (+ _category(latest.get("category")) not in POST_GATE_CATEGORIES+ and latest.get("state", "open") == "open"+ ):+ return False+ rows = instances(alert["number"])+ if not isinstance(rows, list) or any(+ not isinstance(row, dict) for row in rows+ ):+ raise ValueError("Malformed code scanning alert instances")+ # Only an explicit closed state proves an instance closed; a missing or+ # unrecognized state stays in the blocking set.+ open_rows = [+ row for row in rows if row.get("state") not in {"fixed", "dismissed"}+ ]+ return bool(open_rows) and all(+ _category(row.get("category")) in POST_GATE_CATEGORIES+ for row in open_rows+ )+++def gate_alerts(alerts: list[dict], instances) -> list[dict]:+ """Drop alerts that only post-gate Docker publication scans keep open."""+ return [alert for alert in alerts if not post_gate_only(alert, instances)]+++def finding_key(alert: dict) -> tuple:+ """Keep vulnerability clocks across image paths and ordinary rescans."""+ rule = alert["rule"]["id"]+ tool = (alert.get("tool") or {}).get("name")+ if (+ not isinstance(tool, str)+ or not tool+ or not isinstance(rule, str)+ or not rule+ ):+ raise ValueError("Finding has no valid scanner or rule identity")+ tool = tool.casefold()+ vulnerability = re.search(+ r"(?:CVE-\d{4}-\d+|GHSA-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4})",+ rule,+ re.I,+ )+ if vulnerability:+ return tool, vulnerability.group().casefold()+ location = (alert.get("most_recent_instance") or {}).get("location") or {}+ path = location.get("path")+ line = location.get("start_line", 1)+ if (+ not isinstance(path, str)+ or not path+ or type(line) is not int+ or line < 1+ ):+ raise ValueError("Finding has no valid source identity")+ path = unquote(path).replace("\\", "/")+ return tool, rule, path, line+++def retain_first_detection(+ alerts: list[dict], history: list[dict]+) -> list[dict]:+ """Never renew an existing finding's grace after a fix/reopen or re-upload."""+ earliest = {}+ # Open advisory alerts are detections too: they back-date a finding whose+ # severity later rises, consistently with the native report history.+ records = [(alert, not blocking_severity(alert)) for alert in alerts]+ for record, advisory in [*records, *((row, False) for row in history)]:+ try:+ key = finding_key(record)+ except (AttributeError, TypeError, ValueError):+ # An advisory alert without a usable identity cannot back-date+ # anything; a blocking alert without one still fails closed.+ if advisory:+ continue+ raise+ value = record.get("created_at")+ try:+ instant = datetime.fromisoformat(value.replace("Z", "+00:00"))+ except (AttributeError, TypeError, ValueError):+ # An unprovable historical age cannot grant more time.+ earliest[key] = None+ continue+ if instant.tzinfo is None:+ earliest[key] = None+ continue+ if key not in earliest or (+ earliest[key] is not None and instant < earliest[key]+ ):+ earliest[key] = instant+ return [+ {**alert, "first_detected_at": earliest[finding_key(alert)]}+ if blocking_severity(alert)+ else dict(alert)+ for alert in alerts+ ]++def matches_exception(alert: dict, entry: dict) -> bool:instance = alert.get("most_recent_instance") or {}tool = alert.get("tool") or {}@@ -143,6 +351,63 @@ def matches_exception(alert: dict, entry: dict) -> bool:)+def blocking_severity(alert: dict) -> bool:+ """Keep scored lows and native SARIF notes advisory."""+ security = alert["rule"].get("security_severity_level")+ if security in SEVERITIES:+ return True+ if security == "low":+ return False+ if security is not None:+ raise ValueError("Unknown security severity")+ level = alert["rule"].get("severity")+ if level not in {"error", "warning", "note", "none"}:+ raise ValueError("No recognized SARIF severity")+ return level in {"error", "warning"}+++def grace_deadline(alert: dict, now: datetime) -> datetime | None:+ """Age only noncritical findings with a valid original detection time.++ Missing, naive, malformed or future timestamps never grant extra time.+ Neither updated_at nor the latest analysis time can restart this clock.+ """+ if alert["rule"].get("security_severity_level") == "critical":+ return None+ if "first_detected_at" in alert:+ first_seen = alert["first_detected_at"]+ if not isinstance(first_seen, datetime):+ return None+ else:+ created = alert.get("created_at")+ if not isinstance(created, str):+ return None+ try:+ first_seen = datetime.fromisoformat(created.replace("Z", "+00:00"))+ except ValueError:+ return None+ if first_seen.tzinfo is None or now.tzinfo is None:+ return None+ if first_seen > now:+ return None+ deadline = first_seen + GRACE_PERIOD+ return deadline if now < deadline else None+++def apply_grace(+ alerts: list[dict], now: datetime, expired: list[int] | tuple[int, ...] = ()+) -> tuple[list[dict], list[dict]]:+ blocking, graced = [], []+ for alert in alerts:+ destination = (+ graced+ if alert["number"] not in expired and grace_deadline(alert, now)+ else blocking+ )+ destination.append(alert)+ return blocking, graced++def classify_alerts(alerts: list[dict],exceptions: dict[int, dict],@@ -150,7 +415,10 @@ def classify_alerts() -> tuple[list[dict], list[dict], list[int]]:blocking, excepted, expired = [], [], []for alert in alerts:- if alert["rule"].get("security_severity_level") not in SEVERITIES:+ if not blocking_severity(alert):+ continue+ if alert["rule"].get("security_severity_level") == "critical":+ blocking.append(alert)continueentry = exceptions.get(alert["number"])if entry is not None and matches_exception(alert, entry):@@ -164,30 +432,62 @@ def classify_alerts(def publication_deadline(- excepted: list[dict], exceptions: dict[int, dict]+ excepted: list[dict],+ exceptions: dict[int, dict],+ graced: list[dict] | tuple = (),) -> str:- """Carry only applied exceptions' earliest expiry into publication jobs."""- return min(- (exceptions[alert["number"]]["expires_on"] for alert in excepted),- default="none",- )+ """Carry the earliest applied exception or grace expiry into publication."""+ deadlines = [+ exceptions[alert["number"]]["expires_on"] for alert in excepted+ ]+ for alert in graced:+ created = alert.get("first_detected_at") or datetime.fromisoformat(+ alert["created_at"].replace("Z", "+00:00")+ )+ deadlines.append(+ (created + GRACE_PERIOD)+ .astimezone(timezone.utc)+ .isoformat()+ .replace("+00:00", "Z")+ )+ return min(deadlines, key=deadline_instant, default="none")+++def deadline_instant(value: str) -> datetime:+ """Accept legacy UTC dates and exact, timezone-qualified grace deadlines."""+ if re.fullmatch(r"\d{4}-\d{2}-\d{2}", value):+ return datetime.combine(+ date.fromisoformat(value), datetime.min.time(), timezone.utc+ )+ if not re.fullmatch(+ r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?Z", value+ ):+ raise ValueError(+ "Release deadline must be a UTC date, timestamp or none"+ )+ return datetime.fromisoformat(value.replace("Z", "+00:00"))-def earliest_deadline(previous: str, current: str, today: date) -> str:+def earliest_deadline(+ previous: str, current: str, today: date | datetime+) -> str:"""Retain every applied expiry, including alerts absent from a later query."""deadlines = []for value in (previous, current):if value == "none":continue- expiry = date.fromisoformat(value)- if expiry.isoformat() != value:- raise ValueError("Release deadline must be YYYY-MM-DD or none")- if today >= expiry:- raise ValueError(- f"Release exception expired at 00:00 UTC on {value}"- )+ expiry = deadline_instant(value)+ now = (+ today+ if hasattr(today, "hour")+ else datetime.combine(today, datetime.min.time(), timezone.utc)+ )+ if now.tzinfo is None:+ raise ValueError("Release clock must be timezone-qualified")+ if now >= expiry:+ raise ValueError(f"Release exception expired at {value} (UTC)")deadlines.append(value)- return min(deadlines, default="none")+ return min(deadlines, key=deadline_instant, default="none")def summary_text(value: str) -> str:@@ -208,6 +508,7 @@ def render_summary(expired: list[int],exceptions: dict[int, dict],deadline: str,+ graced: list[dict] | tuple = (),) -> str:open_counts, excepted_counts, blocking_counts = (Counter(alert["rule"].get("security_severity_level") for alert in group)@@ -251,6 +552,16 @@ def render_summary("Expired exceptions (blocking again): "+ ", ".join(f"#{number}" for number in expired),]+ if graced:+ lines += [+ "",+ f"**14-day grace period: {len(graced)} open finding(s).**",+ ]+ for alert in graced:+ lines.append(+ f"- [#{alert['number']}](https://github.com/{repository}/security/code-scanning/{alert['number']}) "+ f"becomes blocking at `{publication_deadline([], {}, [alert])}`."+ )if blocking:lines += ["", f"**Release blocked: {len(blocking)} alert(s).**", ""]for alert in blocking:@@ -261,11 +572,16 @@ def render_summary(else "")lines.append(- f"- [{alert['rule']['security_severity_level'].upper()}] "+ f"- [{(alert['rule'].get('security_severity_level') or alert['rule']['severity']).upper()}] "f"`{summary_text(alert['rule']['id'])}` "f"[#{alert['number']}](https://github.com/{repository}"f"/security/code-scanning/{alert['number']}){detail}")+ elif graced:+ lines += [+ "",+ "**Passed with visible, time-limited noncritical findings.**",+ ]elif excepted:lines += ["",@@ -274,16 +590,16 @@ def render_summary(elif deadline != "none":lines += ["",- "**Passed with temporary release exceptions from the fresh "- "scan evidence check. Their original expiry still applies.**",+ "**Passed with time-limited decisions from fresh scan evidence. "+ "Their original expiry still applies.**",]else:lines += ["", "**No open critical, high, or medium severity alerts.**"]if not blocking:lines += ["",- "Publication deadline (UTC, exclusive; `none` means no applied "- "exceptions): "+ "Publication deadline (UTC, exclusive; `none` means no "+ "time-limited decision): "f"`{deadline}`.",]return "\n".join(lines) + "\n"@@ -297,31 +613,70 @@ def annotate(level: str, message: str) -> None:print(f"::{level}::{escaped}")+def native_deadlines(value: str) -> list[str]:+ deadlines = json.loads(value)+ if not isinstance(deadlines, list) or any(+ not isinstance(d, str) for d in deadlines+ ):+ raise ValueError("Invalid native scan deadlines")+ return deadlines++def main() -> int:parser = argparse.ArgumentParser(description=__doc__)parser.add_argument("--repository", required=True)parser.add_argument("--exceptions", type=Path, default=POLICY_PATH)parser.add_argument("--evidence-deadline", required=True)+ parser.add_argument("--native-deadlines", default="[]")args = parser.parse_args()if not re.fullmatch(r"[\w.-]+/[\w.-]+", args.repository):parser.error("Repository must be OWNER/REPO")try:- earliest_deadline(- args.evidence_deadline, "none", datetime.now(timezone.utc).date()- )+ now = datetime.now(timezone.utc)+ earliest_deadline(args.evidence_deadline, "none", now)exceptions = load_exceptions(args.exceptions, args.repository)alerts = fetch_alerts(args.repository)- today = datetime.now(timezone.utc).date()+ now = datetime.now(timezone.utc)+ tools = {+ (a.get("tool") or {}).get("name")+ for a in alerts+ if blocking_severity(a) and grace_deadline(a, now)+ }+ history = [+ row+ for tool in tools+ if tool+ for state in ("fixed", "dismissed")+ for row in fetch_alerts(args.repository, state, tool_name=tool)+ ]+ # Post-gate alerts still back-date the same finding, but cannot block.+ # The open-alert list above is the default branch's view, so its+ # instances are read on that ref only (resolved once, on demand).+ refs = []++ def default_instances(number):+ if not refs:+ refs.append(default_branch_ref(args.repository))+ return fetch_instances(args.repository, number, ref=refs[0])++ alerts = gate_alerts(+ retain_first_detection(alerts, history), default_instances+ )+ now = datetime.now(timezone.utc)+ today = now.date()blocking, excepted, expired = classify_alerts(alerts,exceptions,today,)+ blocking, graced = apply_grace(blocking, now, expired)deadline = earliest_deadline(args.evidence_deadline,- publication_deadline(excepted, exceptions),- today,+ publication_deadline(excepted, exceptions, graced),+ now,)+ for native_deadline in native_deadlines(args.native_deadlines):+ deadline = earliest_deadline(deadline, native_deadline, now)report = render_summary(args.repository,alerts,@@ -330,6 +685,7 @@ def main() -> int:expired,exceptions,deadline,+ graced,)print(report)if path := os.environ.get("GITHUB_STEP_SUMMARY"):@@ -354,17 +710,26 @@ def main() -> int:output.write(f"release_deadline={deadline}\n")return 0except subprocess.CalledProcessError as exc:- # gh puts useful HTTP/rate-limit diagnostics on stderr. Bound and- # escape them so API errors stay actionable without log injection.- detail = exc.stderr or exc.stdout or "No API error body returned"+ # Retain status diagnostics without echoing native API response bodies.+ detail = exc.stderr or exc.stdout or ""+ status = re.search(r"HTTP[ /:]*(\d{3})", detail)+ diagnostic = f"; HTTP {status.group(1)}" if status else ""+ if "rate limit" in detail.casefold():+ diagnostic += "; rate limit"annotate("error",- f"Security alert API request failed (exit {exc.returncode}): "- f"{detail[:2000]}",+ f"Security alert API request failed (exit {exc.returncode}{diagnostic})",)return 1- except (OSError, ValueError, subprocess.SubprocessError) as exc:- annotate("error", f"Security alert gate could not complete: {exc}")+ except (+ OSError,+ ValueError,+ TypeError,+ AttributeError,+ KeyError,+ subprocess.SubprocessError,+ ):+ annotate("error", "Security alert gate could not complete")return 1diff --git a/.github/scripts/check_release_deadline.py b/.github/scripts/check_release_deadline.pyindex 8fb9f8ce32..431ebd48ba 100644--- a/.github/scripts/check_release_deadline.py+++ b/.github/scripts/check_release_deadline.py@@ -1,8 +1,8 @@#!/usr/bin/env python3"""Recheck the security gate's deadline after approvals, before publishing.-The original gate emits YYYY-MM-DD (exclusive, UTC) or the explicit sentinel-`none` when no exception was applied. Missing or malformed values fail closed;+The original gate emits an exclusive UTC date or timestamp, or the explicit+sentinel `none` when no time-limited decision applied. Invalid values fail closed;reruns must not silently turn a lost output into an unlimited exception."""@@ -10,23 +10,34 @@ from __future__ import annotationsimport argparsefrom datetime import date, datetime, timezone+import os+from pathlib import Path+import re+++def deadline_instant(value: str) -> datetime:+ if re.fullmatch(r"\d{4}-\d{2}-\d{2}", value):+ return datetime.combine(+ date.fromisoformat(value), datetime.min.time(), timezone.utc+ )+ if re.fullmatch(+ r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?Z", value+ ):+ return datetime.fromisoformat(value.replace("Z", "+00:00"))+ raise ValueError(+ "Missing or invalid release deadline; use the original security gate output (UTC date, timestamp or none)."+ )def check_deadline(value: str, now: datetime) -> None:if value == "none":return- try:- expiry = date.fromisoformat(value)- except ValueError:- raise ValueError(- "Missing or invalid release deadline; use the original security "- "gate output (YYYY-MM-DD or none)."- ) from None- if expiry.isoformat() != value:- raise ValueError("Release deadline must be YYYY-MM-DD or none.")- if now.astimezone(timezone.utc).date() >= expiry:+ expiry = deadline_instant(value)+ if now.tzinfo is None:+ raise ValueError("The publication clock must be timezone-qualified.")+ if now >= expiry:raise ValueError(- f"Release exception expired at 00:00 UTC on {value}; "+ f"Release exception expired at {value} (UTC); ""publication is blocked. Fix the alert or merge a reviewed ""policy update and start a new release run.")@@ -35,13 +46,34 @@ def check_deadline(value: str, now: datetime) -> None:def main() -> int:parser = argparse.ArgumentParser(description=__doc__)parser.add_argument("--deadline", required=True)+ parser.add_argument("--additional-deadline", default="none")+ parser.add_argument("--write-output", action="store_true")args = parser.parse_args()try:- check_deadline(args.deadline, datetime.now(timezone.utc))+ now = datetime.now(timezone.utc)+ check_deadline(args.deadline, now)+ check_deadline(args.additional_deadline, now)+ if args.write_output:+ earliest = min(+ (+ d+ for d in (args.deadline, args.additional_deadline)+ if d != "none"+ ),+ key=deadline_instant,+ default="none",+ )+ with Path(os.environ["GITHUB_OUTPUT"]).open(+ "a", encoding="utf-8"+ ) as output:+ output.write(f"release_deadline={earliest}\n")except ValueError as exc:# Messages contain only constants and a validated ISO date.print(f"::error::{exc}")return 1+ except (OSError, KeyError):+ print("::error::Release deadline output could not be written")+ return 1print(f"Release exception deadline verified: {args.deadline}")return 0diff --git a/.github/scripts/check_release_report_age.py b/.github/scripts/check_release_report_age.pynew file mode 100644index 0000000000..26b6a3c63e--- /dev/null+++ b/.github/scripts/check_release_report_age.py@@ -0,0 +1,418 @@+#!/usr/bin/env python3+"""Apply the release finding policy to a completed, uploaded native report.++Native scans still validate completion before calling this helper. Only GET+requests are made here. Missing history or invalid reports fail closed; no+finding is dismissed or hidden to obtain a passing release decision.+"""++from __future__ import annotations++import argparse+from datetime import datetime, timezone+import importlib.util+import json+import math+import os+from pathlib import Path+import re+import subprocess+import time+from urllib.parse import unquote, urlsplit, urlencode+from uuid import UUID+++def policy_module():+ source = Path(__file__).with_name("check_code_scanning_alerts.py")+ spec = importlib.util.spec_from_file_location(+ "native_release_policy", source+ )+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ return module+++def api(endpoint):+ response = subprocess.run(+ ["gh", "api", "--method", "GET", endpoint],+ check=True,+ capture_output=True,+ text=True,+ timeout=30,+ )+ return json.loads(response.stdout)+++def verify_upload(+ upload_id,+ category,+ report,+ repository,+ sha,+ ref,+ job,+ workflow_ref,+ *,+ fetch=api,+ sleep=time.sleep,+):+ """A completed native scan must also have this exact successful analysis."""+ if str(UUID(upload_id)) != upload_id:+ raise ValueError("Invalid upload identity")+ if not re.fullmatch(r"[\w.-]+/[\w.-]+", repository, flags=re.ASCII) or any(+ part in {".", ".."} for part in repository.split("/")+ ):+ raise ValueError("Invalid repository context")+ if not re.fullmatch(r"[a-f0-9]{40}", sha) or not ref.startswith("refs/"):+ raise ValueError("Invalid commit or ref context")+ prefix = repository + "/"+ if not workflow_ref.startswith(prefix) or "@" not in workflow_ref:+ raise ValueError("Invalid workflow context")+ workflow = workflow_ref[len(prefix) :].split("@", 1)[0]+ if not re.fullmatch(+ r"\.github/workflows/[\w.-]+\.ya?ml", workflow+ ) or not re.fullmatch(r"[\w-]+", job, flags=re.ASCII):+ raise ValueError("Invalid workflow or job context")+ tool = report["runs"][0]["tool"]["driver"]["name"].casefold()+ if category == "auto" and tool != "osv-scanner":+ raise ValueError("Only the legacy OSV upload uses an implicit category")+ root = f"repos/{repository}/code-scanning"+ for attempt in range(19):+ status = fetch(f"{root}/sarifs/{upload_id}")+ if (+ not isinstance(status, dict)+ or status.get("errors") not in (None, [])+ or status.get("processing_status") not in {"pending", "complete"}+ ):+ raise ValueError("Native SARIF processing failed")+ if status["processing_status"] == "complete":+ records = fetch(+ f"{root}/analyses?"+ + urlencode({"sarif_id": upload_id, "per_page": 100})+ )+ if not isinstance(records, list) or len(records) > 1:+ raise ValueError("Invalid exact-upload analysis response")+ if records:+ row = records[0]+ if not isinstance(row, dict):+ raise ValueError("Invalid native analysis record")+ expected = {+ "sarif_id": upload_id,+ "commit_sha": sha,+ "ref": ref,+ "analysis_key": f"{workflow}:{job}",+ "error": "",+ }+ if category != "auto":+ expected["category"] = category+ elif (+ not isinstance(row.get("category"), str)+ or not row["category"]+ ):+ raise ValueError("Missing native analysis category")+ if (+ any(row.get(k) != v for k, v in expected.items())+ or (row.get("tool") or {}).get("name", "").casefold()+ != tool+ ):+ raise ValueError(+ "Analysis does not match this completed native scan"+ )+ if (+ type(row.get("results_count")) is not int+ or row["results_count"] < 0+ ):+ raise ValueError("Invalid analysis result count")+ if (+ any(run["results"] for run in report["runs"])+ and row["results_count"] == 0+ ):+ raise ValueError(+ "Native findings are absent from the processed analysis"+ )+ return+ if attempt == 18:+ raise ValueError("Native SARIF analysis did not complete")+ sleep(5)+++def relative_location(uri: str, root: Path) -> str:+ value = unquote(uri).replace("\\", "/")+ if value.startswith("file:"):+ value = urlsplit(value).path+ prefix = root.as_posix().rstrip("/") + "/"+ if value.startswith(prefix):+ value = value[len(prefix) :]+ return value.removeprefix("./")+++def report_findings(report: object, root: Path) -> list[dict]:+ if not isinstance(report, dict) or report.get("version") != "2.1.0":+ raise ValueError("Invalid native SARIF envelope")+ runs = report.get("runs")+ if not isinstance(runs, list) or not runs:+ raise ValueError("Native report contains no runs")+ findings = []+ for run in runs:+ if not isinstance(run, dict):+ raise ValueError("Invalid native run")+ driver = (run.get("tool") or {}).get("driver") or {}+ tool = driver.get("name")+ if not isinstance(tool, str) or not tool:+ raise ValueError("Native report has no tool identity")+ for invocation in run.get("invocations", []):+ if (+ not isinstance(invocation, dict)+ or invocation.get("executionSuccessful") is False+ ):+ raise ValueError("Native scanner did not complete")+ if any(+ n.get("level") == "error"+ for n in invocation.get("toolExecutionNotifications", [])+ ):+ raise ValueError("Native scanner reported an execution error")+ declared = driver.get("rules", [])+ if not isinstance(declared, list) or any(+ not isinstance(rule, dict) or not isinstance(rule.get("id"), str)+ for rule in declared+ ):+ raise ValueError("Invalid native rule collection")+ rules = {rule["id"]: rule for rule in declared}+ if len(rules) != len(declared):+ raise ValueError("Ambiguous native rule identities")+ results = run.get("results")+ if not isinstance(results, list):+ raise ValueError("Native report has no results array")+ for result in results:+ if not isinstance(result, dict):+ raise ValueError("Invalid native finding")+ rule_id = result.get("ruleId")+ if not isinstance(rule_id, str) or not rule_id:+ raise ValueError("Native finding has no rule identity")+ # A Docker parser error is incomplete scanning, not an aged finding.+ if tool.casefold() == "hadolint" and rule_id == "DL1000":+ raise ValueError("Dockerfile could not be parsed")+ rule = rules.get(rule_id, {})+ scores = [+ properties["security-severity"]+ for properties in (+ result.get("properties") or {},+ rule.get("properties") or {},+ )+ if properties.get("security-severity") is not None+ ]+ severity = None+ numeric = []+ for score in scores:+ if isinstance(score, bool) or not isinstance(+ score, (str, int, float)+ ):+ raise ValueError("Invalid native security score")+ score = float(score)+ if not math.isfinite(score) or not 0 <= score <= 10:+ raise ValueError("Invalid native security score")+ numeric.append(score)+ if numeric and max(numeric) > 0:+ score = max(numeric)+ severity = (+ "critical"+ if score >= 9+ else "high"+ if score >= 7+ else "medium"+ if score >= 4+ else "low"+ )+ level = result.get(+ "level",+ (rule.get("defaultConfiguration") or {}).get(+ "level", "warning"+ ),+ )+ if level not in {"error", "warning", "note", "none"}:+ raise ValueError("Invalid native finding level")+ locations = result.get("locations")+ if not isinstance(locations, list) or not locations:+ raise ValueError("Native finding has no source location")+ location = locations[0].get("physicalLocation") or {}+ uri = (location.get("artifactLocation") or {}).get("uri")+ if not isinstance(uri, str) or not uri:+ raise ValueError("Native finding has no artifact identity")+ findings.append(+ {+ "number": len(findings) + 1,+ "state": "open",+ "rule": {+ "id": rule_id,+ "security_severity_level": severity,+ "severity": level,+ },+ "tool": {"name": tool},+ "most_recent_instance": {+ "location": {+ "path": relative_location(uri, root),+ "start_line": (location.get("region") or {}).get(+ "startLine", 1+ ),+ }+ },+ }+ )+ return findings+++def evaluate(+ report: object,+ root: Path,+ repository: str,+ *,+ now=None,+ fetch=None,+ sleep=time.sleep,+ refresh=None,+):+ policy = policy_module()+ supplied_now = now is not None+ now = now or datetime.now(timezone.utc)+ findings = [+ f for f in report_findings(report, root) if policy.blocking_severity(f)+ ]+ if any(+ f["rule"]["security_severity_level"] == "critical" for f in findings+ ):+ raise ValueError("Critical native findings block immediately")+ if not findings:+ return "none", 0+ fetch = fetch or policy.fetch_alerts+ history = []+ for attempt in range(7):+ if attempt and refresh is not None:+ refresh()+ history = [+ row+ for state in ("open", "fixed", "dismissed")+ for row in fetch(repository, state)+ ]+ keys = {policy.finding_key(row) for row in history}+ if all(policy.finding_key(row) in keys for row in findings):+ break+ if attempt == 6:+ raise ValueError(+ "Uploaded findings have no indexed first-detection history"+ )+ sleep(5)+ # Synthetic native records must not overwrite the server's original date.+ if not supplied_now:+ now = datetime.now(timezone.utc)+ indexed = []+ for finding in findings:+ matches = [+ row+ for row in history+ if policy.finding_key(row) == policy.finding_key(finding)+ ]+ if any(+ row.get("state") == "open"+ and row["rule"].get("security_severity_level") == "critical"+ for row in matches+ ):+ raise ValueError("Critical indexed findings block immediately")+ # History rows for this key may carry a lower, non-blocking GitHub+ # score than this report. Evaluate an indexed record with the+ # report's blocking severity so first_detected_at is always derived+ # from every matching history row rather than raising KeyError.+ original = policy.retain_first_detection(+ [{**matches[0], "rule": finding["rule"]}], history+ )[0]+ indexed.append(+ {+ **finding,+ "created_at": original.get("created_at"),+ "first_detected_at": original["first_detected_at"],+ }+ )+ blocking, graced = policy.apply_grace(indexed, now)+ if blocking:+ raise ValueError(+ f"{len(blocking)} native finding(s) exceed or cannot prove the 14-day grace period"+ )+ return policy.publication_deadline([], {}, graced), len(graced)+++def main():+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--report", required=True, type=Path, action="append")+ parser.add_argument("--sarif-id", required=True, action="append")+ parser.add_argument("--category", required=True, action="append")+ args = parser.parse_args()+ if not (len(args.report) == len(args.sarif_id) == len(args.category)):+ parser.error("Every report needs its own upload receipt")+ try:+ policy = policy_module()+ deadline, count = "none", 0+ cache = {}+ for path, upload_id, category in zip(+ args.report, args.sarif_id, args.category+ ):+ report = json.loads(path.read_text(encoding="utf-8"))+ report_findings(report, Path.cwd())+ verify_upload(+ upload_id,+ category,+ report,+ os.environ["GITHUB_REPOSITORY"],+ os.environ["GITHUB_SHA"],+ os.environ["GITHUB_REF"],+ os.environ["GITHUB_JOB"],+ os.environ["GITHUB_WORKFLOW_REF"],+ )+ tool = report["runs"][0]["tool"]["driver"]["name"]++ def fetch_history(repository, state):+ key = repository, state, tool, os.environ["GITHUB_REF"]+ if key not in cache:+ # The release ref supplies newly indexed findings; the+ # default branch preserves earlier repository detections.+ cache[key] = [+ row+ for ref in (os.environ["GITHUB_REF"], None)+ for row in policy.fetch_alerts(+ repository, state, ref=ref, tool_name=tool+ )+ ]+ return cache[key]++ current, size = evaluate(+ report,+ Path.cwd(),+ os.environ["GITHUB_REPOSITORY"],+ fetch=fetch_history,+ refresh=cache.clear,+ )+ deadline = policy.earliest_deadline(+ deadline, current, datetime.now(timezone.utc)+ )+ count += size+ policy.earliest_deadline(deadline, "none", datetime.now(timezone.utc))+ print(+ f"Native report verified: {count} visible finding(s) within the grace period; deadline {deadline}"+ )+ if path := os.environ.get("GITHUB_OUTPUT"):+ with Path(path).open("a", encoding="utf-8") as output:+ output.write(f"release_deadline={deadline}\n")+ return 0+ except (+ OSError,+ ValueError,+ KeyError,+ TypeError,+ AttributeError,+ subprocess.SubprocessError,+ ):+ # Do not echo native payloads, package URLs, tokens or parser causes.+ print("::error::Native scan did not satisfy the release finding policy")+ return 1+++if __name__ == "__main__":+ raise SystemExit(main())diff --git a/.github/scripts/check_release_scan_evidence.py b/.github/scripts/check_release_scan_evidence.pyindex 1ece843529..54373e2f3f 100644--- a/.github/scripts/check_release_scan_evidence.py+++ b/.github/scripts/check_release_scan_evidence.py@@ -12,13 +12,6 @@ from datetime import datetime, timezonefrom pathlib import Pathfrom urllib.parse import urlencode-# gh redacts the token from its own error output, but be defensive: never let-# anything resembling a GitHub token reach a public log via a wrapped-# CalledProcessError's stderr.-_TOKEN_PATTERN = re.compile(- r"(?:ghp|gho|ghs|ghr|ghu|github_pat)_[A-Za-z0-9_]{10,}"-)-def timestamp(value):parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))@@ -163,10 +156,9 @@ def evaluate(exception_policy=None,):repo = os.environ["GITHUB_REPOSITORY"]- checker = None+ checker = _exception_checker()exceptions = {}if exception_policy is not None:- checker = _exception_checker()exceptions = checker.load_exceptions(Path(exception_policy), repo)sha, ref = os.environ["GITHUB_SHA"], os.environ["GITHUB_REF"]root = f"repos/{repo}"@@ -205,17 +197,54 @@ def evaluate()for row in page]- blocking = [row for row in alerts if blocking_alert(row)]- excepted = []- if checker is not None:- checker.validate_alerts(alerts)- _, excepted, _ = checker.classify_alerts(- alerts, exceptions, datetime.now(timezone.utc).date()+ now = datetime.now(timezone.utc)+ checker.validate_alerts(alerts)+ tools = {+ (a.get("tool") or {}).get("name")+ for a in alerts+ if blocking_alert(a) and checker.grace_deadline(a, now)+ }+ history = [+ row+ for tool in tools+ if tool+ for state, history_ref in (+ ("fixed", ref),+ ("dismissed", ref),+ ("open", None),+ ("fixed", None),+ ("dismissed", None),+ )+ for page in pages(+ f"{root}/code-scanning/alerts",+ {+ **({"ref": history_ref} if history_ref else {}),+ "state": state,+ "tool_name": tool,+ },+ fetch,)- excepted_numbers = {row["number"] for row in excepted}- blocking = [- row for row in blocking if row["number"] not in excepted_numbers- ]+ for row in page+ ]+ # Docker publication ages its own post-gate Trivy categories; alerts open+ # only there still back-date the same finding but cannot block the gate.+ alerts = checker.gate_alerts(+ checker.retain_first_detection(alerts, history),+ lambda number: [+ row+ for page in pages(+ f"{root}/code-scanning/alerts/{int(number)}/instances",+ {"ref": ref},+ fetch,+ )+ for row in page+ ],+ )+ now = datetime.now(timezone.utc)+ blocking, excepted, expired = checker.classify_alerts(+ alerts, exceptions, now.date()+ )+ blocking, graced = checker.apply_grace(blocking, now, expired)with open(os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-8") as summary:@@ -226,6 +255,9 @@ def evaluate(summary.write(f"Open blocking alerts: **{len(blocking)}** (critical/high/medium or unscored error/warning).\n")+ summary.write(+ f"Visible findings in the 14-day grace period: **{len(graced)}**.\n"+ )if excepted:summary.write(f"Reviewed, unexpired exceptions: **{len(excepted)}**. "@@ -251,7 +283,7 @@ def evaluate(with Path(path).open("a", encoding="utf-8") as output:output.write("release_deadline="- f"{checker.publication_deadline(excepted, exceptions)}\n"+ f"{checker.publication_deadline(excepted, exceptions, graced)}\n")print(f"Release scan policy passed for {sha}: {len(expected)} fresh categories"@@ -275,24 +307,16 @@ def main(argv=()):AttributeError,subprocess.SubprocessError,) as exc:- # CalledProcessError's default str() omits the captured API response- # body, so surface gh's own stderr too (truncated: it can be a large- # JSON/HTML error page). gh already redacts the token from its- # output; _TOKEN_PATTERN is a defensive second layer so a token can- # never reach a public workflow log through this path.- detail = str(exc)- stderr = getattr(exc, "stderr", None)- if stderr:- if isinstance(stderr, bytes):- stderr = stderr.decode("utf-8", "replace")- snippet = _TOKEN_PATTERN.sub("[REDACTED]", stderr.strip())[:500]- if snippet:- detail = f"{detail} | gh stderr: {snippet}"- # Tool names and gh stderr are untrusted: escape them so they cannot- # end this line and start another workflow command.- detail = (- detail.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A")- )+ # Native response bodies, parser text and tool names may contain data+ # that should not be copied to public workflow diagnostics.+ detail = "policy or context validation failed"+ if isinstance(exc, subprocess.CalledProcessError):+ status = re.search(r"HTTP[ /:]*(\d{3})", exc.stderr or "")+ detail = "API request failed" + (+ f"; HTTP {status.group(1)}" if status else ""+ )+ elif isinstance(exc, subprocess.TimeoutExpired):+ detail = "API request timed out"print(f"::error::Release scan evidence failed: {detail}")return 1return 0diff --git a/.github/scripts/release_native_reports.py b/.github/scripts/release_native_reports.pynew file mode 100644index 0000000000..d749a09f9f--- /dev/null+++ b/.github/scripts/release_native_reports.py@@ -0,0 +1,332 @@+#!/usr/bin/env python3+"""Create minimal release-policy SARIF from complete native scanner reports.++Only scanner identities and repository paths are emitted. HTTP samples,+request/response bodies, credentials and native diagnostic payloads are not+copied into GitHub findings or error messages.+"""++from __future__ import annotations++import argparse+from collections import Counter+import json+from pathlib import Path+import re+import subprocess+++NPM_DIRECTORIES = (+ ".",+ "tests",+ "tests/ui_tests",+ "tests/ui_tests/playwright",+ "tests/accessibility_tests",+ "tests/api_tests_with_login",+ "tests/infrastructure_tests",+ "tests/puppeteer",+)+SCORES = {+ "info": "0.0",+ "low": "2.0",+ "moderate": "5.0",+ "medium": "5.0",+ "high": "8.0",+ "critical": "9.8",+}+++def sarif(tool: str, records: list[tuple[str, str, str]]) -> dict:+ rules = {}+ results = []+ for rule_id, severity, source in sorted(set(records)):+ score = SCORES[severity]+ previous = rules.get(rule_id)+ if previous is None or float(score) > float(+ previous["properties"]["security-severity"]+ ):+ rules[rule_id] = {+ "id": rule_id,+ "properties": {+ "security-severity": score,+ "tags": ["security"],+ },+ }+ if rule_id.startswith("GHSA-"):+ rules[rule_id]["helpUri"] = (+ "https://github.com/advisories/" + rule_id+ )+ results.append(+ {+ "ruleId": rule_id,+ "level": "note" if float(score) < 4 else "warning",+ "message": {+ "text": "Native scanner finding; review the native report."+ },+ "locations": [+ {+ "physicalLocation": {+ "artifactLocation": {"uri": source},+ "region": {"startLine": 1},+ }+ }+ ],+ }+ )+ return {+ "version": "2.1.0",+ "$schema": "https://json.schemastore.org/sarif-2.1.0.json",+ "runs": [+ {+ "tool": {+ "driver": {"name": tool, "rules": list(rules.values())}+ },+ "invocations": [{"executionSuccessful": True}],+ "results": results,+ }+ ],+ }+++def npm_findings(data: object, source: str) -> list[tuple[str, str, str]]:+ if (+ not isinstance(data, dict)+ or type(data.get("auditReportVersion")) is not int+ or data["auditReportVersion"] != 2+ or "error" in data+ ):+ raise ValueError("npm audit did not complete")+ vulns = data.get("vulnerabilities")+ if not isinstance(vulns, dict):+ raise ValueError("Invalid npm vulnerability collection")+ metadata = data.get("metadata")+ counts = (+ metadata.get("vulnerabilities") if isinstance(metadata, dict) else None+ )+ if not isinstance(counts, dict):+ raise ValueError("npm audit completion counts are missing")+ severities = ("info", "low", "moderate", "high", "critical")+ if any(+ not isinstance(info, dict) or info.get("severity") not in severities+ for info in vulns.values()+ ):+ raise ValueError("Invalid npm package severity")+ actual = Counter(info["severity"] for info in vulns.values())+ for severity in severities:+ if (+ type(counts.get(severity)) is not int+ or counts[severity] != actual[severity]+ ):+ raise ValueError(+ "npm audit severity counts do not match its records"+ )+ if type(counts.get("total")) is not int or counts["total"] != len(vulns):+ raise ValueError("npm audit returned partial results")+ findings = []++ def resolve(name, seen):+ if name in seen:+ return []+ info = vulns.get(name)+ if not isinstance(info, dict) or info.get("severity") not in SCORES:+ raise ValueError("Invalid npm package record")+ via = info.get("via")+ if not isinstance(via, list) or not via:+ raise ValueError("npm advisory provenance is missing")+ result = []+ for item in via:+ if isinstance(item, str):+ result.extend(resolve(item, {*seen, name}))+ elif isinstance(item, dict):+ identity = re.search(+ r"GHSA-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}",+ item.get("url", ""),+ re.I,+ )+ severity = item.get("severity")+ if identity is None or severity not in severities:+ raise ValueError("Unrecognized npm advisory")+ result.append(+ ("GHSA-" + identity.group()[5:].lower(), severity)+ )+ else:+ raise ValueError("Invalid npm advisory chain")+ return [+ (+ rule,+ max(+ (severity, info["severity"]), key=lambda s: float(SCORES[s])+ ),+ )+ for rule, severity in result+ ]++ for name in vulns:+ resolved = resolve(name, set())+ if not resolved:+ raise ValueError("Unresolvable npm advisory chain")+ for rule_id, severity in resolved:+ findings.append((rule_id, severity, source))+ return findings+++def audit_npm(root: Path, run=subprocess.run) -> dict:+ records = []+ scanned = 0+ for directory in NPM_DIRECTORIES:+ target = root / directory+ if not (target / "package.json").is_file():+ continue+ if not (target / "package-lock.json").is_file():+ raise ValueError("An npm manifest has no committed lockfile")+ scanned += 1+ completed = run(+ ["npm", "audit", "--audit-level=moderate", "--json"],+ cwd=target,+ capture_output=True,+ text=True,+ timeout=60,+ )+ if completed.returncode not in (0, 1):+ raise ValueError("npm audit failed to execute")+ data = json.loads(completed.stdout)+ source = (Path(directory) / "package-lock.json").as_posix()+ records.extend(npm_findings(data, source))+ if not scanned:+ raise ValueError("npm audit scanned no target")+ return sarif("npm-audit", records)+++def zap_actions(path: Path) -> dict[str, str]:+ actions = {}+ for row in path.read_text(encoding="utf-8").splitlines():+ if not row.strip() or row.lstrip().startswith("#"):+ continue+ match = re.fullmatch(r"\s*([0-9]+)\s+(FAIL|WARN|IGNORE)(?:\s+.*)?", row)+ if match is None or match[1] in actions:+ raise ValueError("Invalid or duplicate ZAP rule configuration")+ actions[match[1]] = match[2]+ return actions+++def zap_report(data: object, rules: Path = Path(".zap/rules.tsv")) -> dict:+ if not isinstance(data, dict) or not isinstance(data.get("@version"), str):+ raise ValueError("ZAP did not produce a native report")+ sites = data.get("site")+ 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(+ site.get("alerts"), list+ ):+ raise ValueError("Invalid ZAP target report")+ for finding in site["alerts"]:+ rule = finding.get("pluginid")+ risk = finding.get("riskcode")+ if (+ not isinstance(rule, str)+ or not re.fullmatch(r"[0-9]+", rule)+ or risk not in ("0", "1", "2", "3")+ ):+ raise ValueError("Invalid ZAP finding")+ action = actions.get(rule, "WARN")+ 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"))+ report = sarif("ZAP", records)+ for rule in report["runs"][0]["tool"]["driver"]["rules"]:+ rule["properties"].update(metadata[rule["id"]])+ return report+++def validate_checkov(data: object) -> None:+ reports = data if isinstance(data, list) else [data]+ if not reports:+ raise ValueError("Checkov produced no native summaries")+ for report in reports:+ if not isinstance(report, dict):+ raise ValueError("Checkov did not produce a native summary")+ summary = report.get("summary", report)+ if not isinstance(summary, dict):+ raise ValueError("Checkov did not produce a native summary")+ errors = summary.get("parsing_errors")+ if type(errors) is not int or errors != 0:+ raise ValueError("Checkov reported incomplete parsing")+ if "summary" not in report:+ # The pinned CLI emits this exact flat summary for a completed+ # scan with no applicable checks, rather than a results envelope.+ counts = {+ "passed",+ "failed",+ "skipped",+ "parsing_errors",+ "resource_count",+ }+ if (+ set(summary) != counts | {"checkov_version"}+ or any(+ type(summary[key]) is not int or summary[key] != 0+ for key in counts+ )+ or not isinstance(summary["checkov_version"], str)+ or not summary["checkov_version"]+ ):+ raise ValueError("Invalid Checkov empty-scan summary")+ continue+ results = report.get("results")+ if not isinstance(results, dict) or results.get("parsing_errors", []):+ raise ValueError("Checkov did not finish parsing its targets")+++def main():+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("format", choices=("npm", "zap", "checkov"))+ parser.add_argument("--input", type=Path)+ parser.add_argument("--output", type=Path)+ parser.add_argument("--rules", type=Path, default=Path(".zap/rules.tsv"))+ args = parser.parse_args()+ if args.format != "npm" and args.input is None:+ parser.error("A native report is required")+ if args.format != "checkov" and args.output is None:+ parser.error("A report destination is required")+ try:+ if args.format == "npm":+ report = audit_npm(Path.cwd())+ else:+ report = json.loads(args.input.read_text(encoding="utf-8"))+ if args.format == "checkov":+ validate_checkov(report)+ return 0+ report = zap_report(report, args.rules)+ args.output.write_text(json.dumps(report), encoding="utf-8")+ return 0+ except (+ OSError,+ ValueError,+ KeyError,+ TypeError,+ AttributeError,+ subprocess.SubprocessError,+ ):+ print(+ "::error::Native scanner did not produce complete release evidence"+ )+ return 1+++if __name__ == "__main__":+ raise SystemExit(main())diff --git a/.github/scripts/run_osv_scan.py b/.github/scripts/run_osv_scan.pyindex ff1ecfcd75..4465486ca4 100644--- a/.github/scripts/run_osv_scan.py+++ b/.github/scripts/run_osv_scan.py@@ -188,7 +188,10 @@ def scan(baseline: Path | None = None,*,resolve: bool = True,+ release_policy: bool = False,) -> int:+ if release_policy and baseline is not None:+ raise ValueError("Release finding policy cannot use a PR baseline")# An earlier invocation or a checked-in file must never qualify this scan.output.unlink(missing_ok=True)with tempfile.TemporaryDirectory(@@ -205,6 +208,8 @@ def scan(with open(github_output, "a", encoding="utf-8") as stream:stream.write("scan_complete=true\n")print(f"OSV scan completed: {findings} SARIF findings", flush=True)+ if release_policy:+ return 0if returncode == 0 or baseline is None:return returncodereturn compare_with_baseline(@@ -271,18 +276,22 @@ def main() -> int:parser.add_argument("--scanner", type=Path, required=True)parser.add_argument("--root", type=Path, default=Path.cwd())parser.add_argument("--output", type=Path, default=Path("results.sarif"))+ parser.add_argument("--release-policy", action="store_true")parser.add_argument("--baseline-root",type=Path,help="checkout of the base commit; fail only on findings it lacks",)args = parser.parse_args()+ if args.release_policy and args.baseline_root:+ parser.error("Release finding policy cannot use a PR baseline")try:return scan(args.scanner.resolve(),args.root.resolve(),args.output.absolute(),args.baseline_root.resolve() if args.baseline_root else None,+ release_policy=args.release_policy,)except (OSError, ScanError) as exc:print(f"::error::{exc}", flush=True)diff --git a/.github/workflows/checkov-scan.yml b/.github/workflows/checkov-scan.ymlindex 1cf740e6b6..4e3bae70ea 100644--- a/.github/workflows/checkov-scan.yml+++ b/.github/workflows/checkov-scan.yml@@ -3,6 +3,9 @@ name: Checkov scan and uploadon:workflow_call:inputs:+ release_policy:+ type: boolean+ default: falseallow-analysis-retry:description: Allow the caller to retry one failed analysis in a fresh jobtype: boolean@@ -11,6 +14,8 @@ on:retry:description: The workflow analysis needs one new scan and uploadvalue: ${{ jobs.checkov.outputs.retry }}+ release_deadline:+ value: ${{ jobs.checkov.outputs.release_deadline }}permissions: {} # Minimal top-level for OSSF Scorecard Token-Permissions@@ -20,6 +25,7 @@ jobs:timeout-minutes: 10outputs:retry: ${{ steps.workflow-analysis.outputs.retry }}+ release_deadline: ${{ steps.release-policy.outputs.release_deadline }}permissions:contents: readsecurity-events: write@@ -49,41 +55,52 @@ jobs:# See: https://github.com/bridgecrewio/checkov-action/issues/170# See: https://github.com/bridgecrewio/checkov/issues/5866- name: Run Checkov on Dockerfile+ env:+ RELEASE_POLICY: ${{ inputs.release_policy }}run: |- checkov -f Dockerfile \+ args=()+ if [ "$RELEASE_POLICY" = true ]; then args+=(--soft-fail); fi+ checkov "${args[@]}" -f Dockerfile \--framework dockerfile \--skip-check CKV_DOCKER_3 \- -o cli -o sarif \- --output-file-path console,checkov-docker.sarif+ -o cli -o json -o sarif \+ --output-file-path console,checkov-docker.json,checkov-docker.sarif+ python3 .github/scripts/release_native_reports.py checkov --input checkov-docker.json- name: Run Checkov on docker-compose files+ env:+ RELEASE_POLICY: ${{ inputs.release_policy }}run: |- checkov \+ args=()+ if [ "$RELEASE_POLICY" = true ]; then args+=(--soft-fail); fi+ checkov "${args[@]}" \-f docker-compose.yml \-f docker-compose.gpu.override.yml \-f docker-compose.tts.yml \-f docker-compose.unraid.yml \--framework yaml \- -o cli -o sarif \- --output-file-path console,checkov-compose.sarif-- # Checkov 3.2.499's workflow schema rejects `concurrency.queue` and- # silently skips any workflow that fails it, so release-gate.yml would go- # unscanned. Blank the key in this CI checkout only (line numbers are- # preserved) so the queue key no longer causes a skip. Checkov still- # skips workflows that fail its schema for other reasons (for example- # release.yml's `attestations` key and an expression in docker-tests.yml's- # `cancel-in-progress`).+ -o cli -o json -o sarif \+ --output-file-path console,checkov-compose.json,checkov-compose.sarif+ python3 .github/scripts/release_native_reports.py checkov --input checkov-compose.json++ # Earlier Checkov workflow schemas rejected `concurrency.queue` and+ # silently skipped affected files. Keep the compatibility preparation+ # before scanning; it preserves line numbers and removes no other keys.- name: Blank concurrency.queue for Checkovrun: python3 .github/scripts/strip-concurrency-queue.py .github/workflows/*.yml- name: Run Checkov on GitHub Actions workflows+ env:+ RELEASE_POLICY: ${{ inputs.release_policy }}run: |- checkov -d .github/workflows \+ args=()+ if [ "$RELEASE_POLICY" = true ]; then args+=(--soft-fail); fi+ checkov "${args[@]}" -d .github/workflows \--framework github_actions \--skip-check CKV_GHA_7 \- -o cli -o sarif \- --output-file-path console,checkov-workflows.sarif+ -o cli -o json -o sarif \+ --output-file-path console,checkov-workflows.json,checkov-workflows.sarif+ python3 .github/scripts/release_native_reports.py checkov --input checkov-workflows.json- name: Check SARIF files existid: check-sarif@@ -94,6 +111,7 @@ jobs:[ -f checkov-workflows.sarif ] && echo "workflows=true" >> "$GITHUB_OUTPUT"- name: Upload Dockerfile SARIF results+ id: upload-dockerif: always() && steps.check-sarif.outputs.docker == 'true'uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1with:@@ -101,6 +119,7 @@ jobs:category: checkov-dockerfile- name: Upload docker-compose SARIF results+ id: upload-composeif: always() && steps.check-sarif.outputs.compose == 'true'uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1with:@@ -136,4 +155,20 @@ jobs:run: |echo "=== Checkov IaC Security Scan Summary ==="echo "SARIF results uploaded to GitHub Security tab"- echo "Scan completed (strict mode - failures block CI)"+ echo "Scanner errors remain blocking; release findings use the configured age policy."++ - name: Enforce release finding age+ id: release-policy+ if: ${{ inputs.release_policy && steps.workflow-analysis.outputs.retry != 'true' }}+ env:+ GH_TOKEN: ${{ github.token }}+ SARIF_DOCKER_ID: ${{ steps.upload-docker.outputs.sarif-id }}+ SARIF_COMPOSE_ID: ${{ steps.upload-compose.outputs.sarif-id }}+ SARIF_WORKFLOWS_ID: ${{ steps.upload-workflows.outputs.sarif-id }}+ run: >-+ python3 .github/scripts/check_release_report_age.py+ --report checkov-docker.sarif --report checkov-compose.sarif+ --report checkov-workflows.sarif+ --sarif-id "$SARIF_DOCKER_ID" --category checkov-dockerfile+ --sarif-id "$SARIF_COMPOSE_ID" --category checkov-compose+ --sarif-id "$SARIF_WORKFLOWS_ID" --category checkov-workflowsdiff --git a/.github/workflows/checkov.yml b/.github/workflows/checkov.ymlindex 8a50730bff..d5b5ef7e99 100644--- a/.github/workflows/checkov.yml+++ b/.github/workflows/checkov.yml@@ -3,6 +3,13 @@ name: Checkov IaC Security Scanon:workflow_dispatch:workflow_call: # Called by release-gate.yml+ inputs:+ release_policy:+ type: boolean+ default: false+ outputs:+ release_deadline:+ value: ${{ jobs.scan.outputs.retry == 'true' && jobs.retry.outputs.release_deadline || jobs.scan.outputs.release_deadline }}permissions: {}@@ -14,6 +21,7 @@ jobs:security-events: writewith:allow-analysis-retry: true+ release_policy: ${{ inputs.release_policy == true }}# The official uploader permits one upload per tool/category per job.# A fresh job retains that protection and gives a failed analysis one retry.@@ -26,3 +34,4 @@ jobs:security-events: writewith:allow-analysis-retry: false+ release_policy: ${{ inputs.release_policy == true }}diff --git a/.github/workflows/container-security.yml b/.github/workflows/container-security.ymlindex 3b0fd7c98a..493290fd41 100644--- a/.github/workflows/container-security.yml+++ b/.github/workflows/container-security.yml@@ -62,6 +62,19 @@ jobs:trivyignores: '.trivyignore'version: 'v0.69.2'+ # The release gate ages these image alerts, but detected secrets are never+ # aged: this secret-only scan blocks immediately at the same severities.+ - name: Check for detected secrets+ uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0+ with:+ image-ref: local-deep-research:scan+ scan-type: 'image'+ scanners: 'secret'+ severity: 'CRITICAL,HIGH,MEDIUM'+ trivyignores: '.trivyignore'+ exit-code: '1'+ version: 'v0.69.2'+- name: Check if SARIF file existsid: check-sarifif: always()diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.ymlindex 28f3cf0638..edaaa445d9 100644--- a/.github/workflows/docker-publish.yml+++ b/.github/workflows/docker-publish.yml@@ -13,16 +13,19 @@ name: Publish Docker image# The actual build happens in prerelease-docker.yml; the multi-arch manifest# is signed and attested there. Here we only:# - Verify the source manifest digest matches what prerelease produced+# - Re-run Trivy against the immutable digest and verify finding deadlines# - Retag the prerelease manifest to release tags (:1.6.9, :1.6, :latest)# - Verify the digest is preserved (defends against imagetools re-encoding)-# - Re-run Trivy against the digest (catches CVE-database updates between-# prerelease build and release promote)# - Verify cosign signature transitivity from the original digest# - Clean up the prerelease tags## To re-publish, trigger a new release through release.yml.on:workflow_call:+ outputs:+ release_deadline:+ description: Earliest source or image finding deadline+ value: ${{ jobs.promote.outputs.release_deadline }}inputs:tag:description: "Release tag, e.g. 'v1.6.9' (with leading 'v')"@@ -37,7 +40,7 @@ on:type: stringrequired: truerelease_deadline:- description: "Original security gate deadline (YYYY-MM-DD or none)"+ description: "Original security gate deadline (UTC date/timestamp or none)"type: stringrequired: truesecrets:@@ -63,11 +66,14 @@ jobs:name: Retag prerelease manifest as releaseruns-on: ubuntu-latestenvironment: release+ outputs:+ release_deadline: ${{ steps.native-deadline.outputs.release_deadline }}permissions:# cosign verify is read-only against public Rekor/Fulcio — does not# mint a GitHub OIDC token, so id-token: write is not required here.# Signing (which does need id-token: write) happens in prerelease-docker.yml.contents: read+ security-events: writesteps:- name: Harden Runner@@ -155,9 +161,75 @@ jobs:fiecho "Source digest verified: $ACTUAL"- - name: Promote (retag) prerelease manifest to release tags+ - name: Re-scan release digest with Trivy+ uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0+ env:+ TRIVY_USERNAME: ${{ secrets.DOCKER_USERNAME }}+ TRIVY_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}+ with:+ image-ref: ${{ secrets.DOCKER_USERNAME }}/local-deep-research@${{ steps.version.outputs.expected_digest }}+ format: 'sarif'+ output: 'trivy-promotion.sarif'+ ignore-unfixed: true+ trivyignores: '.trivyignore'+ exit-code: '0'+ version: 'v0.69.2'++ - name: Upload native promotion findings+ id: native-upload+ uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1+ with:+ sarif_file: trivy-promotion.sarif+ category: trivy-promotion++ - name: Enforce promotion finding age+ id: native-policy+ env:+ GH_TOKEN: ${{ github.token }}+ SARIF_ID: ${{ steps.native-upload.outputs.sarif-id }}+ run: python3 .github/scripts/check_release_report_age.py --report trivy-promotion.sarif --sarif-id "$SARIF_ID" --category trivy-promotion++ - name: Check release digest for critical findings+ uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0+ env:+ TRIVY_USERNAME: ${{ secrets.DOCKER_USERNAME }}+ TRIVY_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}+ with:+ image-ref: ${{ secrets.DOCKER_USERNAME }}/local-deep-research@${{ steps.version.outputs.expected_digest }}+ severity: 'CRITICAL'+ ignore-unfixed: true+ trivyignores: '.trivyignore'+ exit-code: '1'+ version: 'v0.69.2'++ # Trivy's default image scanners include `secret`. Detected secrets are+ # never aged: a separate secret-only scan blocks immediately at MEDIUM+ # or above (LOW-rated pattern matches remain advisory in the SARIF).+ - name: Check release digest for detected secrets+ uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0+ env:+ TRIVY_USERNAME: ${{ secrets.DOCKER_USERNAME }}+ TRIVY_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}+ with:+ image-ref: ${{ secrets.DOCKER_USERNAME }}/local-deep-research@${{ steps.version.outputs.expected_digest }}+ scanners: 'secret'+ severity: 'CRITICAL,HIGH,MEDIUM'+ trivyignores: '.trivyignore'+ exit-code: '1'+ version: 'v0.69.2'++ - name: Bind promotion and original release deadlines+ id: native-deadlineenv:RELEASE_DEADLINE: ${{ inputs.release_deadline }}+ NATIVE_DEADLINE: ${{ steps.native-policy.outputs.release_deadline }}+ run: >-+ python3 .github/scripts/check_release_deadline.py --deadline "$RELEASE_DEADLINE"+ --additional-deadline "$NATIVE_DEADLINE" --write-output++ - name: Promote (retag) prerelease manifest to release tags+ env:+ RELEASE_DEADLINE: ${{ steps.native-deadline.outputs.release_deadline }}DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}SOURCE_TAG: ${{ steps.version.outputs.source_tag }}VERSION: ${{ steps.version.outputs.version }}@@ -198,39 +270,6 @@ jobs:echo "${TAG} -> ${ACTUAL} ✓"done- # Catches CVE-database updates that landed between the prerelease- # build and this promote step. Use the SHA-pinned action wrapper- # (same pin as prerelease-docker.yml's security-scan) with an- # explicit binary version pin — the prior `apt-get install -y trivy`- # approach was unpinned and exposed the release path to the Trivy- # apt-repo supply chain. The pinned action downloads the v0.69.2- # binary from GitHub releases by exact tag, which is the same- # binary the prerelease scan validated, keeping the two scans- # consistent.- #- # Unlike prerelease-docker.yml's security-scan (which scans a- # locally-loaded image, no registry pull), this step scans by- # registry digest — Trivy must pull the manifest + layers from- # Docker Hub. TRIVY_USERNAME/TRIVY_PASSWORD is the action's- # documented auth path; the `docker/login-action` above also- # writes ~/.docker/config.json which Trivy reads as a fallback,- # but the explicit env vars are more reliable (Trivy has- # documented docker.io credential-helper quirks — aquasecurity/- # trivy#432, aquasecurity/trivy#8385) and the image we scan IS on- # Docker Hub so this is the path most likely to keep working.- - name: Re-scan release digest with Trivy- uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0- env:- TRIVY_USERNAME: ${{ secrets.DOCKER_USERNAME }}- TRIVY_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}- with:- image-ref: ${{ secrets.DOCKER_USERNAME }}/local-deep-research@${{ steps.version.outputs.expected_digest }}- severity: 'CRITICAL,HIGH'- ignore-unfixed: true- trivyignores: '.trivyignore'- exit-code: '1'- version: 'v0.69.2'-- name: Verify cosign signature on promoted digestenv:DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}diff --git a/.github/workflows/hadolint.yml b/.github/workflows/hadolint.ymlindex af10a521f8..e592bb5098 100644--- a/.github/workflows/hadolint.yml+++ b/.github/workflows/hadolint.yml@@ -7,6 +7,13 @@ on:- '.hadolint.yaml'workflow_dispatch:workflow_call: # Called by release-gate.yml+ inputs:+ release_policy:+ type: boolean+ default: false+ outputs:+ release_deadline:+ value: ${{ jobs.hadolint.outputs.release_deadline }}schedule:# Run weekly on Tuesday at 9 AM UTC- cron: '0 9 * * 2'@@ -21,6 +28,8 @@ permissions: {} # Minimal top-level for OSSF Scorecard Token-Permissionsjobs:hadolint:+ outputs:+ release_deadline: ${{ steps.release-policy.outputs.release_deadline }}name: Hadolint Dockerfile Analysisruns-on: ubuntu-latestpermissions:@@ -45,10 +54,11 @@ jobs:dockerfile: Dockerfileformat: sarifoutput-file: hadolint.sarif- no-fail: false+ no-fail: ${{ inputs.release_policy == true }}verbose: true- name: Upload Hadolint results to GitHub Security+ id: native-uploaduses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1if: always()with:@@ -69,7 +79,7 @@ jobs:with:dockerfile: Dockerfileformat: tty- no-fail: false+ no-fail: ${{ inputs.release_policy == true }}continue-on-error: false- name: Display Hadolint summary@@ -109,3 +119,11 @@ jobs:echo "- [Security Tab](https://github.com/${{ github.repository }}/security/code-scanning)"echo "- [Hadolint Rules](https://github.com/hadolint/hadolint#rules)"} >> "$GITHUB_STEP_SUMMARY"++ - name: Enforce release finding age+ id: release-policy+ if: ${{ inputs.release_policy }}+ env:+ GH_TOKEN: ${{ github.token }}+ SARIF_ID: ${{ steps.native-upload.outputs.sarif-id }}+ run: python3 .github/scripts/check_release_report_age.py --report hadolint.sarif --sarif-id "$SARIF_ID" --category hadolintdiff --git a/.github/workflows/npm-audit.yml b/.github/workflows/npm-audit.ymlindex adc5c13307..f7fe13f7b5 100644--- a/.github/workflows/npm-audit.yml+++ b/.github/workflows/npm-audit.yml@@ -3,12 +3,24 @@ name: npm Security Auditon:workflow_dispatch:workflow_call: # Called by release-gate.yml+ inputs:+ release_policy:+ type: boolean+ default: false+ outputs:+ release_deadline:+ value: ${{ jobs.npm-audit.outputs.release_deadline }}permissions:contents: readjobs:npm-audit:+ permissions:+ contents: read+ security-events: write+ outputs:+ release_deadline: ${{ steps.release-policy.outputs.release_deadline }}runs-on: ubuntu-latesttimeout-minutes: 10@@ -29,6 +41,7 @@ jobs:node-version: '24'- name: Run npm audit on all package.json locations+ if: ${{ !inputs.release_policy }}run: |FAILED=falseFILTER="${GITHUB_WORKSPACE}/.github/scripts/npm_audit_allowlist.py"@@ -71,3 +84,23 @@ jobs:elseecho "✅ No non-allowlisted moderate or higher severity vulnerabilities found"fi++ - name: Generate complete release audit report+ if: ${{ inputs.release_policy }}+ run: python3 .github/scripts/release_native_reports.py npm --output npm-audit.sarif++ - name: Upload native npm findings+ id: native-upload+ if: ${{ inputs.release_policy }}+ uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1+ with:+ sarif_file: npm-audit.sarif+ category: npm-audit-release++ - name: Enforce release finding age+ id: release-policy+ if: ${{ inputs.release_policy }}+ env:+ GH_TOKEN: ${{ github.token }}+ SARIF_ID: ${{ steps.native-upload.outputs.sarif-id }}+ run: python3 .github/scripts/check_release_report_age.py --report npm-audit.sarif --sarif-id "$SARIF_ID" --category npm-audit-releasediff --git a/.github/workflows/osv-scan-reusable.yml b/.github/workflows/osv-scan-reusable.ymlindex 4dbeba1aa2..6d99c5574c 100644--- a/.github/workflows/osv-scan-reusable.yml+++ b/.github/workflows/osv-scan-reusable.yml@@ -5,6 +5,9 @@ name: OSV complete dependency scanon:workflow_call:inputs:+ release_policy:+ type: boolean+ default: falseref:description: Exact commit to scantype: string@@ -13,17 +16,23 @@ on:description: >-For pull requests and the merge queue: also scan the first parentof the scanned merge commit (the base it merges into) and fail only- on findings absent from it. The release gate and scheduled scans- leave it false and fail on any finding.+ on findings absent from it. Release finding age is a separate mode;+ scheduled scans retain strict native finding exits.type: booleandefault: false+ outputs:+ release_deadline:+ value: ${{ jobs.osv-scan.outputs.release_deadline }}+permissions: {}jobs:# Preserve the existing required "scan / osv-scan" check and the default# caller-dependent SARIF category. Category alignment is tracked in #7220.osv-scan:+ outputs:+ release_deadline: ${{ steps.release-policy.outputs.release_deadline }}runs-on: ubuntu-latest# Two serial scans (head and baseline) of up to 10 minutes each.timeout-minutes: 25@@ -69,16 +78,19 @@ jobs:env:GOTOOLCHAIN: autoBASELINE_PARENT: ${{ inputs.baseline_parent }}+ RELEASE_POLICY: ${{ inputs.release_policy }}run: |args=(--scanner "$RUNNER_TEMP/osv-scanner" --output results.sarif)if [ "$BASELINE_PARENT" = true ]; thenargs+=(--baseline-root "$RUNNER_TEMP/osv-baseline")fi+ if [ "$RELEASE_POLICY" = true ]; then+ args+=(--release-policy)+ fipython3 .github/scripts/run_osv_scan.py "${args[@]}"- # Completed vulnerable scans exit 1 and fail the job (with a baseline,- # only for findings the change introduces), while their findings- # remain uploadable. Failed/partial scans never set scan_complete.+ # Outside release policy, vulnerable scans fail (with a baseline, only+ # for introduced findings). Failed/partial scans never set scan_complete.- name: Upload artifactif: ${{ !cancelled() && steps.scan.outputs.scan_complete == 'true' }}uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2@@ -89,7 +101,16 @@ jobs:retention-days: 5- name: Upload to code-scanning+ id: native-uploadif: ${{ !cancelled() && steps.scan.outputs.scan_complete == 'true' }}uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1with:sarif_file: results.sarif++ - name: Enforce release finding age+ id: release-policy+ if: ${{ inputs.release_policy }}+ env:+ GH_TOKEN: ${{ github.token }}+ SARIF_ID: ${{ steps.native-upload.outputs.sarif-id }}+ run: python3 .github/scripts/check_release_report_age.py --report results.sarif --sarif-id "$SARIF_ID" --category autodiff --git a/.github/workflows/osv-scanner.yml b/.github/workflows/osv-scanner.ymlindex 8800701e07..19f1908056 100644--- a/.github/workflows/osv-scanner.yml+++ b/.github/workflows/osv-scanner.yml@@ -15,6 +15,13 @@ name: OSV-Scanneron:workflow_call: # A fresh scan of the caller commit for release-gate.yml+ inputs:+ release_policy:+ type: boolean+ default: false+ outputs:+ release_deadline:+ value: ${{ jobs.scan.outputs.release_deadline }}pull_request:branches: [ "main" ]merge_group:@@ -39,8 +46,9 @@ jobs:actions: readuses: $/.github/workflows/osv-scan-reusable.ymlwith:+ release_policy: ${{ inputs.release_policy == true }}ref: ${{ github.sha }}# PRs and the merge queue fail only on findings they introduce. The- # release gate (workflow_call from release-gate.yml) and the weekly- # schedule get no baseline and still fail on any finding.+ # release gate uses the finding age policy without a baseline. Weekly+ # scans retain strict native finding exits.baseline_parent: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' }}diff --git a/.github/workflows/owasp-zap-scan.yml b/.github/workflows/owasp-zap-scan.ymlindex 932102494e..59a94bf222 100644--- a/.github/workflows/owasp-zap-scan.yml+++ b/.github/workflows/owasp-zap-scan.yml@@ -9,6 +9,15 @@ on:- "scripts/ci/zap_api_*.py"- "tests/ci/standalone/test_zap*.py"workflow_call: # Called by release-gate.yml+ inputs:+ release_policy:+ type: boolean+ default: false+ outputs:+ baseline_deadline:+ value: ${{ jobs.zap-baseline-scan.outputs.release_deadline }}+ api_deadline:+ value: ${{ jobs.zap-api-scan.outputs.release_deadline }}workflow_dispatch:# Restrict top-level permissions (jobs define their own)@@ -16,6 +25,8 @@ permissions: {}jobs:zap-baseline-scan:+ outputs:+ release_deadline: ${{ steps.release-policy.outputs.release_deadline }}name: ZAP Baseline Scanruns-on: ubuntu-latesttimeout-minutes: 45@@ -90,7 +101,7 @@ jobs:rules_file_name: '.zap/rules.tsv'cmd_options: '-a -I' # -I: only fail on FAIL-level alerts per rules.tsv (ignore WARN/INFO)allow_issue_writing: false- fail_action: true+ fail_action: ${{ !inputs.release_policy }}artifact_name: zapbaseline- name: Upload ZAP scan results@@ -112,7 +123,30 @@ jobs:rm server.pidfi++ - name: Convert complete ZAP report+ if: ${{ inputs.release_policy }}+ run: python3 .github/scripts/release_native_reports.py zap --input report_json.json --rules .zap/rules.tsv --output zap-release.sarif++ - name: Upload native ZAP findings+ id: native-upload+ if: ${{ inputs.release_policy }}+ uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1+ with:+ sarif_file: zap-release.sarif+ category: zap-baseline-release++ - name: Enforce release finding age+ id: release-policy+ if: ${{ inputs.release_policy }}+ env:+ GH_TOKEN: ${{ github.token }}+ SARIF_ID: ${{ steps.native-upload.outputs.sarif-id }}+ run: python3 .github/scripts/check_release_report_age.py --report zap-release.sarif --sarif-id "$SARIF_ID" --category zap-baseline-release+zap-api-scan:+ outputs:+ release_deadline: ${{ steps.release-policy.outputs.release_deadline }}name: ZAP API Scanruns-on: ubuntu-latesttimeout-minutes: 45@@ -207,7 +241,7 @@ jobs:# are independent blockers. The hook logs in with real session/CSRF.cmd_options: '-a -I --hook=/zap/wrk/scripts/ci/zap_api_hooks.py -z "-config scanner.threadPerHost=2"'allow_issue_writing: false- fail_action: true+ fail_action: ${{ !inputs.release_policy }}artifact_name: zapapi- name: Require authenticated active-scan coverage@@ -234,3 +268,23 @@ jobs:kill "$(cat server.pid)" || truerm server.pidfi++ - name: Convert complete ZAP report+ if: ${{ inputs.release_policy }}+ run: python3 .github/scripts/release_native_reports.py zap --input report_json.json --rules .zap/rules.tsv --output zap-release.sarif++ - name: Upload native ZAP findings+ id: native-upload+ if: ${{ inputs.release_policy }}+ uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1+ with:+ sarif_file: zap-release.sarif+ category: zap-api-release++ - name: Enforce release finding age+ id: release-policy+ if: ${{ inputs.release_policy }}+ env:+ GH_TOKEN: ${{ github.token }}+ SARIF_ID: ${{ steps.native-upload.outputs.sarif-id }}+ run: python3 .github/scripts/check_release_report_age.py --report zap-release.sarif --sarif-id "$SARIF_ID" --category zap-api-releasediff --git a/.github/workflows/prerelease-docker.yml b/.github/workflows/prerelease-docker.ymlindex c98bd0b3d1..43d5b79527 100644--- a/.github/workflows/prerelease-docker.yml+++ b/.github/workflows/prerelease-docker.yml@@ -26,7 +26,7 @@ on:type: stringrequired: truerelease_deadline:- description: "Original security gate deadline (YYYY-MM-DD or none)"+ description: "Original security gate deadline (UTC date/timestamp or none)"type: stringrequired: truesecrets:@@ -40,6 +40,9 @@ on:required: truedescription: "Docker Hub PAT (Read+Write+Delete scopes)"outputs:+ release_deadline:+ description: Earliest original or image finding deadline+ value: ${{ jobs.create-manifest.outputs.release_deadline }}manifest_digest:description: "sha256:... digest of the multi-arch prerelease manifest. Used by docker-publish.yml to verify retag preserves the digest."value: ${{ jobs.create-manifest.outputs.digest }}@@ -164,11 +167,14 @@ jobs:docker push "$IMAGE"security-scan:+ outputs:+ release_deadline: ${{ steps.native-policy.outputs.release_deadline }}name: Security Scanruns-on: ubuntu-latestenvironment: releasepermissions:contents: read+ security-events: writesteps:- name: Harden the runner (Audit all outbound calls)@@ -213,21 +219,49 @@ jobs:image-ref: local-deep-research:security-scanformat: 'sarif'output: 'trivy-prerelease-scan.sarif'+ trivyignores: '.trivyignore'ignore-unfixed: trueexit-code: '0'version: 'v0.69.2'- # Separate scan that fails build only on fixable HIGH/CRITICAL vulnerabilities- - name: Check for fixable HIGH/CRITICAL vulnerabilities+ - name: Upload native image findings+ id: native-upload+ uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1+ with:+ sarif_file: trivy-prerelease-scan.sarif+ category: trivy-prerelease++ - name: Enforce image finding age+ id: native-policy+ env:+ GH_TOKEN: ${{ github.token }}+ SARIF_ID: ${{ steps.native-upload.outputs.sarif-id }}+ run: python3 .github/scripts/check_release_report_age.py --report trivy-prerelease-scan.sarif --sarif-id "$SARIF_ID" --category trivy-prerelease++ # Retain a native critical-only check; high findings use persisted age.+ - name: Check for fixable CRITICAL vulnerabilitiesuses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0with:image-ref: local-deep-research:security-scan- severity: 'CRITICAL,HIGH'+ severity: 'CRITICAL'ignore-unfixed: truetrivyignores: '.trivyignore'exit-code: '1'version: 'v0.69.2'+ # Trivy's default image scanners include `secret`. Detected secrets are+ # never aged: a separate secret-only scan blocks immediately at MEDIUM+ # or above (LOW-rated pattern matches remain advisory in the SARIF).+ - name: Check for detected secrets+ uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0+ with:+ image-ref: local-deep-research:security-scan+ scanners: 'secret'+ severity: 'CRITICAL,HIGH,MEDIUM'+ trivyignores: '.trivyignore'+ exit-code: '1'+ version: 'v0.69.2'+- name: Upload Trivy scan resultsuses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2if: always()@@ -248,6 +282,7 @@ jobs:# not GITHUB_TOKEN. `packages: write` only matters for ghcr.io pushes.outputs:digest: ${{ steps.capture-digest.outputs.digest }}+ release_deadline: ${{ steps.native-deadline.outputs.release_deadline }}steps:- name: Harden Runner@@ -281,9 +316,18 @@ jobs:- name: Install Syftuses: anchore/sbom-action/download-syft@66cbf4bc1f1c0d2edc94016e65bc221b6bb0ad6c # v0.24.3- - name: Create and push multi-platform manifest+ - name: Bind image and original release deadlines+ id: native-deadlineenv:RELEASE_DEADLINE: ${{ inputs.release_deadline }}+ NATIVE_DEADLINE: ${{ needs.security-scan.outputs.release_deadline }}+ run: >-+ python3 .github/scripts/check_release_deadline.py --deadline "$RELEASE_DEADLINE"+ --additional-deadline "$NATIVE_DEADLINE" --write-output++ - name: Create and push multi-platform manifest+ env:+ RELEASE_DEADLINE: ${{ steps.native-deadline.outputs.release_deadline }}DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}VERSION: ${{ inputs.version }}SHORT_SHA: ${{ inputs.short_sha }}diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.ymlindex 1810ee171e..6fe8853982 100644--- a/.github/workflows/publish.yml+++ b/.github/workflows/publish.yml@@ -145,12 +145,16 @@ jobs:python3 - <<'PYCODE'from datetime import date, datetime, timezoneimport os+ import revalue = os.environ["RELEASE_DEADLINE"]if value != "none":- expiry = date.fromisoformat(value)- if expiry.isoformat() != value:+ if re.fullmatch(r"\d{4}-\d{2}-\d{2}", value):+ expiry = datetime.combine(date.fromisoformat(value), datetime.min.time(), timezone.utc)+ elif re.fullmatch(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?Z", value):+ expiry = datetime.fromisoformat(value.replace("Z", "+00:00"))+ else:raise SystemExit("Invalid release deadline")- if datetime.now(timezone.utc).date() >= expiry:+ if datetime.now(timezone.utc) >= expiry:raise SystemExit("Release exception expired; publication is blocked")print("Original release deadline remains valid")PYCODEdiff --git a/.github/workflows/release-gate.yml b/.github/workflows/release-gate.ymlindex 796314f41a..7bae6fd719 100644--- a/.github/workflows/release-gate.yml+++ b/.github/workflows/release-gate.yml@@ -4,14 +4,15 @@ name: Release Gate## Security model:# - All security scans must pass before any release artifacts are published-# - Open security alerts block release unless an exact, unexpired exception-# is reviewed in .github/release-security-exceptions.json. Alerts stay open.-# Only the two alert checks in check-code-scanning-alerts read that policy:-# scanner jobs that fail on their own findings (OSV-Scanner, npm audit,-# Retire.js, Gitleaks) still block and keep their own suppressions.-# See .github/SECURITY_ALERTS.md#temporary-release-exceptions.-# - Docker and PyPI publish workflows are triggered ONLY via repository_dispatch-# from release.yml, which depends on this gate passing+# - Critical alerts and detected secrets block immediately (Gitleaks on any+# detection; Trivy image secret rules rated medium or above). Other blocking+# findings receive 14 days from original repository detection; low and+# informational findings remain advisory. Findings stay visible.+# - Scan errors and missing/failed processed analyses still block immediately.+# Exact noncritical exceptions require a reviewed, expiring policy entry.+# See .github/SECURITY_ALERTS.md#release-finding-policy.+# - Docker publishing is called by release.yml after this gate. PyPI dispatches+# verify their source run, tested distributions and bound security decision.# - Direct release creation via GitHub UI will NOT trigger publishing# (this is intentional - it prevents bypassing security checks)#@@ -29,7 +30,7 @@ on:workflow_call: # Called by release.ymloutputs:release_deadline:- description: "Earliest applied exception expiry (exclusive UTC date), or none"+ description: "Earliest applied exception or grace expiry (exclusive UTC date/timestamp), or none"value: ${{ jobs.check-code-scanning-alerts.outputs.release_deadline }}package_artifact_id:description: Immutable artifact containing the tested wheel and sdist@@ -103,6 +104,8 @@ jobs:owasp-zap-scan:uses: $/.github/workflows/owasp-zap-scan.yml+ with:+ release_policy: truepermissions:contents: readsecurity-events: write@@ -137,6 +140,8 @@ jobs:# ============================================osv-scan:uses: $/.github/workflows/osv-scanner.yml+ with:+ release_policy: truepermissions:contents: readsecurity-events: write@@ -144,11 +149,16 @@ jobs:npm-audit:uses: $/.github/workflows/npm-audit.yml+ with:+ release_policy: truepermissions:contents: read+ security-events: writeretirejs-scan:uses: $/.github/workflows/retirejs.yml+ with:+ release_policy: truepermissions:contents: readsecurity-events: write@@ -164,12 +174,16 @@ jobs:hadolint-scan:uses: $/.github/workflows/hadolint.yml+ with:+ release_policy: truepermissions:contents: readsecurity-events: writecheckov-scan:uses: $/.github/workflows/checkov.yml+ with:+ release_policy: truepermissions:contents: readsecurity-events: write@@ -365,6 +379,7 @@ jobs:timeout-minutes: 15permissions:contents: read+ security-events: writesteps:- name: Harden the runner (Audit all outbound calls)@@ -499,7 +514,7 @@ jobs:--scanner "$RUNNER_TEMP/osv-scanner" \--manifest "$GITHUB_WORKSPACE/release-package.json" \--policy "$GITHUB_WORKSPACE/osv-scanner.toml" \- --output "$RUNNER_TEMP/installed-dependency-audit/base"+ --output "$RUNNER_TEMP/installed-dependency-audit/base" --release-policyecho ""echo "=== twine check (PyPI metadata + long_description rendering) ==="@@ -544,7 +559,7 @@ jobs:--scanner "$RUNNER_TEMP/osv-scanner" \--manifest "$GITHUB_WORKSPACE/release-package.json" \--policy "$GITHUB_WORKSPACE/osv-scanner.toml" \- --output "$RUNNER_TEMP/installed-dependency-audit/mcp"+ --output "$RUNNER_TEMP/installed-dependency-audit/mcp" --release-policyecho ""echo "=== CLI entry-point resolution ==="@@ -582,6 +597,22 @@ jobs:MANIFEST_SHA256: ${{ steps.package-manifest.outputs.manifest_sha256 }}run: python .github/scripts/release_package.py verify+ # Findings are aged by the final gate after this exact analysis completes.+ # The base and [mcp] audits are separate OSV runs without+ # automationDetails; the pinned uploader rejects several runs from one+ # tool under a single category, so each gets its own required category.+ - name: Upload installed dependency findings+ uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1+ with:+ sarif_file: ${{ runner.temp }}/installed-dependency-audit/base/results.sarif+ category: installed-python-3.12-wheel++ - name: Upload installed [mcp] dependency findings+ uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1+ with:+ sarif_file: ${{ runner.temp }}/installed-dependency-audit/mcp/results.sarif+ category: installed-python-3.12-wheel-mcp+- name: Retain installed dependency audit evidenceif: always()uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2@@ -609,6 +640,7 @@ jobs:timeout-minutes: 20permissions:contents: read+ security-events: writestrategy:fail-fast: falsematrix:@@ -693,7 +725,14 @@ jobs:--scanner "$RUNNER_TEMP/osv-scanner" \--manifest release-package.json \--policy osv-scanner.toml \- --output "$RUNNER_TEMP/installed-dependency-audit"+ --output "$RUNNER_TEMP/installed-dependency-audit" --release-policy+ # Findings are aged by the final gate after this exact analysis completes.+ - name: Upload installed dependency findings+ uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1+ with:+ sarif_file: ${{ runner.temp }}/installed-dependency-audit/+ category: installed-python-${{ matrix.python }}-${{ matrix.distribution }}+- name: Retain installed dependency audit evidenceif: always()uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2@@ -878,6 +917,7 @@ jobs:# Wait for all SARIF-uploading scans to complete- codeql-scan- osv-scan+ - npm-audit- semgrep-scan- devskim-scan- bearer-scan@@ -897,6 +937,8 @@ jobs:- checkov-scan- zizmor-scan- gitleaks-scan+ - pip-install-check+ - package-install-matrixtimeout-minutes: 10permissions:contents: read@@ -926,10 +968,13 @@ jobs:env:GH_TOKEN: ${{ github.token }}EVIDENCE_DEADLINE: ${{ steps.scan-evidence.outputs.release_deadline }}+ NATIVE_DEADLINES: >-+ ["${{ needs.osv-scan.outputs.release_deadline }}", "${{ needs.npm-audit.outputs.release_deadline }}", "${{ needs.retirejs-scan.outputs.release_deadline }}", "${{ needs.hadolint-scan.outputs.release_deadline }}", "${{ needs.checkov-scan.outputs.release_deadline }}", "${{ needs.owasp-zap-scan.outputs.baseline_deadline }}", "${{ needs.owasp-zap-scan.outputs.api_deadline }}"]run: |python3 .github/scripts/check_code_scanning_alerts.py \--repository "$GITHUB_REPOSITORY" \- --evidence-deadline "$EVIDENCE_DEADLINE"+ --evidence-deadline "$EVIDENCE_DEADLINE" \+ --native-deadlines "$NATIVE_DEADLINES"# ============================================# Summary job that reports overall status@@ -1086,7 +1131,7 @@ jobs:echo "# :white_check_mark: RELEASE GATE: PASSED"echo ""echo "> **All $TOTAL required security checks passed.**"- echo "> Review any temporary alert exceptions listed below before publishing."+ echo "> Review the alert summary for time-limited findings before publishing."elseecho "# :x: RELEASE GATE: FAILED"echo ""diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 156f61be39..eea8f8cefb 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -718,6 +718,7 @@ jobs:# NOTE: no `packages: write` — Docker Hub auth uses DOCKER_PASSWORD# secret, not GITHUB_TOKEN. `packages: write` only matters for ghcr.io.contents: read+ security-events: writeid-token: write# Retag the prerelease manifest as the release tags (:VERSION, :MAJOR_MINOR,@@ -739,7 +740,7 @@ jobs:tag: ${{ needs.build.outputs.tag }}source_tag: prerelease-v${{ needs.build.outputs.version }}-${{ needs.build.outputs.short_sha }}expected_digest: ${{ needs.prerelease-docker.outputs.manifest_digest }}- release_deadline: ${{ needs.build.outputs.release_deadline }}+ release_deadline: ${{ needs.prerelease-docker.outputs.release_deadline }}secrets:# Explicit secret pass — env-scoped (`release`) DOCKER_USERNAME and# DOCKER_PASSWORD become available to the callee's `promote` job@@ -753,6 +754,7 @@ jobs:# OIDC is only needed for cosign SIGN, which happens upstream in# prerelease-docker.yml.contents: read+ security-events: writecreate-release:# create-release waits for prerelease-docker (canonical image exists,@@ -1453,7 +1455,7 @@ jobs:GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}RELEASE_TAG: ${{ needs.build.outputs.tag }}RELEASE_VERSION: ${{ needs.build.outputs.version }}- RELEASE_DEADLINE: ${{ needs.build.outputs.release_deadline }}+ RELEASE_DEADLINE: ${{ needs.publish-docker.outputs.release_deadline }}# Optional AI summarization. If OPENROUTER_API_KEY is not configured# in the release environment, the step skips the AI section silently.OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}diff --git a/.github/workflows/retirejs.yml b/.github/workflows/retirejs.ymlindex 88fd3221f4..acd1a27bf2 100644--- a/.github/workflows/retirejs.yml+++ b/.github/workflows/retirejs.yml@@ -3,6 +3,13 @@ name: Retire.js Security Scanon:workflow_dispatch:workflow_call: # Called by release-gate.yml+ inputs:+ release_policy:+ type: boolean+ default: false+ outputs:+ release_deadline:+ value: ${{ jobs.retirejs.outputs.release_deadline }}schedule:# Run weekly security scan on Mondays at 4 AM UTC- cron: '0 4 * * 1'@@ -14,6 +21,8 @@ permissions: {} # Minimal top-level for OSSF Scorecard Token-Permissionsjobs:retirejs:+ outputs:+ release_deadline: ${{ steps.release-policy.outputs.release_deadline }}name: Retire.js Vulnerability Scanruns-on: ubuntu-latesttimeout-minutes: 15@@ -122,6 +131,7 @@ jobs:echo "sarif_exists=true" >> "$GITHUB_OUTPUT"- name: Upload SARIF results+ id: native-uploaduses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1if: always() && steps.retire-scan.outputs.sarif_exists == 'true'with:@@ -129,6 +139,7 @@ jobs:category: retirejs- name: Check scan results+ if: ${{ !inputs.release_policy }}run: |if [[ "$RETIRE_FOUND_ISSUES" == "true" ]]; thenecho "::error::Retire.js found medium or higher severity vulnerabilities"@@ -142,3 +153,11 @@ jobs:elseecho "✅ No medium or higher severity vulnerabilities detected"fi++ - name: Enforce release finding age+ id: release-policy+ if: ${{ inputs.release_policy }}+ env:+ GH_TOKEN: ${{ github.token }}+ SARIF_ID: ${{ steps.native-upload.outputs.sarif-id }}+ run: python3 .github/scripts/check_release_report_age.py --report retire-results.sarif --sarif-id "$SARIF_ID" --category retirejsdiff --git a/tests/ci/standalone/test_installed_dependency_audit.py b/tests/ci/standalone/test_installed_dependency_audit.pyindex 3b1dc902a4..41d40fd781 100644--- a/tests/ci/standalone/test_installed_dependency_audit.py+++ b/tests/ci/standalone/test_installed_dependency_audit.py@@ -113,7 +113,7 @@ class AuditTests(unittest.TestCase):self.output = self.root / "audit"def run_audit(self, status=0):- def scan(scanner, output):+ def scan(scanner, output, *, release_policy=False):self.assertEqual((output / "osv-scanner.toml").read_bytes(),self.policy.read_bytes(),diff --git a/tests/ci/standalone/test_osv_scan.py b/tests/ci/standalone/test_osv_scan.pyindex 82c961ccd8..2852a0762c 100644--- a/tests/ci/standalone/test_osv_scan.py+++ b/tests/ci/standalone/test_osv_scan.py@@ -131,6 +131,7 @@ class ScanBoundaryTests(unittest.TestCase):workflow=False,log="",baseline=None,+ release_policy=False,):"""``baseline`` is (status, payload) for a scan of the base commit."""self.github_output.unlink(missing_ok=True)@@ -153,6 +154,7 @@ class ScanBoundaryTests(unittest.TestCase):FAKE_WRITE="1" if write else "0",FAKE_LOG=log,RUNNER_TEMP=str(self.directory),+ RELEASE_POLICY=str(release_policy).lower(),)if workflow:scripts = self.root / ".github/scripts"@@ -180,6 +182,8 @@ class ScanBoundaryTests(unittest.TestCase):]if baseline is not None:command += ["--baseline-root", str(self.baseline_root)]+ if release_policy:+ command += ["--release-policy"]result = subprocess.run(command,cwd=self.root,@@ -229,6 +233,42 @@ class ScanBoundaryTests(unittest.TestCase):with self.subTest(status=status):self.assert_rejected(status, json.dumps(report()))+ def test_release_mode_defers_only_complete_native_findings(self):+ for workflow in (False, True):+ with self.subTest(workflow=workflow):+ result, flags = self.invoke(+ 1,+ json.dumps(report(findings=True)),+ workflow=workflow,+ release_policy=True,+ )+ self.assertEqual(+ result.returncode, 0, result.stdout + result.stderr+ )+ self.assertEqual(flags, "scan_complete=true\n")+ self.assertTrue(self.output.is_file())++ def test_release_mode_never_turns_native_errors_into_findings(self):+ for status, payload, write in (+ (2, json.dumps(report()), True),+ (0, "invalid", True),+ (0, json.dumps(report()), False),+ ):+ with self.subTest(status=status, payload=payload, write=write):+ result, flags = self.invoke(+ status, payload, write, release_policy=True+ )+ self.assertNotEqual(result.returncode, 0)+ self.assertNotIn("scan_complete=true", flags)+ self.assertFalse(self.output.exists())++ def test_release_mode_cannot_combine_with_a_pr_baseline(self):+ result, flags = self.invoke(+ release_policy=True, baseline=(0, json.dumps(report()))+ )+ self.assertEqual(result.returncode, 2)+ self.assertNotIn("scan_complete=true", flags)+def test_missing_report_is_rejected_even_after_success(self):self.assert_rejected(write=False)diff --git a/tests/ci/standalone/test_release_scan_checkov_upload.py b/tests/ci/standalone/test_release_scan_checkov_upload.pyindex 08e5c50e4e..47ea1976c1 100644--- a/tests/ci/standalone/test_release_scan_checkov_upload.py+++ b/tests/ci/standalone/test_release_scan_checkov_upload.py@@ -355,9 +355,21 @@ class WorkflowContractTests(unittest.TestCase):"retry: ${{ steps.workflow-analysis.outputs.retry }}", self.text)- def test_existing_scanner_strictness_and_release_policy_are_unchanged(self):+ def test_scanner_is_strict_by_default_and_defers_release_finding_age(self):scan = self.steps["Run Checkov on GitHub Actions workflows"]- self.assertNotIn("--soft-fail", scan)+ self.assertIn(+ 'if [ "$RELEASE_POLICY" = true ]; then args+=(--soft-fail); fi',+ scan,+ )+ self.assertIn('checkov "${args[@]}"', scan)+ self.assertIn(+ "release_native_reports.py checkov --input checkov-workflows.json",+ scan,+ )+ self.assertIn(+ "release_policy:\n type: boolean\n default: false",+ self.text,+ )self.assertIn("--framework github_actions", scan)self.assertIn("--skip-check CKV_GHA_7", scan)policy = json.loads(diff --git a/tests/ci/standalone/test_release_scan_evidence.py b/tests/ci/standalone/test_release_scan_evidence.pyindex 98310c5074..9fdaf34709 100644--- a/tests/ci/standalone/test_release_scan_evidence.py+++ b/tests/ci/standalone/test_release_scan_evidence.py@@ -45,13 +45,19 @@ def analysis(**changes):def alert(**changes):- return {+ record = {"number": 1,"state": "open","tool": {"name": "CodeQL"},"rule": {"security_severity_level": "critical", "severity": None},**changes,}+ record["rule"].setdefault("id", "SAMPLE_RULE")+ record.setdefault(+ "most_recent_instance",+ {"location": {"path": "sample.py", "start_line": 1}},+ )+ return record# --- R3: tie release-scan-policy.json to what release-gate.yml actually@@ -185,6 +191,17 @@ def _sarif_categories_in(text, source="workflow"):def _expand_matrix_language(category, workflow_text):+ if "matrix.python" in category:+ legs = re.findall(+ r"- python: ['\"]([0-9.]+)['\"]\s+distribution: (\w+)",+ workflow_text,+ )+ return [+ category.replace("${{ matrix.python }}", version).replace(+ "${{ matrix.distribution }}", distribution+ )+ for version, distribution in legs+ ] or [category]if "matrix.language" not in category:return [category]languages = re.findall(@@ -208,7 +225,11 @@ def _release_gate_sarif_categories():gate_text = (ROOT / ".github/workflows/release-gate.yml").read_text(encoding="utf-8")- categories = set()+ categories = {+ category+ for raw in _sarif_categories_in(gate_text)+ for category in _expand_matrix_language(raw, gate_text)+ }pending = list(_local_reusable_workflow_jobs(gate_text).items())visited = set()while pending:@@ -516,14 +537,11 @@ class EvidenceTests(unittest.TestCase):with patch.object(POLICY, "evaluate", return_value=None):self.assertEqual(POLICY.main(), 0)- def test_main_reports_truncated_redacted_gh_stderr_on_called_process_error(- self,- ):- """R5: gh's stderr must reach the failure log (truncated, and with- any token-shaped substring redacted).- """+ def test_main_reports_status_without_native_private_diagnostics(self):token = "ghp_" + "a" * 40- stderr = f"error: {token} invalid, and " + ("z" * 600)+ stderr = f"HTTP 403: {token} SYNTHETIC_PRIVATE_DIAGNOSTIC " + (+ "z" * 600+ )exc = subprocess.CalledProcessError(1, ["gh", "api", "x"], output="", stderr=stderr)@@ -534,9 +552,9 @@ class EvidenceTests(unittest.TestCase):):self.assertEqual(POLICY.main(), 1)output = buffer.getvalue()- self.assertIn("gh stderr:", output)+ self.assertIn("HTTP 403", output)self.assertNotIn(token, output)- self.assertIn("[REDACTED]", output)+ self.assertNotIn("SYNTHETIC_PRIVATE_DIAGNOSTIC", output)self.assertNotIn("z" * 600, output)def test_main_escapes_untrusted_text_in_the_failure_annotation(self):@@ -551,8 +569,8 @@ class EvidenceTests(unittest.TestCase):1, ["gh", "api", "x"], output="", stderr="403\r\n::warning::x")for exc, escaped in (- (caught.exception, "(Grype%0A::add-mask::deadbeef 100%25)"),- (api_error, "gh stderr: 403%0D%0A::warning::x"),+ (caught.exception, "policy or context validation failed"),+ (api_error, "API request failed"),):with self.subTest(exc=type(exc).__name__):buffer = io.StringIO()diff --git a/tests/ci/test_release_deadline.py b/tests/ci/test_release_deadline.pyindex 638c4f0223..fdb08b28d7 100644--- a/tests/ci/test_release_deadline.py+++ b/tests/ci/test_release_deadline.py@@ -60,7 +60,7 @@ def test_approval_and_rerun_time_is_checked_in_utc(instant, allowed):"None","0","20261013",- "2026-10-13T00:00:00Z",+ "2026-10-13T00:00:00","*","none\n",],@@ -108,7 +108,12 @@ def test_original_deadline_reaches_every_publication_path():"${{ needs.release-gate.outputs.release_deadline }}")for caller in ("prerelease-docker", "publish-docker"):- assert jobs[caller]["with"]["release_deadline"] == BUILD_DEADLINE+ expected = (+ BUILD_DEADLINE+ if caller == "prerelease-docker"+ else "${{ needs.prerelease-docker.outputs.release_deadline }}"+ )+ assert jobs[caller]["with"]["release_deadline"] == expectedcalled_name = jobs[caller]["uses"].split("/")[-1].removesuffix(".yml")contract = workflow(called_name)[True]["workflow_call"]["inputs"]["release_deadline"@@ -240,6 +245,9 @@ def test_pypi_checks_after_its_own_approval_and_before_both_upload_targets():("tomorrow", True),("today", False),("yesterday", False),+ ("future-timestamp", True),+ ("expired-timestamp", False),+ ("2026-10-30T12:00:00", False),("", False),("null", False),("20261013", False),@@ -255,6 +263,11 @@ def test_pypi_executes_its_guard_without_checkout(tmp_path, value, allowed):}if value in relative:value = relative[value].isoformat()+ if value in {"future-timestamp", "expired-timestamp"}:+ instant = datetime.now(timezone.utc) + timedelta(+ hours=1 if value == "future-timestamp" else -1+ )+ value = instant.isoformat().replace("+00:00", "Z")guard = step_named(workflow("publish")["jobs"]["publish"],"Check release exception deadline before publishing",@@ -300,8 +313,18 @@ def test_tag_publication_is_guarded_after_approval(assert job["environment"] == "release"publish = step_named(job, step_name)assert not publish.get("continue-on-error")- expected = BUILD_DEADLINE if workflow_name == "release" else INPUT_DEADLINE+ expected = (+ "${{ needs.publish-docker.outputs.release_deadline }}"+ if workflow_name == "release"+ else "${{ steps.native-deadline.outputs.release_deadline }}"+ )assert publish["env"]["RELEASE_DEADLINE"] == expected+ if workflow_name != "release":+ bind = next(s for s in job["steps"] if s.get("id") == "native-deadline")+ assert bind["env"]["RELEASE_DEADLINE"] == INPUT_DEADLINE+ assert "--additional-deadline" in bind["run"]+ assert "--write-output" in bind["run"]+ assert job["steps"].index(bind) < job["steps"].index(publish)run = publish["run"]assert run.index(GUARD) < run.index(publish_command)assert run.count(GUARD) == run.count(publish_command)diff --git a/tests/ci/test_release_finding_grace.py b/tests/ci/test_release_finding_grace.pynew file mode 100644index 0000000000..0ee42186a6--- /dev/null+++ b/tests/ci/test_release_finding_grace.py@@ -0,0 +1,1085 @@+"""Age, visibility and native-report contracts for release findings."""++# allow: no-sut-import — the SUTs are standalone release policy scripts.++from copy import deepcopy+from datetime import datetime, timedelta, timezone+import importlib.util+import json+from pathlib import Path+import sys+from urllib.parse import parse_qs, urlsplit++import pytest+++SCRIPTS = Path(__file__).resolve().parents[2] / ".github/scripts"+NOW = datetime(2026, 10, 29, 12, tzinfo=timezone.utc)+++def load(name):+ spec = importlib.util.spec_from_file_location(name, SCRIPTS / f"{name}.py")+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ return module+++gate = load("check_code_scanning_alerts")+deadline = load("check_release_deadline")+native = load("check_release_report_age")+reports = load("release_native_reports")+evidence = load("check_release_scan_evidence")+++def alert(age=timedelta(days=1), severity="high", *, state="open", number=1):+ return {+ "number": number,+ "state": state,+ "created_at": (NOW - age).isoformat(),+ "rule": {+ "id": "CVE-2099-0001",+ "security_severity_level": severity,+ "severity": "warning",+ },+ "tool": {"name": "sample-scanner"},+ "most_recent_instance": {+ "category": "sample",+ "location": {"path": "package-lock.json", "start_line": 1},+ },+ }++[email protected]("severity", ["high", "medium", None])+ "age,allowed",+ [+ (timedelta(days=14, microseconds=-1), True),+ (timedelta(days=14), False),+ (timedelta(days=15), False),+ ],+)+def test_noncritical_findings_have_one_exact_window(severity, age, allowed):+ item = alert(age, severity)+ before = deepcopy(item)+ candidates, _, _ = gate.classify_alerts([item], {}, NOW.date())+ blocking, graced = gate.apply_grace(candidates, NOW)+ assert bool(graced) == allowed+ assert bool(blocking) != allowed+ assert item == before and item["state"] == "open"+++def test_critical_has_no_automatic_grace():+ item = alert(timedelta(seconds=1), "critical")+ assert gate.apply_grace([item], NOW) == ([item], [])+++def test_critical_cannot_use_an_explicit_exception_either():+ item = alert(severity="critical")+ entry = {+ "alert_number": 1,+ "rule_id": item["rule"]["id"],+ "tool": "sample-scanner",+ "category": "sample",+ "path": "package-lock.json",+ "severity": "critical",+ "expires_on": "2099-01-01",+ }+ assert gate.classify_alerts([item], {1: entry}, NOW.date()) == (+ [item],+ [],+ [],+ )+++ "severity,level", [("low", "error"), (None, "note"), (None, "none")]+)+def test_advisory_findings_stay_advisory(severity, level):+ item = alert(timedelta(days=100), severity)+ item["rule"]["severity"] = level+ assert gate.classify_alerts([item], {}, NOW.date()) == ([], [], [])+++ "created",+ [+ None,+ "",+ "invalid",+ "2026-10-28",+ "2026-10-28T12:00:00",+ "2026-10-30T12:00:00Z",+ ],+)+def test_unprovable_or_future_age_cannot_grant_time(created):+ item = alert()+ item["created_at"] = created+ assert gate.apply_grace([item], NOW) == ([item], [])+++def test_reruns_reopens_and_image_paths_do_not_reset_a_vulnerability_clock():+ current = alert(number=2)+ current["updated_at"] = NOW.isoformat()+ current["most_recent_instance"]["location"]["path"] = "image-b/Python"+ previous = alert(timedelta(days=20), state="fixed")+ original = deepcopy(current)+ aged = gate.retain_first_detection([current], [previous])+ assert gate.apply_grace(aged, NOW) == (aged, [])+ assert current == original+++def test_invalid_old_history_is_not_discarded_to_extend_grace():+ current = alert()+ previous = alert(state="dismissed", number=2)+ previous["created_at"] = None+ aged = gate.retain_first_detection([current], [previous])+ assert gate.apply_grace(aged, NOW) == (aged, [])+++def test_an_expired_explicit_exception_cannot_restart_as_automatic_grace():+ item = alert()+ assert gate.apply_grace([item], NOW, expired=[1]) == ([item], [])+++def test_the_exact_expiry_is_carried_across_disappearing_alerts_and_approval():+ item = alert(timedelta(days=13))+ expiry = gate.publication_deadline([], {}, [item])+ assert expiry == "2026-10-30T12:00:00Z"+ assert gate.earliest_deadline(expiry, "none", NOW) == expiry+ deadline.check_deadline(+ expiry, datetime(2026, 10, 30, 11, 59, 59, tzinfo=timezone.utc)+ )+ with pytest.raises(ValueError, match="expired"):+ deadline.check_deadline(+ expiry, datetime(2026, 10, 30, 12, tzinfo=timezone.utc)+ )+++def test_legacy_exception_dates_and_exact_grace_timestamps_choose_the_earliest():+ assert (+ gate.earliest_deadline("2026-10-30", "2026-10-30T12:00:00Z", NOW)+ == "2026-10-30"+ )+ assert (+ gate.earliest_deadline("2026-10-31", "2026-10-30T12:00:00Z", NOW)+ == "2026-10-30T12:00:00Z"+ )+++def report(severity="high"):+ return reports.sarif(+ "sample-scanner", [("CVE-2099-0001", severity, "package-lock.json")]+ )+++def test_native_critical_blocks_without_waiting_for_history():+ def forbidden(*args):+ pytest.fail(+ "Critical findings must not consult history for a grace period"+ )++ with pytest.raises(ValueError, match="Critical"):+ native.evaluate(+ report("critical"),+ Path.cwd(),+ "example/project",+ now=NOW,+ fetch=forbidden,+ )+++def test_native_empty_report_needs_no_history():+ def forbidden(*args):+ pytest.fail("Empty complete reports have no grace decision")++ assert native.evaluate(+ reports.sarif("sample-scanner", []),+ Path.cwd(),+ "example/project",+ now=NOW,+ fetch=forbidden,+ ) == ("none", 0)+++def test_native_findings_use_persisted_first_detection():+ calls = []++ def fetch(repository, state):+ calls.append((repository, state))+ return [alert()] if state == "open" else []++ assert native.evaluate(+ report(), Path.cwd(), "example/project", now=NOW, fetch=fetch+ ) == ("2026-11-11T12:00:00Z", 1)+ assert calls == [+ ("example/project", state) for state in ("open", "fixed", "dismissed")+ ]+++def test_native_history_must_be_indexed_and_cannot_be_replaced_with_now():+ sleeps = []+ with pytest.raises(ValueError, match="first-detection"):+ native.evaluate(+ report(),+ Path.cwd(),+ "example/project",+ now=NOW,+ fetch=lambda *args: [],+ sleep=sleeps.append,+ )+ assert sleeps == [5] * 6+++def test_native_index_retry_refreshes_cached_history():+ ready = False++ def refresh():+ nonlocal ready+ ready = True++ assert (+ native.evaluate(+ report(),+ Path.cwd(),+ "example/project",+ now=NOW,+ fetch=lambda _, state: (+ [alert()] if ready and state == "open" else []+ ),+ refresh=refresh,+ sleep=lambda _: None,+ )[1]+ == 1+ )++[email protected]("score", [True, False, "NaN", "inf", -1, 11])+def test_native_invalid_security_scores_cannot_reduce_a_finding(score):+ data = report()+ data["runs"][0]["tool"]["driver"]["rules"][0]["properties"][+ "security-severity"+ ] = score+ with pytest.raises(ValueError, match="score"):+ native.report_findings(data, Path.cwd())+++def test_result_metadata_cannot_reduce_a_critical_rule_score():+ data = report("critical")+ data["runs"][0]["results"][0]["properties"] = {"security-severity": "2.0"}+ with pytest.raises(ValueError, match="Critical"):+ native.evaluate(data, Path.cwd(), "example/project", now=NOW)+++def test_zero_security_score_retains_native_sarif_level():+ data = report()+ data["runs"][0]["tool"]["driver"]["rules"][0]["properties"][+ "security-severity"+ ] = "0.0"+ finding = native.report_findings(data, Path.cwd())[0]+ assert finding["rule"]["security_severity_level"] is None+ assert gate.blocking_severity(finding)+++def test_native_reopened_old_finding_blocks():+ def fetch(repository, state):+ return (+ [alert(timedelta(days=20), state="fixed")]+ if state == "fixed"+ else []+ )++ with pytest.raises(ValueError, match="14-day"):+ native.evaluate(+ report(), Path.cwd(), "example/project", now=NOW, fetch=fetch+ )+++def test_native_noncritical_score_cannot_hide_an_indexed_critical_alert():+ # The native report scores the finding high (< 9), but GitHub's open+ # alert for the same scanner/advisory key is critical: no grace applies,+ # even though the recorded first detection is only one day old.+ def fetch(repository, state):+ return [alert(severity="critical")] if state == "open" else []++ with pytest.raises(ValueError, match="Critical indexed"):+ native.evaluate(+ report("high"), Path.cwd(), "example/project", now=NOW, fetch=fetch+ )+++def test_native_first_detection_ignores_non_blocking_history_order():+ # A low-scored record for the same advisory key listed first must not+ # break the first-detection lookup; the earliest date still applies.+ def fetch(repository, state):+ if state == "open":+ return [+ alert(timedelta(days=2), severity="low", number=2),+ alert(timedelta(days=1)),+ ]+ return []++ assert native.evaluate(+ report(), Path.cwd(), "example/project", now=NOW, fetch=fetch+ ) == ("2026-11-10T12:00:00Z", 1)+++def test_native_first_detection_with_only_non_blocking_history():+ def fetch(repository, state):+ return [alert(severity="low")] if state == "open" else []++ assert native.evaluate(+ report(), Path.cwd(), "example/project", now=NOW, fetch=fetch+ ) == ("2026-11-11T12:00:00Z", 1)+++def test_an_incomplete_scan_never_becomes_a_clean_report():+ data = reports.sarif("sample-scanner", [])+ data["runs"][0]["invocations"][0]["executionSuccessful"] = False+ with pytest.raises(ValueError, match="complete"):+ native.report_findings(data, Path.cwd())+++ "data",+ [+ {},+ {"error": "synthetic diagnostic"},+ {"auditReportVersion": 2},+ {"auditReportVersion": 2, "vulnerabilities": {}, "error": {}},+ ],+)+def test_npm_operational_failures_are_not_findings(data):+ with pytest.raises(ValueError):+ reports.npm_findings(data, "package-lock.json")+++def test_npm_transitive_findings_keep_critical_severity_and_stable_identity():+ data = {+ "auditReportVersion": 2,+ "vulnerabilities": {+ "parent": {"severity": "critical", "via": ["child"]},+ "child": {+ "severity": "high",+ "via": [+ {+ "url": "https://github.com/advisories/GHSA-aaaa-bbbb-cccc",+ "severity": "high",+ }+ ],+ },+ },+ "metadata": {+ "vulnerabilities": {+ "info": 0,+ "low": 0,+ "moderate": 0,+ "high": 1,+ "critical": 1,+ "total": 2,+ }+ },+ }+ rows = reports.npm_findings(data, "package-lock.json")+ assert ("GHSA-aaaa-bbbb-cccc", "critical", "package-lock.json") in rows+ assert len(rows) == 2+++def test_zap_report_discards_http_samples_and_tracks_only_plugin_identity():+ data = {+ "@version": "2.17.0",+ "site": [+ {+ "alerts": [+ {+ "pluginid": "10001",+ "riskcode": "2",+ "instances": [{"evidence": "SYNTHETIC_PRIVATE_MARKER"}],+ }+ ]+ }+ ],+ }+ generated = reports.zap_report(data)+ assert "SYNTHETIC_PRIVATE_MARKER" not in str(generated)+ assert generated["runs"][0]["results"][0]["ruleId"] == "ZAP-10001"+++ "data",+ [+ {},+ {"@version": "2", "site": []},+ {"@version": "2", "site": [{"alerts": "invalid"}]},+ ],+)+def test_zap_missing_or_malformed_targets_fail(data):+ with pytest.raises(ValueError):+ reports.zap_report(data)+++def test_checkov_parsing_errors_remain_fatal():+ with pytest.raises(ValueError, match="parsing"):+ reports.validate_checkov(+ {+ "summary": {"parsing_errors": 1},+ "results": {"parsing_errors": ["synthetic"]},+ }+ )+ reports.validate_checkov(+ {"summary": {"parsing_errors": 0}, "results": {"parsing_errors": []}}+ )+++ "old_default_history,allowed", [(False, True), (True, False)]+)+def test_fresh_release_ref_uses_original_default_branch_history(+ monkeypatch, tmp_path, old_default_history, allowed+):+ class Clock(datetime):+ @classmethod+ def now(cls, tz=None):+ return NOW++ monkeypatch.setattr(evidence, "datetime", Clock)+ repo, sha, ref = "example/project", "a" * 40, "refs/tags/v1.0.0"+ for key, value in {+ "GITHUB_REPOSITORY": repo,+ "GITHUB_SHA": sha,+ "GITHUB_REF": ref,+ "GITHUB_RUN_ID": "1",+ "GITHUB_STEP_SUMMARY": str(tmp_path / "summary"),+ "GITHUB_OUTPUT": str(tmp_path / "output"),+ }.items():+ monkeypatch.setenv(key, value)+ expected = json.loads(+ (SCRIPTS.parent / "release-scan-policy.json").read_text(+ encoding="utf-8"+ )+ )+ calls = []++ def fetch(endpoint):+ calls.append(endpoint)+ if "/actions/runs/" in endpoint:+ return {+ "head_sha": sha,+ "created_at": NOW.isoformat(),+ "path": ".github/workflows/release.yml",+ }+ if "/analyses?" in endpoint:+ return [+ {+ "category": category,+ "commit_sha": sha,+ "ref": ref,+ "analysis_key": f".github/workflows/release.yml:{job}",+ "created_at": NOW.isoformat(),+ "error": "",+ "results_count": 1,+ }+ for category, job in expected.items()+ ]+ query = parse_qs(urlsplit(endpoint).query)+ if query["state"] == ["open"] and "ref" in query:+ return [alert()]+ if (+ query["state"] == ["fixed"]+ and "ref" not in query+ and old_default_history+ ):+ return [alert(timedelta(days=20), state="fixed", number=2)]+ return []++ if allowed:+ evidence.evaluate(fetch=fetch)+ assert (tmp_path / "output").read_text(+ encoding="utf-8"+ ) == "release_deadline=2026-11-11T12:00:00Z\n"+ else:+ with pytest.raises(ValueError, match="blocking code-scanning"):+ evidence.evaluate(fetch=fetch)+ assert not (tmp_path / "output").exists()+ assert any("state=fixed" in call and "ref=" not in call for call in calls)++[email protected]("expire_during_lookup", [False, True])+def test_native_cli_binds_current_ref_and_does_not_emit_an_expired_decision(+ monkeypatch, tmp_path, expire_during_lookup+):+ class Clock(datetime):+ calls = 0++ @classmethod+ def now(cls, tz=None):+ cls.calls += 1+ return NOW + (+ timedelta(seconds=2)+ if expire_during_lookup and cls.calls > 1+ else timedelta()+ )++ monkeypatch.setattr(native, "datetime", Clock)+ monkeypatch.setattr(native, "policy_module", lambda: gate)+ upload = "11111111-1111-4111-8111-111111111111"+ repo, sha, ref = "example/project", "a" * 40, "refs/tags/v1.0.0"+ values = {+ "GITHUB_REPOSITORY": repo,+ "GITHUB_SHA": sha,+ "GITHUB_REF": ref,+ "GITHUB_JOB": "sample",+ "GITHUB_WORKFLOW_REF": repo + "/.github/workflows/release.yml@" + ref,+ "GITHUB_OUTPUT": str(tmp_path / "output"),+ }+ for key, value in values.items():+ monkeypatch.setenv(key, value)+ path = tmp_path / "native.sarif"+ path.write_text(json.dumps(report()), encoding="utf-8")+ monkeypatch.setattr(+ sys,+ "argv",+ [+ "policy",+ "--report",+ str(path),+ "--sarif-id",+ upload,+ "--category",+ "sample-release",+ ],+ )+ original = native.verify_upload++ def api(endpoint):+ if "/sarifs/" in endpoint:+ return {"processing_status": "complete"}+ return [+ {+ "sarif_id": upload,+ "commit_sha": sha,+ "ref": ref,+ "analysis_key": ".github/workflows/release.yml:sample",+ "category": "sample-release",+ "tool": {"name": "sample-scanner"},+ "error": "",+ "results_count": 1,+ }+ ]++ monkeypatch.setattr(+ native, "verify_upload", lambda *args: original(*args, fetch=api)+ )+ calls = []++ def history(repository, state, ref=None, tool_name=None):+ calls.append((repository, state, ref, tool_name))+ return (+ [alert(timedelta(days=14, seconds=-1))]+ if state == "open" and ref == values["GITHUB_REF"]+ else []+ )++ monkeypatch.setattr(gate, "fetch_alerts", history)+ assert native.main() == int(expire_during_lookup)+ assert (tmp_path / "output").exists() != expire_during_lookup+ assert {call[2] for call in calls} == {None, values["GITHUB_REF"]}+ if not expire_during_lookup:+ assert (tmp_path / "output").read_text(+ encoding="utf-8"+ ) == "release_deadline=2026-10-29T12:00:01Z\n"+++class FrozenClock(datetime):+ @classmethod+ def now(cls, tz=None):+ return NOW+++def post_gate_alert(category, *, latest_state="open", age=timedelta(days=20)):+ record = alert(age)+ record["most_recent_instance"] = {+ **record["most_recent_instance"],+ "category": category,+ "state": latest_state,+ }+ return record+++def test_gate_ignores_alerts_open_only_in_post_gate_publication_categories():+ lookups = []++ def instances(rows):+ def fetch(number):+ lookups.append(number)+ return rows++ return fetch++ only_prerelease = [{"state": "open", "category": "trivy-prerelease"}]+ assert (+ gate.gate_alerts(+ [post_gate_alert("trivy-prerelease")], instances(only_prerelease)+ )+ == []+ )+ # Fixed in the gate-time scan, still open only after publication.+ assert (+ gate.gate_alerts(+ [post_gate_alert("container-security", latest_state="fixed")],+ instances(+ [+ {"state": "fixed", "category": "container-security"},+ {"state": "open", "category": "trivy-promotion"},+ ]+ ),+ )+ == []+ )+ # Still open in a gate-time category: it keeps blocking.+ mixed = [+ {"state": "open", "category": "trivy-promotion"},+ {"state": "open", "category": "container-security"},+ ]+ assert (+ len(+ gate.gate_alerts(+ [post_gate_alert("trivy-promotion")], instances(mixed)+ )+ )+ == 1+ )+ # Unprovable instance data stays in the blocking set.+ assert (+ len(+ gate.gate_alerts(+ [post_gate_alert("trivy-prerelease")], instances([])+ )+ )+ == 1+ )+ lookups.clear()+ assert (+ len(+ gate.gate_alerts(+ [post_gate_alert("container-security")],+ instances(only_prerelease),+ )+ )+ == 1+ )+ assert lookups == []+++ "category,allowed",+ [+ ("trivy-prerelease", True),+ ("trivy-promotion", True),+ ("container-security", False),+ ],+)+def test_release_evidence_cannot_deadlock_on_stale_post_gate_alerts(+ monkeypatch, tmp_path, category, allowed+):+ class Clock(datetime):+ @classmethod+ def now(cls, tz=None):+ return NOW++ monkeypatch.setattr(evidence, "datetime", Clock)+ repo, sha, ref = "example/project", "a" * 40, "refs/heads/main"+ for key, value in {+ "GITHUB_REPOSITORY": repo,+ "GITHUB_SHA": sha,+ "GITHUB_REF": ref,+ "GITHUB_RUN_ID": "1",+ "GITHUB_STEP_SUMMARY": str(tmp_path / "summary"),+ "GITHUB_OUTPUT": str(tmp_path / "output"),+ }.items():+ monkeypatch.setenv(key, value)+ expected = json.loads(+ (SCRIPTS.parent / "release-scan-policy.json").read_text(+ encoding="utf-8"+ )+ )++ def fetch(endpoint):+ if "/actions/runs/" in endpoint:+ return {+ "head_sha": sha,+ "created_at": NOW.isoformat(),+ "path": ".github/workflows/release.yml",+ }+ if "/analyses?" in endpoint:+ return [+ {+ "category": name,+ "commit_sha": sha,+ "ref": ref,+ "analysis_key": f".github/workflows/release.yml:{job}",+ "created_at": NOW.isoformat(),+ "error": "",+ "results_count": 1,+ }+ for name, job in expected.items()+ ]+ if "/instances?" in endpoint:+ query = parse_qs(urlsplit(endpoint).query)+ instance_refs.append(query.get("ref"))+ rows = [+ {"state": "open", "category": category, "ref": ref},+ # A stale gate-time row on another ref must not count.+ {+ "state": "open",+ "category": "container-security",+ "ref": "refs/heads/release/rehearsal",+ },+ ]+ return (+ [r for r in rows if r["ref"] in query.get("ref", [r["ref"]])]+ if query["page"] == ["1"]+ else []+ )+ query = parse_qs(urlsplit(endpoint).query)+ if query["state"] == ["open"] and "ref" in query:+ return [post_gate_alert(category)]+ return []++ instance_refs = []+ if allowed:+ evidence.evaluate(fetch=fetch)+ assert (tmp_path / "output").read_text(+ encoding="utf-8"+ ) == "release_deadline=none\n"+ assert instance_refs and all(r == [ref] for r in instance_refs)+ else:+ with pytest.raises(ValueError, match="blocking code-scanning"):+ evidence.evaluate(fetch=fetch)+++ "category,status",+ [+ ("trivy-prerelease", 0),+ ("trivy-promotion", 0),+ ("container-security", 1),+ ],+)+def test_final_alert_check_ignores_stale_post_gate_alerts(+ monkeypatch, tmp_path, category, status+):+ policy = tmp_path / "exceptions.json"+ policy.write_text(+ json.dumps(+ {"version": 1, "repository": "example/project", "exceptions": []}+ ),+ encoding="utf-8",+ )+ monkeypatch.setattr(+ gate,+ "fetch_alerts",+ lambda repository, state="open", ref=None, tool_name=None: (+ [post_gate_alert(category)] if state == "open" else []+ ),+ )+ rows = [+ {"ref": "refs/heads/main", "category": category, "state": "open"},+ {+ "ref": "refs/heads/main",+ "category": "container-security",+ "state": "fixed",+ },+ # Stale gate-time rows on a tag and a rehearsal branch.+ {+ "ref": "refs/tags/v1.0.0",+ "category": "container-security",+ "state": "open",+ },+ {+ "ref": "refs/heads/release/v1.0.0-rehearsal",+ "category": "container-security",+ "state": "open",+ },+ ]+ monkeypatch.setattr(+ gate,+ "fetch_instances",+ lambda repository, number, ref=None: [+ row for row in rows if ref is None or row["ref"] == ref+ ],+ )+ event = tmp_path / "event.json"+ event.write_text(+ json.dumps({"repository": {"default_branch": "main"}}),+ encoding="utf-8",+ )+ monkeypatch.setenv("GITHUB_EVENT_PATH", str(event))+ monkeypatch.delenv("GITHUB_STEP_SUMMARY", raising=False)+ monkeypatch.delenv("GITHUB_OUTPUT", raising=False)+ monkeypatch.setattr(+ sys,+ "argv",+ [+ "check_code_scanning_alerts.py",+ "--repository",+ "example/project",+ "--exceptions",+ str(policy),+ "--evidence-deadline",+ "none",+ ],+ )+ assert gate.main() == status+++def test_unprovable_instance_state_keeps_an_alert_blocking():+ for state in (None, "OPEN", "unknown"):+ row = {"category": "container-security"}+ if state is not None:+ row["state"] = state+ rows = [{"state": "open", "category": "trivy-prerelease"}, row]+ assert (+ len(+ gate.gate_alerts(+ [post_gate_alert("trivy-prerelease")], lambda _: rows+ )+ )+ == 1+ ), state+ closed = [+ {"state": "open", "category": "trivy-prerelease"},+ {"state": "dismissed", "category": "container-security"},+ ]+ assert (+ gate.gate_alerts(+ [post_gate_alert("trivy-prerelease")], lambda _: closed+ )+ == []+ )+++def test_fetch_instances_reads_only_the_requested_ref(monkeypatch):+ urls = []++ def run(argv, **kwargs):+ urls.append(argv[-1])+ page = parse_qs(urlsplit(argv[-1]).query)["page"]+ rows = [+ {"ref": "refs/heads/main", "state": "open"},+ {"ref": "refs/tags/v1.0.0", "state": "open"},+ ]+ return type(+ "Done", (), {"stdout": json.dumps(rows if page == ["1"] else [])}+ )++ monkeypatch.setattr(gate.subprocess, "run", run)+ rows = gate.fetch_instances("example/project", 7, ref="refs/heads/main")+ assert rows == [{"ref": "refs/heads/main", "state": "open"}]+ assert parse_qs(urlsplit(urls[0]).query)["ref"] == ["refs/heads/main"]+++def test_excluded_post_gate_alerts_still_back_date_the_same_finding(+ monkeypatch, tmp_path+):+ """A gate-time alert for the same advisory inherits the earlier detection+ of an alert the gate then excludes as post-gate only."""+ policy = tmp_path / "exceptions.json"+ policy.write_text(+ json.dumps(+ {"version": 1, "repository": "example/project", "exceptions": []}+ ),+ encoding="utf-8",+ )+ stale = post_gate_alert("trivy-prerelease")+ current = post_gate_alert("container-security", age=timedelta(days=1))+ current["number"] = 2+ current["most_recent_instance"]["location"] = {+ "path": "another/image/path",+ "start_line": 1,+ }+ monkeypatch.setattr(+ gate,+ "fetch_alerts",+ lambda repository, state="open", ref=None, tool_name=None: (+ [stale, current] if state == "open" else []+ ),+ )+ monkeypatch.setattr(+ gate,+ "fetch_instances",+ lambda repository, number, ref=None: [+ {"ref": ref, "category": "trivy-prerelease", "state": "open"}+ ],+ )+ monkeypatch.setattr(+ gate, "default_branch_ref", lambda repository: "refs/heads/main"+ )+ # Pin the clock: the unordered variant must grace the 1-day alert.+ monkeypatch.setattr(gate, "datetime", FrozenClock)+ monkeypatch.delenv("GITHUB_STEP_SUMMARY", raising=False)+ monkeypatch.delenv("GITHUB_OUTPUT", raising=False)+ monkeypatch.setattr(+ sys,+ "argv",+ [+ "check_code_scanning_alerts.py",+ "--repository",+ "example/project",+ "--exceptions",+ str(policy),+ "--evidence-deadline",+ "none",+ ],+ )+ # Back-dated to 20 days, the gate-time alert is past its window.+ assert gate.main() == 1+++def test_open_advisory_alerts_back_date_a_later_blocking_finding():+ # An open low alert for the same advisory proves the earlier detection.+ earlier = alert(timedelta(days=20), severity="low", number=2)+ retained = gate.retain_first_detection([alert(), earlier], [])+ assert retained[0]["first_detected_at"] == NOW - timedelta(days=20)+++def test_final_check_back_dates_from_fixed_history(monkeypatch, tmp_path):+ """main() must fetch fixed history for a graced tool and inherit its+ earlier detection: 10 days ago, not the reopened alert's 1 day."""+ policy = tmp_path / "exceptions.json"+ policy.write_text(+ json.dumps(+ {"version": 1, "repository": "example/project", "exceptions": []}+ ),+ encoding="utf-8",+ )+ history_calls = []++ def fetch_alerts(repository, state="open", ref=None, tool_name=None):+ if state == "open":+ return [alert()]+ history_calls.append((state, tool_name))+ if state == "fixed" and tool_name == "sample-scanner":+ return [alert(timedelta(days=10), state="fixed", number=2)]+ return []++ monkeypatch.setattr(gate, "fetch_alerts", fetch_alerts)+ monkeypatch.setattr(gate, "datetime", FrozenClock)+ output = tmp_path / "output"+ monkeypatch.setenv("GITHUB_OUTPUT", str(output))+ monkeypatch.delenv("GITHUB_STEP_SUMMARY", raising=False)+ monkeypatch.setattr(+ sys,+ "argv",+ [+ "check_code_scanning_alerts.py",+ "--repository",+ "example/project",+ "--exceptions",+ str(policy),+ "--evidence-deadline",+ "none",+ ],+ )+ assert gate.main() == 0+ assert ("fixed", "sample-scanner") in history_calls+ assert "release_deadline=2026-11-02T12:00:00Z\n" in output.read_text(+ encoding="utf-8"+ )+++def test_publication_deadline_uses_first_detection_over_created_at():+ graced = {**alert(), "first_detected_at": NOW - timedelta(days=10)}+ assert gate.publication_deadline([], {}, [graced]) == (+ "2026-11-02T12:00:00Z"+ )+ assert gate.publication_deadline([], {}, [alert()]) == (+ "2026-11-11T12:00:00Z"+ )+++def _tag_evidence(monkeypatch, tmp_path, open_on_ref, open_default, rows):+ """Run the evidence check for a tag release (not the default branch)."""+ monkeypatch.setattr(evidence, "datetime", FrozenClock)+ sha, ref = "a" * 40, "refs/tags/v1.0.0"+ for key, value in {+ "GITHUB_REPOSITORY": "example/project",+ "GITHUB_SHA": sha,+ "GITHUB_REF": ref,+ "GITHUB_RUN_ID": "1",+ "GITHUB_STEP_SUMMARY": str(tmp_path / "summary"),+ "GITHUB_OUTPUT": str(tmp_path / "output"),+ }.items():+ monkeypatch.setenv(key, value)+ expected = json.loads(+ (SCRIPTS.parent / "release-scan-policy.json").read_text(+ encoding="utf-8"+ )+ )++ def fetch(endpoint):+ if "/actions/runs/" in endpoint:+ return {+ "head_sha": sha,+ "created_at": NOW.isoformat(),+ "path": ".github/workflows/release.yml",+ }+ if "/analyses?" in endpoint:+ return [+ {+ "category": name,+ "commit_sha": sha,+ "ref": ref,+ "analysis_key": f".github/workflows/release.yml:{job}",+ "created_at": NOW.isoformat(),+ "error": "",+ "results_count": 1,+ }+ for name, job in expected.items()+ ]+ query = parse_qs(urlsplit(endpoint).query)+ if query["page"] != ["1"]:+ return []+ if "/instances?" in endpoint:+ assert query["ref"] == [ref]+ return rows+ if query["state"] == ["open"]:+ return open_on_ref if query.get("ref") == [ref] else open_default+ return []++ evidence.evaluate(fetch=fetch)+ return (tmp_path / "output").read_text(encoding="utf-8")+++def test_tag_evidence_back_dates_before_excluding_post_gate_alerts(+ monkeypatch, tmp_path+):+ stale = post_gate_alert("trivy-prerelease")+ current = post_gate_alert("container-security", age=timedelta(days=1))+ current["number"] = 2+ current["most_recent_instance"]["location"] = {+ "path": "another/image/path",+ "start_line": 1,+ }+ rows = [+ {+ "ref": "refs/tags/v1.0.0",+ "category": "trivy-prerelease",+ "state": "open",+ }+ ]+ with pytest.raises(ValueError, match="blocking code-scanning"):+ _tag_evidence(monkeypatch, tmp_path, [stale, current], [], rows)+++def test_tag_evidence_uses_open_default_branch_history(monkeypatch, tmp_path):+ """A tag release inherits the default branch's earlier open detection."""+ assert (+ _tag_evidence(+ monkeypatch,+ tmp_path,+ [alert()],+ [alert(timedelta(days=10), number=2)],+ [],+ )+ == "release_deadline=2026-11-02T12:00:00Z\n"+ )diff --git a/tests/ci/test_release_native_reports.py b/tests/ci/test_release_native_reports.pynew file mode 100644index 0000000000..59fe9d8a7f--- /dev/null+++ b/tests/ci/test_release_native_reports.py@@ -0,0 +1,464 @@+"""Exact upload receipts, complete native reports and release-only wiring."""++# allow: no-sut-import — standalone CI helpers do not load application code.++import importlib.util+import json+from pathlib import Path+from types import SimpleNamespace+from urllib.parse import parse_qs, urlsplit++import pytest+import yaml+++ROOT = Path(__file__).resolve().parents[2]+++def load(name):+ spec = importlib.util.spec_from_file_location(+ name, ROOT / ".github/scripts" / f"{name}.py"+ )+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ return module+++native = load("check_release_report_age")+reports = load("release_native_reports")+UPLOAD = "11111111-1111-4111-8111-111111111111"+SHA = "a" * 40+++def receipt(**changes):+ return {+ "sarif_id": UPLOAD,+ "commit_sha": SHA,+ "ref": "refs/heads/main",+ "analysis_key": ".github/workflows/release.yml:sample",+ "category": "sample-release",+ "tool": {"name": "sample-scanner"},+ "error": "",+ "results_count": 0,+ **changes,+ }+++def verify(+ fetch,+ *,+ upload=UPLOAD,+ category="sample-release",+ tool="sample-scanner",+ sleep=lambda _: None,+):+ return native.verify_upload(+ upload,+ category,+ reports.sarif(tool, []),+ "example/project",+ SHA,+ "refs/heads/main",+ "sample",+ "example/project/.github/workflows/release.yml@refs/heads/main",+ fetch=fetch,+ sleep=sleep,+ )+++def test_receipt_is_queried_by_exact_uuid_and_scope():+ calls = []++ def fetch(endpoint):+ calls.append(endpoint)+ if endpoint.endswith("/" + UPLOAD):+ return {"processing_status": "complete"}+ assert parse_qs(urlsplit(endpoint).query) == {+ "sarif_id": [UPLOAD],+ "per_page": ["100"],+ }+ return [receipt()]++ verify(fetch)+ assert len(calls) == 2+++ "change",+ [+ {"sarif_id": "22222222-2222-4222-8222-222222222222"},+ {"commit_sha": "b" * 40},+ {"ref": "refs/heads/other"},+ {"analysis_key": "other:sample"},+ {"category": "other"},+ {"tool": {"name": "other"}},+ {"error": "Unknown Error"},+ {"error": None},+ {"results_count": True},+ {"results_count": -1},+ ],+)+def test_clean_looking_report_cannot_use_another_or_failed_analysis(change):+ def fetch(endpoint):+ return (+ {"processing_status": "complete"}+ if "/sarifs/" in endpoint+ else [receipt(**change)]+ )++ with pytest.raises(ValueError):+ verify(fetch)+++ "status",+ [+ None,+ {},+ {"processing_status": "failed"},+ {"processing_status": "complete", "errors": ["synthetic"]},+ ],+)+def test_missing_or_failed_processing_is_blocking_even_for_empty_reports(+ status,+):+ with pytest.raises(ValueError):+ verify(lambda _: status)+++def test_pending_processing_is_bounded():+ waits = []+ with pytest.raises(ValueError, match="complete"):+ verify(lambda _: {"processing_status": "pending"}, sleep=waits.append)+ assert waits == [5] * 18+++def test_nonempty_report_requires_processed_findings():+ with pytest.raises(ValueError, match="absent"):+ native.verify_upload(+ UPLOAD,+ "sample-release",+ reports.sarif(+ "sample-scanner", [("SAMPLE_RULE", "high", "sample.py")]+ ),+ "example/project",+ SHA,+ "refs/heads/main",+ "sample",+ "example/project/.github/workflows/release.yml@refs/heads/main",+ fetch=lambda endpoint: (+ {"processing_status": "complete"}+ if "/sarifs/" in endpoint+ else [receipt()]+ ),+ )+++def test_only_osv_can_use_the_existing_implicit_category():+ with pytest.raises(ValueError, match="OSV"):+ verify(+ lambda _: pytest.fail(+ "Invalid category must fail before API access"+ ),+ category="auto",+ )++ row = receipt(+ category=".github/workflows/release.yml:osv-scan",+ tool={"name": "osv-scanner"},+ )+ verify(+ lambda endpoint: (+ {"processing_status": "complete"}+ if "/sarifs/" in endpoint+ else [row]+ ),+ category="auto",+ tool="osv-scanner",+ )+++def npm_data():+ return {+ "auditReportVersion": 2,+ "vulnerabilities": {},+ "metadata": {+ "vulnerabilities": {+ "info": 0,+ "low": 0,+ "moderate": 0,+ "high": 0,+ "critical": 0,+ "total": 0,+ }+ },+ }+++def test_npm_runner_requires_a_target_and_its_lockfile(tmp_path):+ with pytest.raises(ValueError, match="no target"):+ reports.audit_npm(tmp_path)+ (tmp_path / "package.json").write_text("{}", encoding="utf-8")+ with pytest.raises(ValueError, match="lockfile"):+ reports.audit_npm(tmp_path)++[email protected]("status,allowed", [(0, True), (1, True), (2, False)])+def test_npm_runner_preserves_operational_failures(tmp_path, status, allowed):+ for file in ("package.json", "package-lock.json"):+ (tmp_path / file).write_text("{}", encoding="utf-8")++ def run(argv, **kwargs):+ assert argv == ["npm", "audit", "--audit-level=moderate", "--json"]+ assert kwargs["cwd"] == tmp_path+ return SimpleNamespace(returncode=status, stdout=json.dumps(npm_data()))++ if allowed:+ assert reports.audit_npm(tmp_path, run)["runs"][0]["results"] == []+ else:+ with pytest.raises(ValueError, match="execute"):+ reports.audit_npm(tmp_path, run)+++def test_npm_completion_counts_cannot_hide_partial_records():+ data = npm_data()+ data["metadata"]["vulnerabilities"]["high"] = 1+ with pytest.raises(ValueError, match="counts"):+ reports.npm_findings(data, "package-lock.json")+ data = npm_data()+ data["vulnerabilities"]["synthetic"] = {"severity": "medium", "via": []}+ with pytest.raises(ValueError):+ reports.npm_findings(data, "package-lock.json")+++ "data",+ [+ [],+ {},+ {"summary": {"parsing_errors": False}, "results": {}},+ {"summary": {"parsing_errors": 0}, "results": []},+ ],+)+def test_checkov_empty_or_malformed_completion_is_fatal(data):+ with pytest.raises(ValueError):+ reports.validate_checkov(data)+++def test_checkov_accepts_its_native_complete_empty_summary_without_hiding_errors():+ data = {+ "passed": 0,+ "failed": 0,+ "skipped": 0,+ "parsing_errors": 0,+ "resource_count": 0,+ "checkov_version": "3.2.499",+ }+ reports.validate_checkov(data)+ for field in ("passed", "failed", "parsing_errors", "resource_count"):+ malformed = {**data, field: 1}+ with pytest.raises(ValueError):+ reports.validate_checkov(malformed)+++def workflow(name):+ return yaml.safe_load(+ (ROOT / ".github/workflows" / f"{name}.yml").read_text(encoding="utf-8")+ )+++def test_zap_preserves_configured_and_default_advisories(tmp_path):+ path = tmp_path / "rules.tsv"+ path.write_text(+ "10001\tFAIL\tSynthetic fail\n10002\tWARN\tSynthetic warning\n10003\tIGNORE\tSynthetic ignored\n",+ encoding="utf-8",+ )+ payload = {+ "@version": "synthetic",+ "site": [+ {+ "alerts": [+ {"pluginid": str(rule), "riskcode": "2"}+ for rule in range(10001, 10005)+ ]+ }+ ],+ }+ report = reports.zap_report(payload, path)+ policy = native.policy_module()+ assert [+ policy.blocking_severity(finding)+ for finding in native.report_findings(report, tmp_path)+ ] == [True, False, False, False]+ rules = report["runs"][0]["tool"]["driver"]["rules"]+ assert [rule["properties"]["native-risk"] for rule in rules] == [+ "medium"+ ] * 4+ assert [rule["properties"]["configured-action"] for rule in rules] == [+ "FAIL",+ "WARN",+ "IGNORE",+ "WARN",+ ]+++ "riskcode,severity", [("0", "medium"), ("1", "medium"), ("3", "high")]+)+def test_zap_configured_fail_rules_block_at_any_native_risk(+ tmp_path, riskcode, severity+):+ """Low/Informational FAIL rules (e.g. 10021, 10035, 10063) must not+ become permanently advisory notes; they enforce the age policy."""+ path = tmp_path / "rules.tsv"+ path.write_text("10021\tFAIL\tSynthetic header rule\n", encoding="utf-8")+ payload = {+ "@version": "synthetic",+ "site": [{"alerts": [{"pluginid": "10021", "riskcode": riskcode}]}],+ }+ report = reports.zap_report(payload, path)+ findings = native.report_findings(report, tmp_path)+ assert len(findings) == 1+ assert findings[0]["rule"]["security_severity_level"] == severity+ assert findings[0]["rule"]["severity"] == "warning"+ assert native.policy_module().blocking_severity(findings[0])+ rule = report["runs"][0]["tool"]["driver"]["rules"][0]+ assert (+ rule["properties"]["native-risk"]+ == (("info", "low", "medium", "high")[int(riskcode)])+ )+++ "configuration", ["10001\tOTHER\n", "10001\tFAIL\n10001\tIGNORE\n"]+)+def test_zap_invalid_rule_configuration_does_not_grant_a_pass(+ tmp_path, configuration+):+ path = tmp_path / "rules.tsv"+ path.write_text(configuration, encoding="utf-8")+ with pytest.raises(ValueError):+ reports.zap_report(+ {"@version": "synthetic", "site": [{"alerts": []}]}, path+ )+++def test_release_native_jobs_and_installed_audits_precede_the_final_decision():+ gate = workflow("release-gate")["jobs"]+ native_jobs = {+ "osv-scan",+ "npm-audit",+ "retirejs-scan",+ "hadolint-scan",+ "checkov-scan",+ "owasp-zap-scan",+ }+ for name in native_jobs:+ assert gate[name]["with"]["release_policy"] is True+ alert_job = gate["check-code-scanning-alerts"]+ assert native_jobs | {"pip-install-check", "package-install-matrix"} <= set(+ alert_job["needs"]+ )+ summary = gate["release-gate-summary"]+ assert {+ "security-tests",+ "gitleaks-scan",+ "check-code-scanning-alerts",+ } <= set(summary["needs"])+ step = next(s for s in alert_job["steps"] if s.get("id") == "alert-check")+ assert len(json.loads(step["env"]["NATIVE_DEADLINES"])) == 7+ assert "--native-deadlines" in step["run"]+ for name in ("pip-install-check", "package-install-matrix"):+ audits = [+ s["run"]+ for s in gate[name]["steps"]+ if "audit_installed_dependencies.py" in s.get("run", "")+ ]+ assert audits and all(+ "--release-policy" in command for command in audits+ )+ assert any(+ "upload-sarif@" in s.get("uses", "") for s in gate[name]["steps"]+ )+++def test_promotion_finding_decision_precedes_tag_publication():+ steps = workflow("docker-publish")["jobs"]["promote"]["steps"]+ position = {s.get("id"): i for i, s in enumerate(steps) if "id" in s}+ publish = next(+ i+ for i, s in enumerate(steps)+ if "docker buildx imagetools create" in s.get("run", "")+ )+ assert (+ position["native-upload"]+ < position["native-policy"]+ < position["native-deadline"]+ < publish+ )+ # Immediate critical and secret checks must also precede tag publication.+ immediate = [+ i+ for i, s in enumerate(steps)+ if "aquasecurity/trivy-action@" in s.get("uses", "")+ and str((s.get("with") or {}).get("exit-code")) == "1"+ ]+ secret = [+ i+ for i in immediate+ if (steps[i].get("with") or {}).get("scanners") == "secret"+ ]+ assert len(immediate) == 2 and len(secret) == 1+ assert max(immediate) < publish+ promotion = workflow("docker-publish")+ assert (+ promotion[True]["workflow_call"]["outputs"]["release_deadline"]["value"]+ == "${{ jobs.promote.outputs.release_deadline }}"+ )+ assert (+ promotion["jobs"]["promote"]["outputs"]["release_deadline"]+ == "${{ steps.native-deadline.outputs.release_deadline }}"+ )+++ "name,job",+ [+ ("prerelease-docker", "security-scan"),+ ("docker-publish", "promote"),+ ("container-security", "trivy-scan"),+ ],+)+def test_image_secrets_block_immediately_instead_of_being_aged(name, job):+ """Trivy's default image scanners include `secret`; its HIGH rules+ (private-key, pypi-upload-token) must not inherit the 14-day window."""+ checks = [+ step+ for step in workflow(name)["jobs"][job]["steps"]+ if "aquasecurity/trivy-action@" in step.get("uses", "")+ and step.get("with", {}).get("scanners") == "secret"+ ]+ assert len(checks) == 1+ step = checks[0]+ assert "if" not in step and "continue-on-error" not in step+ assert str(step["with"]["exit-code"]) == "1"+ assert {"CRITICAL", "HIGH", "MEDIUM"} <= set(+ step["with"]["severity"].split(",")+ )+++def test_release_policy_passthroughs_always_send_a_boolean():+ """Without workflow_call inputs (pull_request, merge_group, schedule,+ dispatch) `inputs.release_policy` is empty; GitHub rejects '' for a+ typed boolean input and the caller run reports no jobs at all."""+ checked = 0+ for path in sorted((ROOT / ".github/workflows").glob("*.yml")):+ for job in (workflow(path.stem).get("jobs") or {}).values():+ value = (job.get("with") or {}).get("release_policy")+ if value is None or not job.get("uses"):+ continue+ checked += 1+ assert value is True or value == (+ "${{ inputs.release_policy == true }}"+ ), f"{path.name}: release_policy passthrough {value!r}"+ assert checked >= 9diff --git a/tests/ci/test_release_queue_contract.py b/tests/ci/test_release_queue_contract.pyindex 82a2743f2b..43a8dbe815 100644--- a/tests/ci/test_release_queue_contract.py+++ b/tests/ci/test_release_queue_contract.py@@ -2,6 +2,7 @@import importlib.utilfrom pathlib import Path+import shleximport yaml@@ -26,8 +27,8 @@ def test_release_and_gate_retain_pending_runs_without_deadlocking() -> None:def test_checkov_scans_workflows_with_queue_after_blanking_it() -> None:- """Checkov 3.2.499's schema rejects concurrency.queue and then silently- skips the whole workflow, so the gate must blank it before scanning."""+ """Keep compatibility preparation before the workflow scan: earlier+ Checkov schemas rejected concurrency.queue and skipped affected files."""root = WORKFLOWS.parents[1]checkov = yaml.safe_load((WORKFLOWS / "checkov-scan.yml").read_text())steps = checkov["jobs"]["checkov"]["steps"]@@ -39,9 +40,17 @@ def test_checkov_scans_workflows_with_queue_after_blanking_it() -> None:)scan = next(i- for i, run in enumerate(commands)- if "checkov -d .github/workflows" in run+ for i, step in enumerate(steps)+ if step.get("name") == "Run Checkov on GitHub Actions workflows"+ )+ invocation = next(+ line.strip()+ for line in commands[scan].replace("\\\n", " ").splitlines()+ if line.lstrip().startswith("checkov "))+ arguments = shlex.split(invocation)+ assert arguments[arguments.index("-d") + 1] == ".github/workflows"+ assert arguments[arguments.index("--framework") + 1] == "github_actions"assert blank < scanscript = root / ".github" / "scripts" / "strip-concurrency-queue.py"diff --git a/tests/ci/test_release_security_decision.py b/tests/ci/test_release_security_decision.pyindex 3d7851f8bf..40794ac434 100644--- a/tests/ci/test_release_security_decision.py+++ b/tests/ci/test_release_security_decision.py@@ -192,6 +192,26 @@ def test_no_exception_sentinel_requires_an_authentic_decision(assert verify() == "none"+ "value,allowed",+ [+ ("2026-10-12T12:00:00Z", False),+ ("2026-10-12T12:00:00.000001Z", True),+ ("2026-10-12T12:00:01Z", True),+ ],+)+def test_bound_decision_retains_exact_grace_expiry(+ responses, record, value, allowed+):+ record["release_deadline"] = value+ replace_archive(responses, record)+ if allowed:+ assert verify() == value+ else:+ with pytest.raises(ValueError, match="expired"):+ verify()++@pytest.mark.parametrize("field,value",[diff --git a/tests/ci/test_release_security_exceptions.py b/tests/ci/test_release_security_exceptions.pyindex 9727a89042..1c95624920 100644--- a/tests/ci/test_release_security_exceptions.py+++ b/tests/ci/test_release_security_exceptions.py@@ -155,20 +155,20 @@ def test_unrelated_alerts_still_block(alert, exceptions, severity):@pytest.mark.parametrize("severity", ["low", None])def test_existing_nonblocking_severities_are_preserved(alert, severity):alert["rule"]["security_severity_level"] = severity+ alert["rule"]["severity"] = "note"gate.validate_alerts([alert])assert gate.classify_alerts([alert], {}, TODAY) == ([], [], [])-def test_quality_alert_without_security_severity_is_nonblocking(+def test_informational_alert_without_security_severity_is_nonblocking(monkeypatch, cli):- # Shape of real Hadolint alert #8101: ordinary rule severity is not a- # security severity. The optional security_severity_level is absent.+ # Native informational results remain advisory without a numerical score.alert = {- "number": 8101,+ "number": 101,"state": "open",- "rule": {"id": "DL3025", "severity": "warning"},- "tool": {"name": "Hadolint"},+ "rule": {"id": "SAMPLE_NOTE", "severity": "note"},+ "tool": {"name": "Sample scanner"},}original = deepcopy(alert)_mock_pages(monkeypatch, [[alert], []])@@ -341,7 +341,7 @@ def test_api_failure_after_first_page_never_grants_exception(@pytest.mark.parametrize("channel", ["stderr", "output"])-def test_api_failure_preserves_bounded_escaped_diagnostics(+def test_api_failure_preserves_status_without_echoing_private_diagnostics(monkeypatch, cli, capsys, channel):failure = subprocess.CalledProcessError(@@ -352,7 +352,8 @@ def test_api_failure_preserves_bounded_escaped_diagnostics(_mock_pages(monkeypatch, [failure])assert gate.main() == 1report = capsys.readouterr().out- assert "HTTP 403 rate limit%0A::warning::injected%25%0D" in report+ assert "HTTP 403" in report and "rate limit" in report+ assert "injected" not in reportassert "x" * 2001 not in reportassert len(report.splitlines()) == 1assert not cli[1].exists()@@ -468,6 +469,7 @@ def test_evidence_expiring_during_alert_fetch_does_not_grant_output([datetime(2026, 10, 12, 23, 59, tzinfo=timezone.utc),datetime(2026, 10, 13, tzinfo=timezone.utc),+ datetime(2026, 10, 13, tzinfo=timezone.utc),])