mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-03 18:28:19 +00:00
feat(pre-push-safety-net): declare the provisional advisory scope and print it on every run
One packaged record (advisory-scope.json, shipped in the wheel beside eligibility.json) states the provisional scope, every exclusion with its reason, and what each exclusion leaves untold. The hook renders exactly one bounded Scope line per run in every state (provisional, with defects, record unavailable) and the artifact carries the record under advisory_scope. The record is provisional if and only if the shipped registry is NO-GO with no enabled declaration. Task 15.2. The task text cites a requirement 5.6 that does not exist, so this is implemented against 3.1, 5.1, 7.1 and 7.3.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"status": "provisional",
|
||||
"basis": "No capability is qualified for alerts today: the shipped capability registry (eligibility.json) has verdict NO-GO and enables no declaration. This is the intended v1 advisory scope; it becomes effective only through the M4 evaluation bound to an immutable spent population (valid-detection-benchmark tasks 11.6 and 11.7).",
|
||||
"scope": [
|
||||
{
|
||||
"family": "injection",
|
||||
"label": "injection",
|
||||
"reason": "Injection entails with witnesses on the measured subjects."
|
||||
},
|
||||
{
|
||||
"family": "untrusted_destination",
|
||||
"label": "untrusted destination",
|
||||
"reason": "Untrusted destination entails with witnesses on the measured subjects."
|
||||
},
|
||||
{
|
||||
"family": "config_secrets",
|
||||
"label": "configuration",
|
||||
"reason": "Configuration entails with witnesses on the measured subjects."
|
||||
}
|
||||
],
|
||||
"exclusions": [
|
||||
{
|
||||
"family": "access_control",
|
||||
"label": "access control",
|
||||
"reason": "Access control does not entail with witnesses on the measured subjects: on an application that splits its route from its data access the obligation is carried, and a carried obligation corroborates by design, so shipping the family would ship silence.",
|
||||
"not_told": "No defect is reported for access control, so a contributor is not told that a change reaches a protected operation without the guard or ownership constraint its siblings carry, even when it does."
|
||||
},
|
||||
{
|
||||
"family": "output_encoding",
|
||||
"label": "output encoding",
|
||||
"reason": "Has not earned a place through evaluation.",
|
||||
"not_told": "No defect is reported for output encoding, so a contributor is not told that a change sends untrusted data to a rendered document or a header without encoding, even when it does."
|
||||
},
|
||||
{
|
||||
"family": "path",
|
||||
"label": "path",
|
||||
"reason": "Has not earned a place through evaluation.",
|
||||
"not_told": "No defect is reported for path, so a contributor is not told that a change lets untrusted input reach a filesystem path, even when it does."
|
||||
},
|
||||
{
|
||||
"family": "prototype",
|
||||
"label": "prototype",
|
||||
"reason": "Has not earned a place through evaluation.",
|
||||
"not_told": "No defect is reported for prototype, so a contributor is not told that a change lets untrusted keys reach an object merge or an attribute assignment, even when it does."
|
||||
},
|
||||
{
|
||||
"family": "deserialization",
|
||||
"label": "deserialization",
|
||||
"reason": "Has not earned a place through evaluation.",
|
||||
"not_told": "No defect is reported for deserialization, so a contributor is not told that a change deserializes untrusted data into objects the process then trusts, even when it does."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
"""The declared advisory scope of the pre-push safety net (task 15.2): one packaged record.
|
||||
|
||||
``advisory-scope.json`` names the families whose claims are intended to be admitted as alerts and every
|
||||
family that is not, with the reason and what a contributor is therefore not told. Like the eligibility
|
||||
registry it is a shipped release input: never repository configuration, never a model response. The
|
||||
scope is provisional until the M4 evaluation qualifies a capability, so the rendered line states that
|
||||
limit instead of letting a listed family read as checked and found fine.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from openultrasast.model.taxonomy import FAMILY_IDS
|
||||
|
||||
_DEFAULT = Path(__file__).with_name("advisory-scope.json")
|
||||
_LIMIT = 64 * 1024
|
||||
_SCHEMA_VERSION = 1
|
||||
_TOP_KEYS = frozenset({"schema_version", "status", "basis", "scope", "exclusions"})
|
||||
_ENTRY_KEYS = frozenset({"family", "label", "reason"})
|
||||
_EXCLUSION_KEYS = _ENTRY_KEYS | {"not_told"}
|
||||
# Families come from the closed vocabulary and are unique, so labels of this size keep the line bounded.
|
||||
_MAX_LABEL = 48
|
||||
_UNAVAILABLE = "advisory_scope_invalid_or_unavailable"
|
||||
_PROVISIONAL_LINE = (
|
||||
"Scope: provisional, not yet in effect: no family is qualified for alerts yet. "
|
||||
"Intended v1 advisory scope: {scope}. "
|
||||
"Not reported as defects: {excluded}, or any other family outside the scope. "
|
||||
"Listing a family does not mean the repository was found free of defects in it."
|
||||
)
|
||||
_UNKNOWN_LINE = (
|
||||
"Scope: unknown. The shipped scope record could not be read, so which families this tool can and cannot "
|
||||
"report is unknown; that missing limit is itself a limit of this run."
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class FamilyScope:
|
||||
"""One family of the record: intended for admission, or excluded from it with what is not told."""
|
||||
|
||||
family: str
|
||||
label: str
|
||||
reason: str
|
||||
not_told: str | None = None
|
||||
|
||||
def to_payload(self) -> dict[str, str]:
|
||||
payload = {"family": self.family, "label": self.label, "reason": self.reason}
|
||||
if self.not_told is not None:
|
||||
payload["not_told"] = self.not_told
|
||||
return payload
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class AdvisoryScope:
|
||||
"""A validated provisional scope, or the closed `unavailable` result with one reason code."""
|
||||
|
||||
status: str
|
||||
basis: str = ""
|
||||
scope: tuple[FamilyScope, ...] = ()
|
||||
exclusions: tuple[FamilyScope, ...] = ()
|
||||
reason: str = ""
|
||||
|
||||
def to_payload(self) -> dict[str, object]:
|
||||
"""The artifact field: the record itself, or the unavailable status with its reason."""
|
||||
if self.status != "provisional":
|
||||
return {"status": self.status, "reason": self.reason}
|
||||
return {
|
||||
"schema_version": _SCHEMA_VERSION,
|
||||
"status": self.status,
|
||||
"basis": self.basis,
|
||||
"scope": [entry.to_payload() for entry in self.scope],
|
||||
"exclusions": [entry.to_payload() for entry in self.exclusions],
|
||||
}
|
||||
|
||||
def render(self) -> str:
|
||||
"""The one limit line for the terminal: fixed phrases and the record's labels, nothing else."""
|
||||
if self.status != "provisional":
|
||||
# Anything but a validated provisional record leaves the limits unknown; never a claim.
|
||||
return _UNKNOWN_LINE
|
||||
return _PROVISIONAL_LINE.format(scope=_labels(self.scope), excluded=_labels(self.exclusions))
|
||||
|
||||
|
||||
def _labels(entries: tuple[FamilyScope, ...]) -> str:
|
||||
return ", ".join(entry.label for entry in entries)
|
||||
|
||||
|
||||
def _text(value: object, *, limit: int | None = None) -> str:
|
||||
# Exact type and printable ASCII: a bool is not a name, and no control character can add a line or an escape.
|
||||
if type(value) is not str or not value.strip() or not value.isascii() or not value.isprintable():
|
||||
raise ValueError("advisory_scope_text_invalid")
|
||||
if limit is not None and len(value) > limit:
|
||||
raise ValueError("advisory_scope_label_too_long")
|
||||
return value
|
||||
|
||||
|
||||
def _entry(raw: object, *, excluded: bool) -> FamilyScope:
|
||||
if type(raw) is not dict or set(raw) != (_EXCLUSION_KEYS if excluded else _ENTRY_KEYS):
|
||||
raise ValueError("advisory_scope_entry_invalid")
|
||||
family = _text(raw["family"], limit=_MAX_LABEL)
|
||||
if family not in FAMILY_IDS:
|
||||
raise ValueError("advisory_scope_family_unknown")
|
||||
return FamilyScope(
|
||||
family,
|
||||
_text(raw["label"], limit=_MAX_LABEL),
|
||||
_text(raw["reason"]),
|
||||
_text(raw["not_told"]) if excluded else None,
|
||||
)
|
||||
|
||||
|
||||
def _validate(data: object) -> AdvisoryScope:
|
||||
if type(data) is not dict or set(data) != _TOP_KEYS:
|
||||
raise ValueError("advisory_scope_shape_invalid")
|
||||
version, status, scope, exclusions = (data[key] for key in ("schema_version", "status", "scope", "exclusions"))
|
||||
if type(version) is not int or version != _SCHEMA_VERSION or status != "provisional":
|
||||
raise ValueError("advisory_scope_version_or_status_unsupported")
|
||||
if type(scope) is not list or type(exclusions) is not list or not scope or not exclusions:
|
||||
raise ValueError("advisory_scope_families_invalid")
|
||||
intended = tuple(_entry(item, excluded=False) for item in scope)
|
||||
leave_out = tuple(_entry(item, excluded=True) for item in exclusions)
|
||||
families = [entry.family for entry in (*intended, *leave_out)]
|
||||
if len(set(families)) != len(families):
|
||||
# One rule for a family named twice and for one listed on both sides: the sides stay disjoint.
|
||||
raise ValueError("advisory_scope_family_repeated")
|
||||
return AdvisoryScope("provisional", _text(data["basis"]), intended, leave_out)
|
||||
|
||||
|
||||
def load_advisory_scope(path: Path | None = None) -> AdvisoryScope:
|
||||
"""The shipped scope record, or a closed `unavailable` scope: this never raises into the hook."""
|
||||
try:
|
||||
with (path or _DEFAULT).open("rb") as stream:
|
||||
content = stream.read(_LIMIT + 1)
|
||||
if len(content) > _LIMIT:
|
||||
raise ValueError("advisory_scope_size_limit")
|
||||
return _validate(json.loads(content))
|
||||
except (OSError, ValueError, TypeError, KeyError, AttributeError, RecursionError):
|
||||
return AdvisoryScope("unavailable", reason=_UNAVAILABLE)
|
||||
@@ -17,6 +17,7 @@ from typing import Literal
|
||||
|
||||
from openultrasast.model.contracts import ChangeContext, ExecutionBudget
|
||||
from openultrasast.model.scan import ModelScanResult
|
||||
from openultrasast.push.advisory_scope import AdvisoryScope, load_advisory_scope
|
||||
from openultrasast.push.contracts import PushComparison, PushResolution, PushResult, SnapshotManifest
|
||||
from openultrasast.push.explain import explain
|
||||
from openultrasast.push.policy import AdmissionResult, _context_boundaries
|
||||
@@ -49,6 +50,9 @@ class PushReport:
|
||||
quick: tuple[Mapping[str, object], ...] = ()
|
||||
# The background engine (task 17.5): what this run started, and earlier results shown now.
|
||||
background: Mapping[str, object] = field(default_factory=dict)
|
||||
# The declared advisory scope (task 15.2): the shipped record, kept in the artifact and rendered as the
|
||||
# one limit line. Loading is closed: an unreadable record is itself reported as a limit.
|
||||
advisory_scope: AdvisoryScope = field(default_factory=load_advisory_scope)
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
object.__setattr__(self, "model_assistance", MappingProxyType(dict(self.model_assistance)))
|
||||
@@ -90,6 +94,8 @@ class PushReport:
|
||||
type(value) not in (int, float) or not math.isfinite(value) or value < 0 for value in self.timings.values()
|
||||
):
|
||||
raise ValueError("report requires finite nonnegative timings including total_seconds")
|
||||
if not isinstance(self.advisory_scope, AdvisoryScope):
|
||||
raise ValueError("report requires a loaded advisory scope")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -140,6 +146,7 @@ def _write_artifact(report: PushReport, target: Path, temporary: Path, connectio
|
||||
"experimental": dict(report.experimental),
|
||||
"quick_tier": [dict(item) for item in report.quick],
|
||||
"engine_background": dict(report.background),
|
||||
"advisory_scope": report.advisory_scope.to_payload(),
|
||||
}
|
||||
json.dump(payload, stream, ensure_ascii=True, allow_nan=False, indent=2)
|
||||
stream.write("\n")
|
||||
@@ -413,6 +420,8 @@ def render_report(report: PushReport, *, artifact: Path | None, error: str | Non
|
||||
lines.append("Notice: " + " ".join(notices))
|
||||
if report.experimental:
|
||||
lines.append("Experimental: " + _experimental_line(report.experimental))
|
||||
# The limit notice of the whole report (task 15.2): once per run, with or without defects.
|
||||
lines.append(report.advisory_scope.render())
|
||||
if artifact is not None:
|
||||
lines.append("Details: " + _short(str(artifact), 4096))
|
||||
if report.result.push_disposition == "block":
|
||||
|
||||
Reference in New Issue
Block a user