synthetic-bundle · Sharp (bundled librsvg)
precondition_present
Reported version: 0.35.4 · Rule: CVE-2026-96889 · Exploitability: not_tested
For official bundled binaries, upgrade Sharp to 0.35.5 or a later supported patched release. For a global library, independently verify the selected librsvg and apply the upstream 2.63.2 fix or a documented vendor fix. Rebuild/redeploy and verify the actual linkage. Effective VipsForeignLoadSvg blocking and Node PIE are separate mitigations; neither attests the library patch set.
- The reported official Sharp bundle is below 0.35.5.
- Version, platform, libc, effective mitigation and input-path observations are operator claims; local exploitability remains not_tested.
- A mitigated configuration preserves an affected library/package assessment and does not establish safety or absence of prior compromise.
Evidence and assessment dimensions
- version: present — The reported official Sharp bundle is below 0.35.5.
- inventory: present — Operator-reported library selection: bundled; linkage is not independently verified.
- inventory: present — Sharp version observation: 0.35.4. Accepted exact observations: 0.35.4.
- inventory: unknown — librsvg version observation: missing, qualified or conflicting.
- configuration: present — Reported platform: linux; reported libc: glibc. Other platforms do not establish that the underlying memory bug is absent.
- configuration: present — Reported effective SVG decoder state: enabled. A blocked claim must cover VipsForeignLoadSvg in the deployed process.
- configuration: present — Reported Node executable PIE state: disabled. This operator claim is not inferred from optional binary metadata hints.
- configuration: present — Operator-reviewed untrusted SVG input path: present. No data-flow or reachability test is performed.
{
+CompleteTech LLCSecurity evidence report
sharp-rsvg-rce-check 0.2.0 · Run assessed (UTC): 2026-10-25T12:34:56Z · Executable SHA-256: da4132845194dce45f044b9446d177632996553281f9e22ba975fd51f42279bc · rules verified 2026-10-24
Completed assessmentLocal exploitability is not tested. Version, configuration, candidate source patterns and external exploitation reports are separate evidence.
precondition_present: 1 · mitigated_configuration: 1 · fixed_version_reported: 1 · unknown: 1
- Offline supplied evidence and explicitly selected metadata only; library selection, deployed versions, provenance and effective mitigations are not independently attested.
- No network requests, application execution, image decoding, exploitation, reachability test or compromise detection is performed.
- The Sharp comparison covers exact stable 0.0-0.35 versions. Global librsvg has a documented remediation build, not a published independent affected-version range; only stable 2.63.2+ within 2.63 is accepted as reported remediation.
- PIE is an RCE mitigation, not a library patch or a guarantee against other memory-corruption impact. Unknown libc or PIE remains unknown.
synthetic-bundle · Sharp (bundled librsvg)
precondition_present
Reported version: 0.35.4 · Rule: CVE-2026-96889 · Exploitability: not_tested
For official bundled binaries, upgrade Sharp to 0.35.5 or a later supported patched release. For a global library, independently verify the selected librsvg and apply the upstream 2.63.2 fix or a documented vendor fix. Rebuild/redeploy and verify the actual linkage. Effective VipsForeignLoadSvg blocking and Node PIE are separate mitigations; neither attests the library patch set.
- The reported official Sharp bundle is below 0.35.5.
- Version, platform, libc, effective mitigation and input-path observations are operator claims; local exploitability remains not_tested.
- A mitigated configuration preserves an affected library/package assessment and does not establish safety or absence of prior compromise.
Evidence and assessment dimensions
- version: present — The reported official Sharp bundle is below 0.35.5.
- inventory: present — Operator-reported library selection: bundled; linkage is not independently verified.
- inventory: present — Sharp version observation: 0.35.4. Accepted exact observations: 0.35.4.
- inventory: unknown — librsvg version observation: missing, qualified or conflicting.
- configuration: present — Reported platform: linux; reported libc: glibc. Other platforms do not establish that the underlying memory bug is absent.
- configuration: present — Reported effective SVG decoder state: enabled. A blocked claim must cover VipsForeignLoadSvg in the deployed process.
- configuration: present — Reported Node executable PIE state: disabled. This operator claim is not inferred from optional binary metadata hints.
- configuration: present — Operator-reviewed untrusted SVG input path: present. No data-flow or reachability test is performed.
{
"confidence": "low",
"mitigation": {
"evidence_ids": [],
diff --git a/schemas/report-v1.schema.json b/schemas/report-v1.schema.json
index 43bb84e..2a11cca 100644
--- a/schemas/report-v1.schema.json
+++ b/schemas/report-v1.schema.json
@@ -6,6 +6,12 @@
"complete": {
"type": "boolean"
},
+ "generated_at": {
+ "format": "date-time",
+ "maxLength": 20,
+ "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z(?![\\s\\S])",
+ "type": "string"
+ },
"limitations": {
"items": {
"maxLength": 2048,
@@ -459,6 +465,10 @@
"tool": {
"additionalProperties": false,
"properties": {
+ "executable_sha256": {
+ "pattern": "^[a-f0-9]{64}(?![\\s\\S])",
+ "type": "string"
+ },
"name": {
"maxLength": 128,
"pattern": "^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}(?![\\s\\S])",
@@ -473,7 +483,8 @@
},
"required": [
"name",
- "version"
+ "version",
+ "executable_sha256"
],
"type": "object"
}
@@ -481,6 +492,7 @@
"required": [
"schema_version",
"tool",
+ "generated_at",
"rules",
"complete",
"limitations",
diff --git a/sharp_rsvg_rce_check.py b/sharp_rsvg_rce_check.py
index c264ebc..91d179e 100644
--- a/sharp_rsvg_rce_check.py
+++ b/sharp_rsvg_rce_check.py
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-CompleteTech-Commercial
# Copyright (c) 2026 CompleteTech LLC. See LICENSING.md.
# Generated by tools/build.py. Edit src/checker.py, src/adapters.py and vendor/common.py.
-# Vendored common.py SHA-256: 714fb820175dc3d2dcb967928df4e1e97ad6fa0d478901ff6dba985f1368c0f7
+# Vendored common.py SHA-256: 77f61da266a4c79262cbc782edd1b99e5974adee134578e8cc03ebd40762d397
from __future__ import annotations
# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-CompleteTech-Commercial
@@ -21,7 +21,7 @@
import stat
import tempfile
from copy import deepcopy
-from datetime import date
+from datetime import date, datetime, timezone
from pathlib import Path
from urllib.parse import urlsplit
@@ -62,6 +62,9 @@ def _array(items, maximum=1000, minimum=0):
ID_SCHEMA = {"type": "string", "pattern": r"^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}(?![\s\S])", "maxLength": 128}
DATE_SCHEMA = {"type": "string", "format": "date"}
+UTC_SCHEMA = {"type": "string", "format": "date-time", "maxLength": 20,
+ "pattern": r"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z(?![\s\S])"}
+DIGEST_SCHEMA = {"type": "string", "pattern": r"^[a-f0-9]{64}(?![\s\S])"}
URL_SCHEMA = {"type": "string", "format": "uri", "maxLength": 2048}
NULLABLE_DATE = {"anyOf": [DATE_SCHEMA, {"type": "null"}]}
NULLABLE_URL = {"anyOf": [URL_SCHEMA, {"type": "null"}]}
@@ -107,7 +110,8 @@ def _threat_schema(states):
})
REPORT_SCHEMA = _object({
"schema_version": {"const": CONTRACT_VERSION},
- "tool": _object({"name": ID_SCHEMA, "version": _text(64, min_length=1)}),
+ "tool": _object({"name": ID_SCHEMA, "version": _text(64, min_length=1), "executable_sha256": DIGEST_SCHEMA}),
+ "generated_at": UTC_SCHEMA,
"rules": _object({
"snapshot_id": ID_SCHEMA, "verified_at": DATE_SCHEMA,
"sha256": {"anyOf": [{"type": "string", "pattern": r"^[a-f0-9]{64}(?![\s\S])"}, {"type": "null"}]},
@@ -156,6 +160,13 @@ def _check_format(value, fmt, path):
date.fromisoformat(value)
except ValueError:
raise ContractError(f"{path}: invalid ISO date") from None
+ elif fmt == "date-time":
+ try:
+ if re.fullmatch(r"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z", value) is None:
+ raise ValueError
+ datetime.strptime(value, "%Y-%m-%dT%H:%M:%SZ")
+ except ValueError:
+ raise ContractError(f"{path}: expected real UTC timestamp") from None
elif fmt == "uri":
try:
parsed = urlsplit(value)
@@ -315,9 +326,25 @@ def make_result(asset_id, component, rule_id, status="unknown", *, version=None,
return validate_result(result)
+def utc_now():
+ """Run assessment time, separate from rule verification and evidence acquisition."""
+ return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
+
+
+def executable_digest():
+ """Identify actual standalone bytes; this is not deployed patch attestation."""
+ try:
+ executable = Path(__file__).resolve(strict=True)
+ except RuntimeError:
+ raise ContractError("Executable path could not be resolved") from None
+ return hashlib.sha256(_read_regular_file(executable, MAX_JSON_BYTES)).hexdigest()
+
+
def make_report(tool, tool_version, snapshot_id, rules_as_of, results, *, complete=True,
- limitations=None, snapshot_digest=None):
- report = {"schema_version": CONTRACT_VERSION, "tool": {"name": tool, "version": tool_version},
+ limitations=None, snapshot_digest=None, generated_at=None, executable_sha256=None):
+ report = {"schema_version": CONTRACT_VERSION, "tool": {"name": tool, "version": tool_version,
+ "executable_sha256": executable_digest() if executable_sha256 is None else executable_sha256},
+ "generated_at": utc_now() if generated_at is None else generated_at,
"rules": {"snapshot_id": snapshot_id, "verified_at": rules_as_of, "sha256": snapshot_digest},
"complete": complete, "limitations": deepcopy(limitations or []), "results": deepcopy(results)}
return validate_report(report)
@@ -448,19 +475,24 @@ def render_csv(report):
output = io.StringIO(newline="")
fields = ("record_type", "asset_id", "component", "version", "rule_id", "status", "version_assessment", "confidence",
"exploitability", "complete", "rules_as_of", "evidence", "preconditions", "mitigation",
- "reachability", "threat", "reasons", "recommendation", "sources", "limitations")
+ "reachability", "threat", "reasons", "recommendation", "sources", "limitations",
+ "tool", "tool_version", "executable_sha256", "generated_at", "rules_snapshot_id", "rules_sha256")
writer = csv.DictWriter(output, fieldnames=fields, lineterminator="\n")
writer.writeheader()
+ provenance = {"tool": report["tool"]["name"], "tool_version": report["tool"]["version"],
+ "executable_sha256": report["tool"]["executable_sha256"], "generated_at": report["generated_at"],
+ "rules_snapshot_id": report["rules"]["snapshot_id"], "rules_sha256": report["rules"]["sha256"] or ""}
for result in report["results"]:
row = {key: result[key] for key in fields if key in result}
row.update(record_type="result", component=result["component"]["name"], version=result["component"]["version"] or "",
complete=report["complete"], rules_as_of=report["rules"]["verified_at"], limitations=report["limitations"])
+ row.update(provenance)
writer.writerow({key: _csv_safe(json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
if isinstance(value, (dict, list)) else value) for key, value in row.items()})
if not report["results"]:
- writer.writerow({"record_type": "summary", "complete": report["complete"],
+ writer.writerow({key: _csv_safe(value) for key, value in {"record_type": "summary", "complete": report["complete"],
"rules_as_of": report["rules"]["verified_at"], "exploitability": "not_tested",
- "limitations": json.dumps(report["limitations"], ensure_ascii=False, sort_keys=True, separators=(",", ":"))})
+ "limitations": json.dumps(report["limitations"], ensure_ascii=False, sort_keys=True, separators=(",", ":")), **provenance}.items()})
return output.getvalue()
@@ -515,7 +547,8 @@ def render_html(report, brand="CompleteTech LLC", logo=None):
pre{white-space:pre-wrap;overflow-wrap:anywhere;font-size:.85rem}p,li,code{overflow-wrap:anywhere}a{color:var(--accent)}summary{cursor:pointer}
footer{font-size:.85rem;color:var(--muted)}@media print{body{background:white;color:black}article{break-inside:avoid}details>summary{display:none}details>ul,details>pre{display:block}}
""" + logo_html + "" + esc(brand) + "Security evidence report
" + esc(report["tool"]["name"]) \
- + " " + esc(report["tool"]["version"]) + " · rules verified " + esc(report["rules"]["verified_at"]) \
+ + " " + esc(report["tool"]["version"]) + " · Run assessed (UTC): " + esc(report["generated_at"]) \
+ + " · Executable SHA-256: " + esc(report["tool"]["executable_sha256"]) + " · rules verified " + esc(report["rules"]["verified_at"]) \
+ "
" + ("Completed assessment" if report["complete"] else "Incomplete assessment") \
+ "Local exploitability is not tested. Version, configuration, candidate source patterns and external exploitation reports are separate evidence.
" \
+ counts + "
" + limitations + "
" + "".join(rows) \
@@ -1064,6 +1097,7 @@ def publish_results(args, results, protected, *, complete, state=None):
state = {} if state is None else state
report = make_report(TOOL_NAME, TOOL_VERSION, SNAPSHOT_ID, RULE_DATE, results,
complete=complete, limitations=LIMITATIONS,
+ generated_at=state.get("generated_at"), executable_sha256=state.get("executable_sha256"),
snapshot_digest=snapshot_digest(RULE_SNAPSHOT))
rendered = canonical_json(report) if args.format == "json" else render_csv(report) if args.format == "csv" else render_html(report, brand=args.brand, logo=args.logo)
if args.output:
@@ -1121,6 +1155,7 @@ def main(argv=None):
if args.logo:
protected.append(args.logo)
try:
+ publication["generated_at"], publication["executable_sha256"] = utc_now(), executable_digest()
if args.logo and args.format != "html":
raise ContractError("logo requires HTML output")
if len(adapter_files) > 100 or (adapter_files and (args.evidence_root is None or not args.evidence_root.is_dir())):
diff --git a/src/checker.py b/src/checker.py
index 0a5c42d..d3740a3 100644
--- a/src/checker.py
+++ b/src/checker.py
@@ -177,6 +177,7 @@ def publish_results(args, results, protected, *, complete, state=None):
state = {} if state is None else state
report = make_report(TOOL_NAME, TOOL_VERSION, SNAPSHOT_ID, RULE_DATE, results,
complete=complete, limitations=LIMITATIONS,
+ generated_at=state.get("generated_at"), executable_sha256=state.get("executable_sha256"),
snapshot_digest=snapshot_digest(RULE_SNAPSHOT))
rendered = canonical_json(report) if args.format == "json" else render_csv(report) if args.format == "csv" else render_html(report, brand=args.brand, logo=args.logo)
if args.output:
@@ -234,6 +235,7 @@ def main(argv=None):
if args.logo:
protected.append(args.logo)
try:
+ publication["generated_at"], publication["executable_sha256"] = utc_now(), executable_digest()
if args.logo and args.format != "html":
raise ContractError("logo requires HTML output")
if len(adapter_files) > 100 or (adapter_files and (args.evidence_root is None or not args.evidence_root.is_dir())):
diff --git a/test_conflict_evidence.py b/test_conflict_evidence.py
index 0d17ae9..aa970a8 100644
--- a/test_conflict_evidence.py
+++ b/test_conflict_evidence.py
@@ -19,7 +19,10 @@ def report(self, sharp, native, fmt):
for value in native:
args += ['--librsvg-version', value]
out = io.StringIO()
- with patch('socket.socket', side_effect=AssertionError('offline')), contextlib.redirect_stdout(out):
+ with patch('socket.socket', side_effect=AssertionError('offline')), \
+ patch.object(check, 'utc_now', return_value='2026-10-25T12:34:56Z'), \
+ patch.object(check, 'executable_digest', return_value='a' * 64), \
+ contextlib.redirect_stdout(out):
self.assertEqual(0, check.main(args))
return out.getvalue()
diff --git a/test_contract.py b/test_contract.py
index b9487b5..f4e5371 100644
--- a/test_contract.py
+++ b/test_contract.py
@@ -27,6 +27,8 @@ def affected(**overrides):
def report(result=None, **overrides):
+ overrides.setdefault("generated_at", "2026-10-25T12:34:56Z")
+ overrides.setdefault("executable_sha256", "a" * 64)
return contract.make_report("synthetic-check", "0.1.0", "synthetic-1", "2026-10-23",
[result or affected()], **overrides)
@@ -181,7 +183,7 @@ def test_rule_and_snapshot_dates_are_consistent_and_hash_is_stable(self):
with self.assertRaises(contract.ContractError):
contract.snapshot_digest(snapshot)
- def test_reports_are_deterministic_without_wall_clock_or_input_mutation(self):
+ def test_reports_are_deterministic_with_injected_context_without_input_mutation(self):
result = affected()
value = report(result)
result["reasons"].append("changed later")
@@ -189,7 +191,8 @@ def test_reports_are_deterministic_without_wall_clock_or_input_mutation(self):
first = contract.canonical_json(value)
second = contract.canonical_json(dict(reversed(list(value.items()))))
self.assertEqual(first, second)
- self.assertNotIn("generated_at", first)
+ self.assertEqual("2026-10-25T12:34:56Z", value["generated_at"])
+ self.assertEqual("a" * 64, value["tool"]["executable_sha256"])
def test_html_escapes_every_untrusted_text_and_contains_no_external_assets(self):
result = affected(component='
', reasons=[""], recommendation='x')
diff --git a/test_report_provenance.py b/test_report_provenance.py
new file mode 100644
index 0000000..d5799ab
--- /dev/null
+++ b/test_report_provenance.py
@@ -0,0 +1,118 @@
+"""Synthetic run-envelope provenance regressions; no networking."""
+import contextlib
+import csv
+import hashlib
+import io
+import json
+from pathlib import Path
+import subprocess
+import sys
+import tempfile
+import unittest
+from unittest.mock import patch
+
+import sharp_rsvg_rce_check as c
+
+STAMP = '2026-10-25T12:34:56Z'
+DIGEST = 'a' * 64
+BASE = ['--sharp-version', '0.35.4', '--library-source', 'bundled', '--sharp-build-source', 'upstream']
+
+
+class ProvenanceTests(unittest.TestCase):
+ def report(self, results=(), **extra):
+ return c.make_report(c.TOOL_NAME, c.TOOL_VERSION, c.SNAPSHOT_ID, c.RULE_DATE,
+ list(results), snapshot_digest=c.snapshot_digest(c.RULE_SNAPSHOT),
+ generated_at=STAMP, executable_sha256=DIGEST, **extra)
+
+ def test_injected_context_deterministic_and_preserved_all_formats(self):
+ record = c.normalize_record({'asset_id': 'synthetic', 'sharp_versions': ['0.35.4'],
+ 'library_source': 'bundled', 'sharp_build_source': 'upstream'})
+ report = self.report([c.assess_record(record)])
+ self.assertEqual(c.canonical_json(report), c.canonical_json(self.report(report['results'])))
+ row = next(csv.DictReader(io.StringIO(c.render_csv(report))))
+ expected = dict(tool=c.TOOL_NAME, tool_version=c.TOOL_VERSION, executable_sha256=DIGEST,
+ generated_at=STAMP, rules_snapshot_id=c.SNAPSHOT_ID,
+ rules_sha256=c.snapshot_digest(c.RULE_SNAPSHOT), rules_as_of=c.RULE_DATE)
+ for key, value in expected.items():
+ self.assertEqual(value, row[key])
+ self.assertIn(value, c.render_html(report))
+ self.assertEqual('not_tested', row['exploitability'])
+
+ def test_empty_incomplete_and_formula_safe_summary(self):
+ report = self.report(complete=False)
+ report['tool']['version'] = '=synthetic'
+ row = next(csv.DictReader(io.StringIO(c.render_csv(report))))
+ self.assertEqual('summary', row['record_type'])
+ self.assertEqual('False', row['complete'])
+ self.assertEqual("'=synthetic", row['tool_version'])
+ self.assertEqual(STAMP, row['generated_at'])
+ self.assertEqual(DIGEST, row['executable_sha256'])
+ self.assertIn('Incomplete assessment', c.render_html(report))
+
+ def test_real_timestamp_and_digest_validation(self):
+ external = json.loads((Path(c.__file__).parent / 'schemas/report-v1.schema.json').read_text(encoding='utf-8'))
+ external.pop('$schema')
+ external.pop('$id')
+ external.pop('title')
+ self.assertEqual(c.REPORT_SCHEMA, external)
+ for value in ['2026-02-30T12:00:00Z', '2026-10-25T12:00:00+00:00', STAMP+'\n']:
+ report = self.report()
+ report['generated_at'] = value
+ with self.assertRaises(c.ContractError):
+ c.validate_report(report)
+ report = self.report()
+ report['tool']['executable_sha256'] = 'private-invalid'
+ with self.assertRaises(c.ContractError):
+ c.validate_report(report)
+
+ def test_cli_context_captured_once_and_reused_after_interrupt(self):
+ for fmt in ['json', 'csv', 'html']:
+ stdout, stderr = io.StringIO(), io.StringIO()
+ real = c.canonical_json if fmt == 'json' else c.render_csv if fmt == 'csv' else c.render_html
+ name = 'canonical_json' if fmt == 'json' else 'render_csv' if fmt == 'csv' else 'render_html'
+ calls = []
+ def render(report, *args, **kwargs):
+ calls.append(report)
+ if len(calls) == 1:
+ raise KeyboardInterrupt
+ return real(report, *args, **kwargs)
+ with patch.object(c, 'utc_now', return_value=STAMP) as clock, patch.object(c, 'executable_digest', return_value=DIGEST) as digest, patch.object(c, name, side_effect=render), contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(stderr):
+ self.assertEqual(130, c.main(BASE + ['--format', fmt]))
+ self.assertEqual(1, clock.call_count)
+ self.assertEqual(1, digest.call_count)
+ self.assertEqual([STAMP, STAMP], [r['generated_at'] for r in calls])
+ self.assertFalse(calls[-1]['complete'])
+ self.assertEqual(1, len(calls[-1]['results']))
+ self.assertIn(STAMP, stdout.getvalue())
+
+ def test_cli_digest_identifies_standalone_bytes(self):
+ stdout, stderr = io.StringIO(), io.StringIO()
+ with contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(stderr):
+ self.assertEqual(0, c.main(BASE))
+ report = json.loads(stdout.getvalue())
+ self.assertEqual(hashlib.sha256(Path(c.__file__).read_bytes()).hexdigest(), report['tool']['executable_sha256'])
+ self.assertRegex(report['generated_at'], r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$')
+
+ def test_copied_and_symlink_invocations_hash_actual_executable(self):
+ with tempfile.TemporaryDirectory() as directory:
+ copied = Path(directory) / 'copied.py'
+ copied.write_bytes(Path(c.__file__).read_bytes() + b'\n# synthetic installation copy\n')
+ result = subprocess.run([sys.executable, str(copied), *BASE], capture_output=True, text=True)
+ self.assertEqual(0, result.returncode, result.stderr)
+ expected = hashlib.sha256(copied.read_bytes()).hexdigest()
+ self.assertEqual(expected, json.loads(result.stdout)['tool']['executable_sha256'])
+ linked = Path(directory) / 'linked.py'
+ try:
+ linked.symlink_to(copied)
+ except OSError:
+ self.skipTest('Symlink creation unavailable on this platform')
+ result = subprocess.run([sys.executable, str(linked), *BASE], capture_output=True, text=True)
+ self.assertEqual(0, result.returncode, result.stderr)
+ self.assertEqual(expected, json.loads(result.stdout)['tool']['executable_sha256'])
+ # Executable aliases are supported without allowing evidence aliases.
+ with self.assertRaises(c.ContractError):
+ c._read_regular_file(linked, c.MAX_JSON_BYTES)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/vendor/common.py b/vendor/common.py
index acaf830..542ea71 100644
--- a/vendor/common.py
+++ b/vendor/common.py
@@ -15,7 +15,7 @@
import stat
import tempfile
from copy import deepcopy
-from datetime import date
+from datetime import date, datetime, timezone
from pathlib import Path
from urllib.parse import urlsplit
@@ -56,6 +56,9 @@ def _array(items, maximum=1000, minimum=0):
ID_SCHEMA = {"type": "string", "pattern": r"^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}(?![\s\S])", "maxLength": 128}
DATE_SCHEMA = {"type": "string", "format": "date"}
+UTC_SCHEMA = {"type": "string", "format": "date-time", "maxLength": 20,
+ "pattern": r"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z(?![\s\S])"}
+DIGEST_SCHEMA = {"type": "string", "pattern": r"^[a-f0-9]{64}(?![\s\S])"}
URL_SCHEMA = {"type": "string", "format": "uri", "maxLength": 2048}
NULLABLE_DATE = {"anyOf": [DATE_SCHEMA, {"type": "null"}]}
NULLABLE_URL = {"anyOf": [URL_SCHEMA, {"type": "null"}]}
@@ -101,7 +104,8 @@ def _threat_schema(states):
})
REPORT_SCHEMA = _object({
"schema_version": {"const": CONTRACT_VERSION},
- "tool": _object({"name": ID_SCHEMA, "version": _text(64, min_length=1)}),
+ "tool": _object({"name": ID_SCHEMA, "version": _text(64, min_length=1), "executable_sha256": DIGEST_SCHEMA}),
+ "generated_at": UTC_SCHEMA,
"rules": _object({
"snapshot_id": ID_SCHEMA, "verified_at": DATE_SCHEMA,
"sha256": {"anyOf": [{"type": "string", "pattern": r"^[a-f0-9]{64}(?![\s\S])"}, {"type": "null"}]},
@@ -150,6 +154,13 @@ def _check_format(value, fmt, path):
date.fromisoformat(value)
except ValueError:
raise ContractError(f"{path}: invalid ISO date") from None
+ elif fmt == "date-time":
+ try:
+ if re.fullmatch(r"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z", value) is None:
+ raise ValueError
+ datetime.strptime(value, "%Y-%m-%dT%H:%M:%SZ")
+ except ValueError:
+ raise ContractError(f"{path}: expected real UTC timestamp") from None
elif fmt == "uri":
try:
parsed = urlsplit(value)
@@ -309,9 +320,25 @@ def make_result(asset_id, component, rule_id, status="unknown", *, version=None,
return validate_result(result)
+def utc_now():
+ """Run assessment time, separate from rule verification and evidence acquisition."""
+ return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
+
+
+def executable_digest():
+ """Identify actual standalone bytes; this is not deployed patch attestation."""
+ try:
+ executable = Path(__file__).resolve(strict=True)
+ except RuntimeError:
+ raise ContractError("Executable path could not be resolved") from None
+ return hashlib.sha256(_read_regular_file(executable, MAX_JSON_BYTES)).hexdigest()
+
+
def make_report(tool, tool_version, snapshot_id, rules_as_of, results, *, complete=True,
- limitations=None, snapshot_digest=None):
- report = {"schema_version": CONTRACT_VERSION, "tool": {"name": tool, "version": tool_version},
+ limitations=None, snapshot_digest=None, generated_at=None, executable_sha256=None):
+ report = {"schema_version": CONTRACT_VERSION, "tool": {"name": tool, "version": tool_version,
+ "executable_sha256": executable_digest() if executable_sha256 is None else executable_sha256},
+ "generated_at": utc_now() if generated_at is None else generated_at,
"rules": {"snapshot_id": snapshot_id, "verified_at": rules_as_of, "sha256": snapshot_digest},
"complete": complete, "limitations": deepcopy(limitations or []), "results": deepcopy(results)}
return validate_report(report)
@@ -442,19 +469,24 @@ def render_csv(report):
output = io.StringIO(newline="")
fields = ("record_type", "asset_id", "component", "version", "rule_id", "status", "version_assessment", "confidence",
"exploitability", "complete", "rules_as_of", "evidence", "preconditions", "mitigation",
- "reachability", "threat", "reasons", "recommendation", "sources", "limitations")
+ "reachability", "threat", "reasons", "recommendation", "sources", "limitations",
+ "tool", "tool_version", "executable_sha256", "generated_at", "rules_snapshot_id", "rules_sha256")
writer = csv.DictWriter(output, fieldnames=fields, lineterminator="\n")
writer.writeheader()
+ provenance = {"tool": report["tool"]["name"], "tool_version": report["tool"]["version"],
+ "executable_sha256": report["tool"]["executable_sha256"], "generated_at": report["generated_at"],
+ "rules_snapshot_id": report["rules"]["snapshot_id"], "rules_sha256": report["rules"]["sha256"] or ""}
for result in report["results"]:
row = {key: result[key] for key in fields if key in result}
row.update(record_type="result", component=result["component"]["name"], version=result["component"]["version"] or "",
complete=report["complete"], rules_as_of=report["rules"]["verified_at"], limitations=report["limitations"])
+ row.update(provenance)
writer.writerow({key: _csv_safe(json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
if isinstance(value, (dict, list)) else value) for key, value in row.items()})
if not report["results"]:
- writer.writerow({"record_type": "summary", "complete": report["complete"],
+ writer.writerow({key: _csv_safe(value) for key, value in {"record_type": "summary", "complete": report["complete"],
"rules_as_of": report["rules"]["verified_at"], "exploitability": "not_tested",
- "limitations": json.dumps(report["limitations"], ensure_ascii=False, sort_keys=True, separators=(",", ":"))})
+ "limitations": json.dumps(report["limitations"], ensure_ascii=False, sort_keys=True, separators=(",", ":")), **provenance}.items()})
return output.getvalue()
@@ -509,7 +541,8 @@ def render_html(report, brand="CompleteTech LLC", logo=None):
pre{white-space:pre-wrap;overflow-wrap:anywhere;font-size:.85rem}p,li,code{overflow-wrap:anywhere}a{color:var(--accent)}summary{cursor:pointer}
footer{font-size:.85rem;color:var(--muted)}@media print{body{background:white;color:black}article{break-inside:avoid}details>summary{display:none}details>ul,details>pre{display:block}}
""" + logo_html + "" + esc(brand) + "Security evidence report
" + esc(report["tool"]["name"]) \
- + " " + esc(report["tool"]["version"]) + " · rules verified " + esc(report["rules"]["verified_at"]) \
+ + " " + esc(report["tool"]["version"]) + " · Run assessed (UTC): " + esc(report["generated_at"]) \
+ + " · Executable SHA-256: " + esc(report["tool"]["executable_sha256"]) + " · rules verified " + esc(report["rules"]["verified_at"]) \
+ "
" + ("Completed assessment" if report["complete"] else "Incomplete assessment") \
+ "Local exploitability is not tested. Version, configuration, candidate source patterns and external exploitation reports are separate evidence.
" \
+ counts + "
" + limitations + "
" + "".join(rows) \