From ea90feb8c8240c7cc465d74ed4f135705e02a87b Mon Sep 17 00:00:00 2001 From: Oleksii-debug Date: Sun, 13 Sep 2026 07:31:09 +0200 Subject: [PATCH 01/42] R06 QA: make research label binding assertion semantic --- .../repair_overlay/tests/test_research_persistence_ui.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lanes/dev1/repair_overlay/tests/test_research_persistence_ui.py b/lanes/dev1/repair_overlay/tests/test_research_persistence_ui.py index cec30098a..c8bef4bd7 100644 --- a/lanes/dev1/repair_overlay/tests/test_research_persistence_ui.py +++ b/lanes/dev1/repair_overlay/tests/test_research_persistence_ui.py @@ -61,7 +61,10 @@ def test_dynamic_content_uses_safe_dom_text(self): for forbidden in ('innerHTML','outerHTML','insertAdjacentHTML','localStorage','sessionStorage','eval(','new Function'): self.assertNotIn(forbidden,self.ui) self.assertIn("status.setAttribute('role','status')",self.ui) - self.assertIn("label.htmlFor",self.ui) + label_vars=set(re.findall(r"\b([A-Za-z_$][\w$]*)\s*=\s*text\('label'",self.ui)) + bound_vars=set(re.findall(r"\b([A-Za-z_$][\w$]*)\.htmlFor\s*=\s*[A-Za-z_$][\w$]*\.id\b",self.ui)) + self.assertGreaterEqual(len(label_vars),4) + self.assertTrue(label_vars.issubset(bound_vars),f"labels missing htmlFor bindings: {sorted(label_vars-bound_vars)}") def test_session_pins_remain_separate(self): self.assertIn('this.pinned=new Set()',self.workbench) From aaab89d4c60cb08e76f38fb9be0278433a4d29a5 Mon Sep 17 00:00:00 2001 From: Oleksii-debug Date: Sun, 13 Sep 2026 07:40:50 +0200 Subject: [PATCH 02/42] R06 QA: make diagnostics blob check newline-portable --- lanes/dev1/repair_overlay/tests/test_packaged_diagnostics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lanes/dev1/repair_overlay/tests/test_packaged_diagnostics.py b/lanes/dev1/repair_overlay/tests/test_packaged_diagnostics.py index 7ec23cb6b..38488669a 100644 --- a/lanes/dev1/repair_overlay/tests/test_packaged_diagnostics.py +++ b/lanes/dev1/repair_overlay/tests/test_packaged_diagnostics.py @@ -128,7 +128,7 @@ def test_non_diagnostics_commands_delegate_unchanged(self): def test_packaged_stack_reuses_exact_qualified_diagnostics_core_blob(self): core = repository_root() / "runtime_engine" / "scripture_archive_runtime" / "diagnostics.py" - self.assertEqual(QUALIFIED_DIAGNOSTICS_BLOB, git_blob_sha(core.read_bytes())) + self.assertEqual(QUALIFIED_DIAGNOSTICS_BLOB, git_blob_sha(core.read_text(encoding="utf-8").encode("utf-8"))) def test_frontend_is_semantic_empty_payload_and_text_only(self): platform = Path(__file__).resolve().parents[1] From e1e855c560c2d020a4a1fd7f90a21ca163497631 Mon Sep 17 00:00:00 2001 From: Oleksii-debug Date: Sun, 13 Sep 2026 08:23:38 +0200 Subject: [PATCH 03/42] Fix release secret scan private-key file coverage --- runtime_engine/scripture_archive_runtime/release_security.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime_engine/scripture_archive_runtime/release_security.py b/runtime_engine/scripture_archive_runtime/release_security.py index 60fb3ba32..2133b7001 100644 --- a/runtime_engine/scripture_archive_runtime/release_security.py +++ b/runtime_engine/scripture_archive_runtime/release_security.py @@ -9,7 +9,7 @@ SKIP_DIRS = {".git", ".venv", "venv", "__pycache__", "build", "dist", ".pytest_cache", ".mypy_cache"} FORBIDDEN_BASENAMES = {".env", "token.json", "credentials.json", "cookies.txt", "cookies.sqlite", "session.json"} TEXT_SUFFIXES = { - "", ".cfg", ".css", ".csv", ".html", ".ini", ".js", ".json", ".md", ".ps1", ".py", ".toml", ".tsv", ".txt", ".xml", ".yaml", ".yml", + "", ".cfg", ".css", ".csv", ".html", ".ini", ".js", ".json", ".key", ".md", ".pem", ".ps1", ".py", ".toml", ".tsv", ".txt", ".xml", ".yaml", ".yml", } PLACEHOLDER_MARKERS = ("EXAMPLE", "PLACEHOLDER", "REDACTED", "CHANGEME", "YOUR_KEY", "YOUR-KEY") From 246194467829326e7bec7b0a3a078a0eb2e0c096 Mon Sep 17 00:00:00 2001 From: Oleksii-debug Date: Sun, 13 Sep 2026 08:23:57 +0200 Subject: [PATCH 04/42] Add tree-level private-key container regression --- runtime_engine/tests/test_release_security.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/runtime_engine/tests/test_release_security.py b/runtime_engine/tests/test_release_security.py index f36f15b19..b473b7a6c 100644 --- a/runtime_engine/tests/test_release_security.py +++ b/runtime_engine/tests/test_release_security.py @@ -24,6 +24,22 @@ def test_private_key_header_is_flagged(self): findings = scan_text(private_key_header + "\nabc\n", "key.pem") self.assertEqual([finding.rule for finding in findings], ["PRIVATE_KEY"]) + def test_private_key_container_files_are_tree_scanned_and_blocking(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + private_key_header = "-----BEGIN " + "PRIVATE KEY-----" + for filename in ("release.pem", "signing.key"): + (root / filename).write_text(private_key_header + "\nabc\n", encoding="utf-8") + report = scan_tree_report(root) + self.assertFalse(report.passed) + self.assertEqual(report.unverified_file_count, 0) + self.assertEqual(report.skipped_file_count, 0) + self.assertEqual(report.verified_file_count, 2) + self.assertEqual( + {(finding.path, finding.rule) for finding in report.findings}, + {("release.pem", "PRIVATE_KEY"), ("signing.key", "PRIVATE_KEY")}, + ) + def test_forbidden_secret_filename_is_flagged(self): with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) From 32cf8913220138e6c06667f368a27f419a5ca708 Mon Sep 17 00:00:00 2001 From: Oleksii-debug Date: Sun, 13 Sep 2026 08:26:52 +0200 Subject: [PATCH 05/42] Cover armored private-key header variants --- runtime_engine/scripture_archive_runtime/release_security.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime_engine/scripture_archive_runtime/release_security.py b/runtime_engine/scripture_archive_runtime/release_security.py index 2133b7001..e8c94fe80 100644 --- a/runtime_engine/scripture_archive_runtime/release_security.py +++ b/runtime_engine/scripture_archive_runtime/release_security.py @@ -14,7 +14,7 @@ PLACEHOLDER_MARKERS = ("EXAMPLE", "PLACEHOLDER", "REDACTED", "CHANGEME", "YOUR_KEY", "YOUR-KEY") _SECRET_PATTERNS: tuple[tuple[str, re.Pattern[str]], ...] = ( - ("PRIVATE_KEY", re.compile(r"-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----")), + ("PRIVATE_KEY", re.compile(r"-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY(?: BLOCK)?-----")), ("OPENAI_API_KEY", re.compile(r"\bsk-[A-Za-z0-9_-]{20,}\b")), ("GITHUB_TOKEN", re.compile(r"\bgh[pousr]_[A-Za-z0-9]{30,}\b")), ("AWS_ACCESS_KEY", re.compile(r"\bAKIA[0-9A-Z]{16}\b")), From 0813afa06e485797dc86361f8b64356571dfe041 Mon Sep 17 00:00:00 2001 From: Oleksii-debug Date: Sun, 13 Sep 2026 08:27:14 +0200 Subject: [PATCH 06/42] Regress armored private-key header variants --- runtime_engine/tests/test_release_security.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/runtime_engine/tests/test_release_security.py b/runtime_engine/tests/test_release_security.py index b473b7a6c..aade5c20d 100644 --- a/runtime_engine/tests/test_release_security.py +++ b/runtime_engine/tests/test_release_security.py @@ -24,6 +24,13 @@ def test_private_key_header_is_flagged(self): findings = scan_text(private_key_header + "\nabc\n", "key.pem") self.assertEqual([finding.rule for finding in findings], ["PRIVATE_KEY"]) + def test_armored_private_key_header_variants_are_flagged(self): + for label in ("ENCRYPTED PRIVATE KEY", "DSA PRIVATE KEY", "PGP PRIVATE KEY BLOCK"): + with self.subTest(label=label): + private_key_header = "-----BEGIN " + label + "-----" + findings = scan_text(private_key_header + "\nabc\n", "key.pem") + self.assertEqual([finding.rule for finding in findings], ["PRIVATE_KEY"]) + def test_private_key_container_files_are_tree_scanned_and_blocking(self): with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) From 349befdb1c0b0ecf85b7d62a10bd8f6ebe421195 Mon Sep 17 00:00:00 2001 From: Oleksii-debug Date: Sun, 13 Sep 2026 08:29:10 +0200 Subject: [PATCH 07/42] Add regression for local update open-file identity --- ...test_application_update_openfd_identity.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 runtime_engine/tests/test_application_update_openfd_identity.py diff --git a/runtime_engine/tests/test_application_update_openfd_identity.py b/runtime_engine/tests/test_application_update_openfd_identity.py new file mode 100644 index 000000000..5b425d2b5 --- /dev/null +++ b/runtime_engine/tests/test_application_update_openfd_identity.py @@ -0,0 +1,57 @@ +import hashlib +from pathlib import Path +import tempfile +import unittest +from unittest.mock import patch + +from scripture_archive_runtime.application_update import ( + ApplicationUpdateError, + ApplicationUpdateManifest, + UPDATE_MANIFEST_SCHEMA, + verify_local_update, +) + + +SOURCE_HEAD = "9dc82b50ac82de00e3af9ee7a58204982d39217d" +VERIFIED_BYTES = b"scripture-archive-release-bytes\x00\x01" + + +class ApplicationUpdateOpenIdentityTests(unittest.TestCase): + def test_opened_descriptor_must_match_prechecked_path_identity(self): + manifest = ApplicationUpdateManifest.from_mapping( + { + "schema": UPDATE_MANIFEST_SCHEMA, + "product_id": "scripture-archive", + "target_platform": "windows-x64", + "target_version": "1.2.0", + "source_head": SOURCE_HEAD, + "artifact_name": "ScriptureArchive-1.2.0-win-x64.zip", + "artifact_size": len(VERIFIED_BYTES), + "artifact_sha256": hashlib.sha256(VERIFIED_BYTES).hexdigest(), + } + ) + + with tempfile.TemporaryDirectory() as temp: + root = Path(temp) + path = root / manifest.artifact_name + substitute = root / "substitute.zip" + path.write_bytes(b"X" * len(VERIFIED_BYTES)) + substitute.write_bytes(VERIFIED_BYTES) + + real_open = Path.open + + def redirected_open(candidate, *args, **kwargs): + if candidate == path: + return real_open(substitute, *args, **kwargs) + return real_open(candidate, *args, **kwargs) + + with patch.object(Path, "open", new=redirected_open): + with self.assertRaisesRegex( + ApplicationUpdateError, + "opened artifact identity does not match verified path", + ): + verify_local_update(manifest, path, current_version="1.1.0") + + +if __name__ == "__main__": + unittest.main() From de2ebdaf6aba0a9a39754f0fc9a3fef2ad3e42be Mon Sep 17 00:00:00 2001 From: Oleksii-debug Date: Sun, 13 Sep 2026 08:30:05 +0200 Subject: [PATCH 08/42] Bind application update verification to opened file identity --- .../application_update.py | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/runtime_engine/scripture_archive_runtime/application_update.py b/runtime_engine/scripture_archive_runtime/application_update.py index 4d621a301..f39ed818d 100644 --- a/runtime_engine/scripture_archive_runtime/application_update.py +++ b/runtime_engine/scripture_archive_runtime/application_update.py @@ -222,9 +222,10 @@ def verify_local_update( """Verify a local regular file without unpacking or executing it. The file name must exactly match the manifest. Symlinks and non-regular files - are rejected. Metadata is checked before and after hashing to fail closed if - the file changes during verification. A host must still bind any later install - step to this exact digest/size rather than trusting a mutable path. + are rejected. The opened file descriptor is identity-bound to the path both + before and after hashing so path-resolution swaps fail closed. A host must + still bind any later install step to this exact digest/size rather than + trusting a mutable path. """ manifest = _validated_manifest(manifest) @@ -240,10 +241,23 @@ def verify_local_update( raise ApplicationUpdateError("local artifact must be a regular non-symlink file") if before.st_size != manifest.artifact_size: raise ApplicationUpdateError("artifact size does not match manifest") + + before_identity = (before.st_dev, before.st_ino, before.st_size, before.st_mtime_ns) digest = hashlib.sha256() total = 0 try: with path.open("rb") as handle: + opened_before = os.fstat(handle.fileno()) + if not stat.S_ISREG(opened_before.st_mode): + raise ApplicationUpdateError("opened local artifact must be a regular file") + opened_before_identity = ( + opened_before.st_dev, + opened_before.st_ino, + opened_before.st_size, + opened_before.st_mtime_ns, + ) + if opened_before_identity != before_identity: + raise ApplicationUpdateError("opened artifact identity does not match verified path") while True: chunk = handle.read(1024 * 1024) if not chunk: @@ -252,6 +266,15 @@ def verify_local_update( if total > manifest.artifact_size: raise ApplicationUpdateError("artifact grew during verification") digest.update(chunk) + opened_after = os.fstat(handle.fileno()) + opened_after_identity = ( + opened_after.st_dev, + opened_after.st_ino, + opened_after.st_size, + opened_after.st_mtime_ns, + ) + if opened_after_identity != opened_before_identity: + raise ApplicationUpdateError("opened artifact changed during verification") after = path.lstat() except ApplicationUpdateError: raise @@ -259,7 +282,6 @@ def verify_local_update( raise ApplicationUpdateError("local artifact could not be verified") from exc if stat.S_ISLNK(after.st_mode) or not stat.S_ISREG(after.st_mode): raise ApplicationUpdateError("local artifact type changed during verification") - before_identity = (before.st_dev, before.st_ino, before.st_size, before.st_mtime_ns) after_identity = (after.st_dev, after.st_ino, after.st_size, after.st_mtime_ns) if before_identity != after_identity or total != manifest.artifact_size: raise ApplicationUpdateError("local artifact changed during verification") From effaca26cbb4b292e4cb7cdd7f4949be1979e43a Mon Sep 17 00:00:00 2001 From: Oleksii-debug Date: Sun, 13 Sep 2026 08:31:18 +0200 Subject: [PATCH 09/42] Fail closed on malformed Constructor draft imports --- .../scripture_archive_platform/authoring/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lanes/dev1/repair_overlay/scripture_archive_platform/authoring/service.py b/lanes/dev1/repair_overlay/scripture_archive_platform/authoring/service.py index afbd33975..a7030c66a 100644 --- a/lanes/dev1/repair_overlay/scripture_archive_platform/authoring/service.py +++ b/lanes/dev1/repair_overlay/scripture_archive_platform/authoring/service.py @@ -353,7 +353,7 @@ def import_draft(self, text: str) -> dict[str, Any]: obj = json.loads(text) if not isinstance(obj, dict) or obj.get("draft_schema") != DRAFT_SCHEMA: raise ValueError("invalid imported draft") - obj = self._json_copy(obj) + obj = self._envelope(obj) now = int(self.clock()) obj["draft_id"] = "draft-" + self.id_factory() obj["status"] = "DRAFT" From 58cb0fe685be6b003037538d85cb78d82a5b6f6a Mon Sep 17 00:00:00 2001 From: Oleksii-debug Date: Sun, 13 Sep 2026 08:31:54 +0200 Subject: [PATCH 10/42] Regress malformed Constructor draft imports --- .../tests/test_constructor_v2_lifecycle.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lanes/dev1/repair_overlay/tests/test_constructor_v2_lifecycle.py b/lanes/dev1/repair_overlay/tests/test_constructor_v2_lifecycle.py index 02f929801..4cfeaf073 100644 --- a/lanes/dev1/repair_overlay/tests/test_constructor_v2_lifecycle.py +++ b/lanes/dev1/repair_overlay/tests/test_constructor_v2_lifecycle.py @@ -1,4 +1,5 @@ import itertools +import json import tempfile import unittest from pathlib import Path @@ -129,6 +130,38 @@ def test_cross_draft_snapshot_and_version_restore_are_rejected(self): with self.assertRaisesRegex(ValueError, "another draft"): self.service.rollback_version(second["draft_id"], version["version_id"]) + def test_import_draft_validates_envelope_before_persistence(self): + source = self._campaign("Import source") + exported = json.loads(self.service.export_draft(source["draft_id"])) + baseline = set(self.service.store.list_keys("drafts")) + + malformed = [] + bad_kind = json.loads(json.dumps(exported)) + bad_kind["kind"] = "bogus" + bad_kind["base_identity"] = {"bogus": "ZZ-CAMPAIGN"} + malformed.append((bad_kind, "kind must be campaign, mission or node")) + + bad_title = json.loads(json.dumps(exported)) + bad_title["title"] = "" + malformed.append((bad_title, "title must be 1..300 characters")) + + bad_record = json.loads(json.dumps(exported)) + bad_record["node"] = [] + malformed.append((bad_record, "node must be an object")) + + for payload, expected_error in malformed: + with self.subTest(expected_error=expected_error): + with self.assertRaisesRegex(ValueError, expected_error): + self.service.import_draft(json.dumps(payload)) + self.assertEqual(baseline, set(self.service.store.list_keys("drafts"))) + + exported["campaign"]["player_promise"] = "" + imported = self.service.import_draft(json.dumps(exported)) + self.assertNotEqual(source["draft_id"], imported["draft_id"]) + self.assertEqual("import_data_only", imported["change_record"][0]["action"]) + self.assertIn("