Add honest SDA deployment-source evidence

#3
README.md CHANGED
@@ -100,14 +100,23 @@ receipt — never inflated.**
100
 
101
  ## Tech / sovereignty
102
 
103
- Pure static HTML/CSS/JS. **0 runtime CDN** — `three.js` r160 (MIT) is **vendored** locally under
104
  `assets/three.module.min.js` (see `assets/THREE_LICENSE.txt`). The COP canvas, score panel, verify widget,
105
- and fabric reader are self-contained. **System fonts only** (Calibri / system-ui stack). No server,
106
- no build step.
107
 
108
  Mobile system per the estate mobile spec: ≥12px font floor, ≥44px tap targets, `safe-area-inset`,
109
  0px horizontal overflow at 320/360/390/768, `prefers-reduced-motion`, WCAG AA.
110
 
 
 
 
 
 
 
 
 
 
111
  ## Branding
112
 
113
  Deep-space dark, teal `#01696F` / cyan `#3DD6FF` / violet `#7C5CFF` glow, glassmorphism, system fonts —
 
100
 
101
  ## Tech / sovereignty
102
 
103
+ Static HTML/CSS/JS behind a small hardened read-only Python file server. **0 runtime CDN** — `three.js` r160 (MIT) is **vendored** locally under
104
  `assets/three.module.min.js` (see `assets/THREE_LICENSE.txt`). The COP canvas, score panel, verify widget,
105
+ and fabric reader are self-contained. **System fonts only** (Calibri / system-ui stack). There is no
106
+ application database, write API, or frontend build step.
107
 
108
  Mobile system per the estate mobile spec: ≥12px font floor, ≥44px tap targets, `safe-area-inset`,
109
  0px horizontal overflow at 320/360/390/768, `prefers-reduced-motion`, WCAG AA.
110
 
111
+ ### Deployment-source evidence
112
+
113
+ `GET /.well-known/szl-source.json` reports the measured Hugging Face repository head and the
114
+ source-resolution boundary. The inferred name-matched repository `szl-holdings/sda` returned GitHub
115
+ `404`, so the document states `PENDING_SOURCE_RESOLUTION` / `UNKNOWN`, leaves `source.commit` null,
116
+ and explicitly does not claim GitHub parity, a reproducible build, or exact serving-process provenance.
117
+ `?refresh=1` bypasses the short repository-head cache. The response is read-only, `no-store`, and
118
+ inherits the same security headers as the rest of the Space.
119
+
120
  ## Branding
121
 
122
  Deep-space dark, teal `#01696F` / cyan `#3DD6FF` / violet `#7C5CFF` glow, glassmorphism, system fonts —
server.py CHANGED
@@ -18,10 +18,32 @@ read-only cross-origin verify fetches to a-11-oy.com and killinchu, so the
18
  WebGL scene and the SDA verify widget keep working.
19
  """
20
  import functools
 
21
  from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
 
 
 
22
 
23
  PORT = 7860
24
  DIRECTORY = "/app"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  CONTENT_SECURITY_POLICY = (
27
  "default-src 'self'; "
@@ -44,6 +66,33 @@ class HardenedHandler(SimpleHTTPRequestHandler):
44
  def version_string(self):
45
  return "szl"
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  def end_headers(self):
48
  self.send_header("Content-Security-Policy", CONTENT_SECURITY_POLICY)
49
  self.send_header(
 
18
  WebGL scene and the SDA verify widget keep working.
19
  """
20
  import functools
21
+ import json
22
  from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
23
+ from urllib.parse import parse_qs, urlsplit
24
+
25
+ from szl_source_attestation import build_attestation
26
 
27
  PORT = 7860
28
  DIRECTORY = "/app"
29
+ SPACE_ID = "SZLHOLDINGS/sda"
30
+ HF_OVERLAY_BASE_REVISION = "05cd77a1e728f59ab920e04bd632e7ff64a25b2e"
31
+ SOURCE_OBSERVATION = {
32
+ "repository": "szl-holdings/sda",
33
+ "commit": None,
34
+ "path": "",
35
+ "state": "PENDING_SOURCE_RESOLUTION",
36
+ "relation": "UNKNOWN",
37
+ "evidence_url": "https://api.github.com/repos/szl-holdings/sda",
38
+ "observation": {
39
+ "observed_at": "2026-07-11T22:00:20Z",
40
+ "http_status": 404,
41
+ "meaning": (
42
+ "The inferred name-matched GitHub repository was not found. "
43
+ "No source commit or parity claim is available."
44
+ ),
45
+ },
46
+ }
47
 
48
  CONTENT_SECURITY_POLICY = (
49
  "default-src 'self'; "
 
66
  def version_string(self):
67
  return "szl"
68
 
69
+ def _send_json(self, payload, status=200):
70
+ body = json.dumps(payload, sort_keys=True, separators=(",", ":")).encode("utf-8")
71
+ self.send_response(status)
72
+ self.send_header("Content-Type", "application/json; charset=utf-8")
73
+ self.send_header("Content-Length", str(len(body)))
74
+ self.send_header("Cache-Control", "no-store")
75
+ self.send_header("X-SZL-Transport-State", "REACHABLE")
76
+ self.send_header("X-SZL-Evidence-State", payload.get("evidence_state", "UNAVAILABLE"))
77
+ self.send_header("X-SZL-Authority-State", "READ_ONLY")
78
+ self.end_headers()
79
+ self.wfile.write(body)
80
+
81
+ def do_GET(self):
82
+ parsed = urlsplit(self.path)
83
+ if parsed.path == "/.well-known/szl-source.json":
84
+ force = parse_qs(parsed.query).get("refresh", ["0"])[0] == "1"
85
+ payload = build_attestation(
86
+ space_id=SPACE_ID,
87
+ source=SOURCE_OBSERVATION,
88
+ alignment_state="UNKNOWN",
89
+ overlay_base_revision=HF_OVERLAY_BASE_REVISION,
90
+ force=force,
91
+ )
92
+ self._send_json(payload)
93
+ return
94
+ super().do_GET()
95
+
96
  def end_headers(self):
97
  self.send_header("Content-Security-Policy", CONTENT_SECURITY_POLICY)
98
  self.send_header(
szl_source_attestation.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Honest deployment-source evidence for a public Hugging Face Space.
2
+
3
+ The Hugging Face repository head is measured independently from GitHub source
4
+ observations. A source reference never implies byte parity, a reproducible
5
+ build, or proof of the exact process revision during a rolling deployment.
6
+ """
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ import re
11
+ import threading
12
+ import time
13
+ import urllib.request
14
+ from datetime import datetime, timezone
15
+ from typing import Any
16
+
17
+
18
+ _SHA = re.compile(r"^[0-9a-f]{40}$")
19
+ _CACHE_LOCK = threading.Lock()
20
+ _CACHE: dict[str, dict[str, Any]] = {}
21
+
22
+
23
+ def _now_iso() -> str:
24
+ return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
25
+
26
+
27
+ def _valid_sha(value: object) -> str | None:
28
+ candidate = str(value or "").strip().lower()
29
+ return candidate if _SHA.fullmatch(candidate) else None
30
+
31
+
32
+ def measure_hf_head(space_id: str, force: bool = False) -> dict[str, Any]:
33
+ """Measure the Hub repository head; never label it as process provenance."""
34
+ now = time.monotonic()
35
+ with _CACHE_LOCK:
36
+ cached = _CACHE.get(space_id)
37
+ if not force and cached and now - float(cached["stored_at"]) < 60:
38
+ return dict(cached["measurement"])
39
+
40
+ endpoint = (
41
+ f"https://huggingface.co/api/spaces/{space_id}"
42
+ "?expand[]=sha&expand[]=lastModified"
43
+ )
44
+ request = urllib.request.Request(
45
+ endpoint,
46
+ headers={
47
+ "Accept": "application/json",
48
+ "User-Agent": "szl-source-attestation/2.0",
49
+ },
50
+ )
51
+ revision = None
52
+ last_modified = None
53
+ error = None
54
+ try:
55
+ with urllib.request.urlopen(request, timeout=4) as response:
56
+ payload = json.load(response)
57
+ revision = _valid_sha(payload.get("sha"))
58
+ candidate_time = payload.get("lastModified")
59
+ if isinstance(candidate_time, str) and "T" in candidate_time:
60
+ last_modified = candidate_time
61
+ except Exception as exc: # the contract reports unavailability, never guesses
62
+ error = type(exc).__name__
63
+
64
+ measurement: dict[str, Any] = {
65
+ "hf_revision": revision,
66
+ "last_modified": last_modified,
67
+ "observed_at": _now_iso(),
68
+ "state": "MEASURED" if revision else "UNAVAILABLE",
69
+ "method": "HUGGINGFACE_API" if revision else "UNAVAILABLE",
70
+ "resolver": endpoint,
71
+ }
72
+ if error:
73
+ measurement["error"] = error
74
+ with _CACHE_LOCK:
75
+ _CACHE[space_id] = {
76
+ "stored_at": time.monotonic(),
77
+ "measurement": dict(measurement),
78
+ }
79
+ return measurement
80
+
81
+
82
+ def build_attestation(
83
+ *,
84
+ space_id: str,
85
+ source: dict[str, Any],
86
+ alignment_state: str,
87
+ overlay_base_revision: str,
88
+ force: bool = False,
89
+ ) -> dict[str, Any]:
90
+ measurement = measure_hf_head(space_id, force=force)
91
+ revision = measurement["hf_revision"]
92
+ return {
93
+ "schema": "szl.deployment-source/v1",
94
+ "source": dict(source),
95
+ "deployment": {
96
+ "hf_space": space_id,
97
+ "hf_revision": revision,
98
+ },
99
+ "built_at": measurement["last_modified"],
100
+ "observed_at": measurement["observed_at"],
101
+ "transport_state": "REACHABLE",
102
+ "evidence_state": "COMPUTED" if revision else "UNAVAILABLE",
103
+ "verification_state": "STRUCTURAL_ONLY",
104
+ "authority_state": "READ_ONLY",
105
+ "alignment_state": alignment_state,
106
+ "attestation_state": "UNSIGNED_STRUCTURAL",
107
+ "claims": {
108
+ "github_parity": "NOT_CLAIMED",
109
+ "reproducible_build": "NOT_CLAIMED",
110
+ "running_process_revision": "NOT_CLAIMED",
111
+ },
112
+ "extensions": {
113
+ "schema": "szl.deployment-source-evidence/v1",
114
+ "deployment_revision_evidence": {
115
+ **measurement,
116
+ "semantics": (
117
+ "Measured Hugging Face repository head; external verification "
118
+ "must confirm runtime SHA convergence after deployment."
119
+ ),
120
+ },
121
+ "overlay": {
122
+ "base_revision": overlay_base_revision,
123
+ "base_revision_semantics": (
124
+ "Hugging Face head inspected before this attestation overlay."
125
+ ),
126
+ },
127
+ },
128
+ "limits": [
129
+ "The Hugging Face revision is measured independently from GitHub evidence.",
130
+ "A GitHub observation does not establish deployed-artifact equivalence.",
131
+ "Repository-head evidence is not proof of the exact process revision during a rolling deploy.",
132
+ "This unsigned structural document does not establish SLSA provenance or reproducible builds.",
133
+ ],
134
+ }
135
+
tests/test_source_attestation.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import functools
4
+ import json
5
+ import sys
6
+ import threading
7
+ import unittest
8
+ from http.server import ThreadingHTTPServer
9
+ from pathlib import Path
10
+ from unittest.mock import patch
11
+ from urllib.request import urlopen
12
+
13
+
14
+ ROOT = Path(__file__).resolve().parents[1]
15
+ sys.path.insert(0, str(ROOT))
16
+ import server # noqa: E402
17
+ import szl_source_attestation # noqa: E402
18
+
19
+
20
+ MEASUREMENT = {
21
+ "hf_revision": "a" * 40,
22
+ "last_modified": "2026-07-11T22:00:00.000Z",
23
+ "observed_at": "2026-07-11T22:00:01Z",
24
+ "state": "MEASURED",
25
+ "method": "TEST_FIXTURE",
26
+ "resolver": "https://example.invalid/hf-head",
27
+ }
28
+
29
+
30
+ class SourceAttestationTests(unittest.TestCase):
31
+ def test_unknown_source_never_invents_commit_or_parity(self):
32
+ with patch.object(szl_source_attestation, "measure_hf_head", return_value=MEASUREMENT):
33
+ payload = szl_source_attestation.build_attestation(
34
+ space_id=server.SPACE_ID,
35
+ source=server.SOURCE_OBSERVATION,
36
+ alignment_state="UNKNOWN",
37
+ overlay_base_revision=server.HF_OVERLAY_BASE_REVISION,
38
+ )
39
+ self.assertIsNone(payload["source"]["commit"])
40
+ self.assertEqual("PENDING_SOURCE_RESOLUTION", payload["source"]["state"])
41
+ self.assertEqual("UNKNOWN", payload["source"]["relation"])
42
+ self.assertEqual("UNKNOWN", payload["alignment_state"])
43
+ self.assertEqual("NOT_CLAIMED", payload["claims"]["github_parity"])
44
+ self.assertEqual("a" * 40, payload["deployment"]["hf_revision"])
45
+
46
+ def test_well_known_route_is_json_no_store_and_hardened(self):
47
+ handler = functools.partial(server.HardenedHandler, directory=str(ROOT))
48
+ httpd = ThreadingHTTPServer(("127.0.0.1", 0), handler)
49
+ thread = threading.Thread(target=httpd.serve_forever, daemon=True)
50
+ thread.start()
51
+ try:
52
+ with patch.object(szl_source_attestation, "measure_hf_head", return_value=MEASUREMENT):
53
+ with urlopen(
54
+ f"http://127.0.0.1:{httpd.server_port}/.well-known/szl-source.json?refresh=1",
55
+ timeout=3,
56
+ ) as response:
57
+ payload = json.load(response)
58
+ self.assertEqual(200, response.status)
59
+ self.assertEqual("application/json; charset=utf-8", response.headers["Content-Type"])
60
+ self.assertEqual("no-store", response.headers["Cache-Control"])
61
+ self.assertEqual("nosniff", response.headers["X-Content-Type-Options"])
62
+ self.assertIn("default-src 'self'", response.headers["Content-Security-Policy"])
63
+ self.assertEqual("COMPUTED", response.headers["X-SZL-Evidence-State"])
64
+ self.assertEqual("UNKNOWN", payload["alignment_state"])
65
+ finally:
66
+ httpd.shutdown()
67
+ httpd.server_close()
68
+ thread.join(timeout=3)
69
+
70
+
71
+ if __name__ == "__main__":
72
+ unittest.main()
73
+