From 4f6c77465a0d27b237b8e98760d1bb4b67c9e564 Mon Sep 17 00:00:00 2001 From: Dr_rOot Date: Thu, 1 Oct 2026 23:14:18 +0800 Subject: [PATCH] fix: preserve approved build record bytes in release packages --- CONTRIBUTING.md | 6 ++++ SECURITY.md | 25 ++++++++++++++-- scripts/package-artifact.py | 17 +++++++---- security/action-reachability-review.json | 6 ++-- security/action-risk-review.json | 8 ++--- sources.env | 2 +- tests/test_dependency_updates.py | 2 +- tests/test_pipeline.py | 38 ++++++++++++++++++++++++ tests/test_release_workflow_security.py | 2 +- 9 files changed, 88 insertions(+), 18 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 36e6d5c..b7faaf2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -495,6 +495,12 @@ plan/visibility change, or credential rotation. ## Maintainer release checklist +`BUILD-INFO.json` in an archive must retain the exact approved `build-info.json` +bytes after complete bounded schema/provenance validation. Do not re-serialize +that record, change dependency order, or replace final byte comparison with +semantic JSON equality. Canonical metadata/SBOM descriptions are separate from +the bound original build record. + 1. Review `sources.env`, its diff history, upstream signatures, checksums, and source/toolchain BOM, minimum-OS declarations, and the derived `v-motrix.` tag. Confirm the intended current diff --git a/SECURITY.md b/SECURITY.md index 9a57977..239cfb3 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -156,6 +156,27 @@ default keychain, trust store, Action commit, source archive or toolchain change The continuing authorization is freshly bound only to `.7`, with the same 42 advisories and 2026-10-15 UTC deadline; no prior Environment approval is reused. All six earlier annotated tags remain immutable. +Formal `.7` run `36871808723` passed both genuine Developer ID signing and +exact-ZIP notarization jobs following fresh human Environment confirmation. +The isolated keychain lifecycle correction worked on both macOS architectures; +no identity lookup or notarization failure remains in that run. Both native +Windows final smoke tests also passed. All four macOS/Windows final structural +checks then failed closed at the exact `BUILD-INFO` byte comparison: the packager +re-serialized the validated record, changing formatting and potentially +dependency order instead of preserving the approved bytes. Assembly, Ed25519 signing and +publication were skipped; no public Release exists. Candidate `.8` retains one +bounded, binary, race-checked read for both complete schema/provenance validation +and archive content. Normalized dependency descriptions remain separate metadata; +the archived build record is no longer rewritten. Exact final byte comparisons +are unchanged, and malformed/duplicate/unknown records still fail validation. +Six-target public fixtures run the real isolated packaging CLI on noncanonical +valid JSON with CRLF, whitespace and reversed dependency order and prove that +the complete original bytes survive ZIP/TAR packaging without modifying input. +Signing/notarization, keychain isolation, all workflows, official Action commits, +source archives and toolchains are unchanged. The continuing authorization is +freshly bound only to `.8`, with the same 42 advisories and 2026-10-15 UTC deadline; +new protected-Environment confirmations are required, and all seven earlier +annotated tags and their run-specific signing evidence remain immutable. The protected-main prepare job checks this gate before cache restoration, source compilation, environment approvals, or signing/publishing credentials. An approval must bind every exact Action commit, the SHA-256 of the complete @@ -212,8 +233,8 @@ PGP verification is unchanged. ```bash set -euo pipefail repo=motrixapp/ffmpeg-static -tag=v9.0.2-motrix.7 -asset=ffmpeg-9.0.2-motrix.7-linux-x64.tar.gz +tag=v9.0.2-motrix.8 +asset=ffmpeg-9.0.2-motrix.8-linux-x64.tar.gz manifest=ffmpeg-manifest.json gh release verify "$tag" -R "$repo" gh release download "$tag" -R "$repo" -p "$manifest" -p "$manifest.sig" -p SHA256SUMS diff --git a/scripts/package-artifact.py b/scripts/package-artifact.py index 55f719f..53fea54 100644 --- a/scripts/package-artifact.py +++ b/scripts/package-artifact.py @@ -23,10 +23,12 @@ MAX_LICENSE_FILE_BYTES, MAX_NOTARIZATION_JSON_BYTES, PACKAGE_README, + _read_bounded_regular_file, artifact_license, artifact_stem, canonical_json, load_sources, + load_json_bytes, load_json_file, minimum_os, notarization_log_asset_name, @@ -48,12 +50,15 @@ def digest_bytes(data: bytes) -> str: def _load_build_info( path: Path, target_name: str, sources: dict[str, str], configure_args: list[str] -) -> tuple[dict[str, object], list[dict[str, str]]]: - info = load_json_file(path, "build info", maximum=256 * 1024) - normalized, dependencies = validate_build_info( +) -> tuple[bytes, list[dict[str, str]]]: + # Validate and archive the SAME bounded, race-checked binary read. Formatting + # and array order are part of the approved input bytes, not disposable data. + data = _read_bounded_regular_file(path, "build info", 256 * 1024) + info = load_json_bytes(data, "build info", maximum=256 * 1024) + _normalized, dependencies = validate_build_info( info, target_name, sources, configure_args ) - return normalized, dependencies + return data, dependencies def _license_entries( @@ -135,10 +140,10 @@ def archive_entries( configure_args = parse_configure_record(configure_data) entries.append(("configure.txt", configure_data, 0o644)) - info, dependencies = _load_build_info( + info_bytes, dependencies = _load_build_info( build_info, target_name, sources, configure_args ) - entries.append(("BUILD-INFO.json", canonical_json(info), 0o644)) + entries.append(("BUILD-INFO.json", info_bytes, 0o644)) entries.append(("README.txt", PACKAGE_README, 0o644)) license_entries, license_records = _license_entries( payload, target_name, sources diff --git a/security/action-reachability-review.json b/security/action-reachability-review.json index aa10262..3f509f4 100644 --- a/security/action-reachability-review.json +++ b/security/action-reachability-review.json @@ -2,14 +2,14 @@ "schemaVersion": 1, "status": "assessment-only", "reviewedAt": "2026-10-01", - "releaseTag": "v9.0.2-motrix.7", + "releaseTag": "v9.0.2-motrix.8", "auditReportSha256": "06e7bf28f087a2ed4ef7c4c9d244c79267b439da48924ee07081d03750cafcd1", "workflowSha256": { ".github/workflows/ci.yml": "74d679b32694fa267a8e546f59dd2658c5a80b0413bec7ea9fd6d53eaa2f7682", ".github/workflows/dependency-audit.yml": "507bdf1a9233c83eb2926f001cae71e1fa03e43830ad326491050a53d8e3364b", ".github/workflows/release.yml": "4eee054e4c8a2e14a3ed47c6152f6e7fea738d928adfec30d4b78262a71f5aaa" }, - "sourceLockSha256": "5a0746f3233815574f26aeca10889056a5b1db85297bf08df67ee8856ca4f2e3", + "sourceLockSha256": "b3ac51dbf3dc8ec472b6a4404fc5fc9d77013fc0480114aeea8ea196214cf630", "actionReferences": [ "actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6", "actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9", @@ -17,7 +17,7 @@ "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c", "actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a" ], - "decision": "Supporting static assessment only, not release authority or proof of non-reachability. On 2026-10-01 agalwood authorized corrective revisions until the first formal Release succeeds, in response to the disclosed .4 scope and unchanged 42 residual advisories through 2026-10-15 UTC. Authority is only the separately recorded maintainer decision in action-risk-review.json, bound to the complete exact scope and at most 14-day validity. This fresh record binds only v9.0.2-motrix.7 to the same complete same-day audit. Formal .6 run 36858422887 passed all 22 preceding jobs, including both Windows finalizers. After human macOS Environment confirmation, PKCS12 decoding/import and the unique valid Developer ID/Team checks passed, but both codesign identity lookups failed before any successful signature or notarization. The maintainer reuploaded canonical Base64 and the rerun failed identically. No Secret value was inspected or public Release created. The signing script omitted registration of its temporary keychain in the user search list. The .7 correction snapshots that list before create-keychain, safely parses bounded literal absolute paths without evaluation, preserves its entries/order while registering the owned keychain, and restores the snapshot before deletion on every exit. Restoration/deletion failure cannot report success. Full production-script tests use public fake commands and data, never real keychains, signatures or credentials, covering each setup/signing failure, create side effects, empty lists, literal special/space paths, malformed/bounded inventories and cleanup failures. Native macOS required CI and secret-free pre-sign jobs run these tests before candidate download/approval. Actual Developer ID signing is still tested only in the protected formal job. Unique valid Developer ID selection, SHA1 identity, explicit codesign --keychain, nonextractable imports, codesign-only access, internal Team/certificate pins, hardened runtime, timestamps and exact ZIP notarization remain. No default-keychain mutation, trust-store import, Action commit, source archive/URL, toolchain, dispatch input, API binding, cache prefix, Secret name/surface, signing environment or publication authority changes. Existing strict wrapped Base64 decoding, isolated Windows packaging/risk checks, protected binary readers, deterministic macOS baseline and bounded read-only NASM evidence remain. All 42 inventoried advisories persist, including cache service/extraction risks before validation and signature type-binding risk; none is claimed fixed or wholly unreachable. Publication still requires every exact-commit CI check, size/race/hash/byte comparison, independent rebuild, platform signing/notarization, pinned Ed25519 root, independent final verification, fresh protected-Environment confirmations and Immutable Releases. All six earlier annotated tags remain immutable; no prior Environment approval or exact-scope record is reused. New advisories, deadline extensions or unrelated source/Action updates require a new human decision.", + "decision": "Supporting static assessment only. Authority is only the separately recorded maintainer decision in action-risk-review.json, bound to the complete exact scope and at most 14-day validity. On 2026-10-01 agalwood authorized corrective revisions until the first formal Release succeeds, with the same 42 residual Action advisories (1 Critical, 18 High, 19 Medium, 4 Low) and unchanged 2026-10-15 UTC deadline. This fresh exact-scope record binds only v9.0.2-motrix.8, its source lock, every unchanged workflow byte, the unchanged complete same-day audit 36807648066 and official full-SHA Action references. Formal .7 run 36871808723 passed genuine Developer ID signing and exact-ZIP notarization on both macOS architectures after fresh Environment confirmation, plus both native Windows final smoke tests. Four final structural jobs failed closed at BUILD-INFO exact-byte comparison because packaging re-serialized the validated record. Assembly, Ed25519 signing and publication were skipped; no Release was published or Secret value inspected. The .8 correction archives the same single bounded, binary, race-checked BUILD-INFO read used for complete strict JSON/schema/provenance validation, preserving approved bytes verbatim. Normalized dependency descriptions remain separate metadata/SBOM data. All exact final byte comparisons and malformed/duplicate/unknown-record, source, configure, license and architecture checks remain. Public six-target fixtures run the real isolated packaging CLI with noncanonical valid JSON, CRLF, whitespace and reversed dependency order, proving original bytes in ZIP/TAR and unchanged input. No workflow, Action, source archive/URL, toolchain, cache policy, dispatch/API/artifact binding, Secret surface/permission, keychain isolation, certificate pin, hardened runtime, timestamp, notarization or publication authority changes. Existing strict Base64, isolated Windows packaging/risk checks, protected readers, deterministic macOS baseline and NASM evidence remain. All 42 advisories persist, including cache service/extraction risks before validation and signature type-binding risk; none is claimed fixed or wholly unreachable. Publication still requires exact-commit CI, size/race/hash/byte checks, independent rebuilds, platform signing/notarization, pinned Ed25519 authentication, independent final verification, Immutable Releases and fresh human Environment confirmations. All seven prior tags remain immutable; no prior scope, approval or run-specific signature/notarization evidence is reused for .8. Further corrections require fresh exact-scope records. New advisories, deadline extensions or unrelated source/Action updates require a new human decision. This assessment grants no release or Environment approval.", "limitations": [ "Static call-path review, not complete dynamic taint analysis, exploit testing, or proof of non-reachability.", "The lock inventory includes code beyond the selected entrypoint; findings are retained rather than suppressed.", diff --git a/security/action-risk-review.json b/security/action-risk-review.json index 83b664a..dbb31b1 100644 --- a/security/action-risk-review.json +++ b/security/action-risk-review.json @@ -4,7 +4,7 @@ "reviewedAt": "2026-10-01", "validUntil": "2026-10-15", "reviewedBy": "agalwood", - "decision": "On 2026-10-01 agalwood authorized corrective revisions until the first formal Release succeeds in response to the disclosed .4 scope and unchanged 42 residual Action advisories (1 Critical, 18 High, 19 Medium, 4 Low), retaining the 2026-10-15 UTC deadline. This fresh record binds only v9.0.2-motrix.7 to its exact source lock, every workflow byte, supporting assessment, complete same-day audit report and official full-SHA Action references. Formal .6 run 36858422887 passed all 22 preceding jobs, including both Windows finalizers. After human macOS Environment confirmation, decoding, PKCS12 import and unique valid Developer ID/Team checks passed, but both codesign identity lookups failed before a successful signature or notarization. Reuploading canonical Base64 and rerunning the same commit failed identically; no Secret contents were inspected or public Release created. The script omitted its temporary keychain from the user search list. The .7 correction snapshots that list before creation, parses bounded literal paths without evaluation, registers the owned keychain while preserving existing entries/order, and restores the original list before deletion on every exit. Cleanup failures cannot report success. Full production-script tests with public fake commands/data cover registration, setup/signing failures, create side effects, empty/literal-space/special-character paths, malformed inventories and restoration/deletion failures. They never touch a real keychain or credential, and do not claim an actual Developer ID signature. Native macOS required CI and secret-free pre-sign jobs run them before candidate download/approval. SHA1 identity selection, explicit --keychain, unique valid Developer ID, nonextractable keys, codesign-only access, internal Team/certificate pins, hardened runtime, timestamps and exact ZIP notarization remain. No default keychain, trust store, source archive/URL, toolchain, official Action commit, Secret name/permission or publication authority changes. Existing strict wrapped Base64 decoding, isolated Windows packaging/risk checks, native fresh packaging checks, protected binary-mode readers, deterministic macOS baseline and read-only bounded NASM evidence remain. Audit 36807648066 and its complete 42-advisory inventory are unchanged; none is claimed fixed or wholly unreachable, including cache service/extraction risks before validation and signature type-binding risk. Publication remains conditional on all required exact-commit CI checks, file/race/size/hash guards, independent clean rebuilds, Developer ID signing/notarization, Ed25519 authentication, independent final verification, Immutable Releases and fresh protected-Environment confirmations. All six prior annotated tags stay immutable; no previous hash binding or Environment approval is reused. Further corrective revisions need fresh exact-scope records. New advisories, deadline extensions or unrelated source/Action updates need a new human decision. This limited record grants no Environment approval, no exception for another tag or unrecorded scope, and no publication after the deadline.", + "decision": "On 2026-10-01 agalwood authorized corrective revisions until the first formal Release succeeds, with the same 42 residual Action advisories (1 Critical, 18 High, 19 Medium, 4 Low) and unchanged 2026-10-15 UTC deadline. This fresh exact-scope record binds only v9.0.2-motrix.8, its source lock, every unchanged workflow byte, the unchanged complete same-day audit 36807648066 and official full-SHA Action references. Formal .7 run 36871808723 passed genuine Developer ID signing and exact-ZIP notarization on both macOS architectures after fresh Environment confirmation, plus both native Windows final smoke tests. Four final structural jobs failed closed at BUILD-INFO exact-byte comparison because packaging re-serialized the validated record. Assembly, Ed25519 signing and publication were skipped; no Release was published or Secret value inspected. The .8 correction archives the same single bounded, binary, race-checked BUILD-INFO read used for complete strict JSON/schema/provenance validation, preserving approved bytes verbatim. Normalized dependency descriptions remain separate metadata/SBOM data. All exact final byte comparisons and malformed/duplicate/unknown-record, source, configure, license and architecture checks remain. Public six-target fixtures run the real isolated packaging CLI with noncanonical valid JSON, CRLF, whitespace and reversed dependency order, proving original bytes in ZIP/TAR and unchanged input. No workflow, Action, source archive/URL, toolchain, cache policy, dispatch/API/artifact binding, Secret surface/permission, keychain isolation, certificate pin, hardened runtime, timestamp, notarization or publication authority changes. Existing strict Base64, isolated Windows packaging/risk checks, protected readers, deterministic macOS baseline and NASM evidence remain. All 42 advisories persist, including cache service/extraction risks before validation and signature type-binding risk; none is claimed fixed or wholly unreachable. Publication still requires exact-commit CI, size/race/hash/byte checks, independent rebuilds, platform signing/notarization, pinned Ed25519 authentication, independent final verification, Immutable Releases and fresh human Environment confirmations. All seven prior tags remain immutable; no prior scope, approval or run-specific signature/notarization evidence is reused for .8. Further corrections require fresh exact-scope records. New advisories, deadline extensions or unrelated source/Action updates require a new human decision. This limited decision grants no Environment approval, no exception for another tag or unknown scope, and no publication after the deadline.", "actionReferences": [ "actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6", "actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9", @@ -57,12 +57,12 @@ "GHSA-vxpw-j846-p89q" ], "auditReportSha256": "06e7bf28f087a2ed4ef7c4c9d244c79267b439da48924ee07081d03750cafcd1", - "releaseTag": "v9.0.2-motrix.7", - "sourceLockSha256": "5a0746f3233815574f26aeca10889056a5b1db85297bf08df67ee8856ca4f2e3", + "releaseTag": "v9.0.2-motrix.8", + "sourceLockSha256": "b3ac51dbf3dc8ec472b6a4404fc5fc9d77013fc0480114aeea8ea196214cf630", "workflowSha256": { ".github/workflows/ci.yml": "74d679b32694fa267a8e546f59dd2658c5a80b0413bec7ea9fd6d53eaa2f7682", ".github/workflows/dependency-audit.yml": "507bdf1a9233c83eb2926f001cae71e1fa03e43830ad326491050a53d8e3364b", ".github/workflows/release.yml": "4eee054e4c8a2e14a3ed47c6152f6e7fea738d928adfec30d4b78262a71f5aaa" }, - "assessmentSha256": "893b60c20064a69de04d14086ce22632e6249b812034be918fed1c6c3e1e5a42" + "assessmentSha256": "8602ba441a30f8583dafc5ef474fa075db79fec5c6f07ffc16da3ba0e097ecbe" } diff --git a/sources.env b/sources.env index 65a349a..87f2c0f 100644 --- a/sources.env +++ b/sources.env @@ -2,7 +2,7 @@ # Keep this file compatible with both POSIX-style shell sourcing and the # dependency-free parser in scripts/pipeline_lib.py (plain KEY=VALUE only). -BUILD_REVISION=7 +BUILD_REVISION=8 SOURCE_DATE_EPOCH=1789699562 MACOS_MIN_VERSION=12.0 THIRD_PARTY_NOTICES_SHA256=e9e78e757a9f33e38c23107194fb86a868b5e095690d1b340852033d16a79065 diff --git a/tests/test_dependency_updates.py b/tests/test_dependency_updates.py index 2c2326f..73c9462 100644 --- a/tests/test_dependency_updates.py +++ b/tests/test_dependency_updates.py @@ -44,7 +44,7 @@ def test_recorded_scope_and_approved_and_blocked_fixtures(self) -> None: reviews.validate(self.approved_review(), self.references, self.today) reviews.validate_scope(self.review, ROOT / ".github/workflows", ROOT / "sources.env", self.review["releaseTag"], ROOT / "security/action-reachability-review.json") - self.assertEqual(self.review["releaseTag"], "v9.0.2-motrix.7") + self.assertEqual(self.review["releaseTag"], "v9.0.2-motrix.8") blocked = copy.deepcopy(self.review) blocked["status"] = "blocked" with self.assertRaisesRegex(ValueError, "formal release blocked"): diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 0875907..22d4e9a 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -1605,6 +1605,44 @@ def test_platform_runtime_notices_and_license_manifest_are_exact(self) -> None: expected, ) + def test_real_packager_preserves_approved_build_info_bytes_for_all_targets(self) -> None: + # The builder emits valid, noncanonical JSON. Package it through the + # real isolated CLI; retaining only equal parsed objects is insufficient. + for target in EXPECTED_TARGETS: + with self.subTest(target=target), tempfile.TemporaryDirectory() as temporary: + base = Path(temporary) + lock, _assets = self.make_sources(base) + payload, build_info = self.make_payload(base, target, lock) + info = json.loads(build_info.read_bytes()) + # Preserve source list order too: validation may return a + # normalized dependency list for metadata/SBOM separately. + info["dependencies"].reverse() + approved_bytes = ( + " \r\n" + json.dumps(info, indent=4, sort_keys=False) + "\r\n\t" + ).encode("utf-8") + self.assertNotEqual(approved_bytes, pipeline_lib.canonical_json(info)) + build_info.write_bytes(approved_bytes) + output = base / "out" + result = subprocess.run( + [sys.executable, "-I", str(SCRIPTS / "package-artifact.py"), + "--target", target, "--payload", str(payload), + "--build-info", str(build_info), "--output-dir", str(output), + "--sources-file", str(lock)], + cwd=ROOT, capture_output=True, text=True, check=False, timeout=30, + ) + self.assertEqual(result.returncode, 0, result.stderr) + archive = Path(result.stdout.strip()) + sources = pipeline_lib.load_sources(lock) + files = assemble_release.archive_files(archive, int(sources["SOURCE_DATE_EPOCH"])) + self.assertEqual(files["BUILD-INFO.json"], approved_bytes) + self.assertEqual(build_info.read_bytes(), approved_bytes) + # Both real final jobs must retain the exact-byte guard. A + # semantically identical whitespace mutation must still differ. + workflow = (ROOT / ".github/workflows/release.yml").read_text(encoding="utf-8") + self.assertIn('(unsigned / "build-info.json").read_bytes() != (signed / "BUILD-INFO.json").read_bytes()', workflow) + self.assertIn('(unsigned_root / "build-info.json").read_bytes() != files["BUILD-INFO.json"]', workflow) + self.assertNotEqual(approved_bytes + b" ", files["BUILD-INFO.json"]) + def test_missing_runtime_notice_is_rejected(self) -> None: with tempfile.TemporaryDirectory() as temporary: base = Path(temporary) diff --git a/tests/test_release_workflow_security.py b/tests/test_release_workflow_security.py index 010732f..6b0daaa 100644 --- a/tests/test_release_workflow_security.py +++ b/tests/test_release_workflow_security.py @@ -596,7 +596,7 @@ def test_deployed_trust_reference_does_not_approve_action_risks(self) -> None: review = json.loads((ROOT / "security/action-risk-review.json").read_bytes()) self.assertIn("does not approve these risks", security) self.assertIn("explicit maintainer", security) - self.assertEqual(review["releaseTag"], "v9.0.2-motrix.7") + self.assertEqual(review["releaseTag"], "v9.0.2-motrix.8") self.assertEqual(review["auditReportSha256"], hashlib.sha256(report).hexdigest()) def test_public_readmes_are_user_facing_download_guides(self) -> None: