From 4f5292d4b837de8641ed8e865acb806034ce8ae2 Mon Sep 17 00:00:00 2001 From: Timothy Wayne Gregg Date: Sun, 25 Oct 2026 21:16:26 -0400 Subject: [PATCH 1/2] Reject unsupported OCI artifact filesystem semantics --- README.md | 9 +++++ SHA256SUMS | 2 +- oci_runtime_inventory.py | 14 ++++++- test_artifact_semantics.py | 78 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 test_artifact_semantics.py diff --git a/README.md b/README.md index 21874e7..58d50a5 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,15 @@ checker's accepted fields. Preserve the process exit code as well as the output. - OCI plain-TAR or gzip layers; Docker-save plain-TAR layers. Extended PAX/GNU long-name/sparse records, zstd, foreign layers, unsupported digests, outer gzip and other archive formats are unresolved, not silently accepted as complete. +- OCI-layout descriptors must explicitly identify an OCI image manifest/index + or Docker schema-2 manifest/list. An optional manifest `mediaType` must match + its descriptor. Only OCI image-config or Docker image-config media types + authorize filesystem interpretation; the config bytes remain opaque and + digest-verified. Manifests declaring `artifactType`, empty artifact configs, + missing config media types and unknown descriptor/config types are incomplete + artifact records with no package observations or consumer records. Verified + manifest digests remain in canonical output, and supported image siblings + retain their observations. - JSON CycloneDX 1.4/1.5/1.6, including metadata.component and nested components; SPDX 2.2/2.3 package metadata. This reads selected metadata fields, not full SBOM conformance or deployment/relationship attestation. diff --git a/SHA256SUMS b/SHA256SUMS index a86d025..26b77cb 100644 --- a/SHA256SUMS +++ b/SHA256SUMS @@ -1 +1 @@ -b6422d9849a64a4fe54a316a1d64f3fed4a20f52486697990b1d9bc08e6547f2 oci_runtime_inventory.py +21d6cbd46b86c101b346d507ed0de30af6f6655fc8b4825ce7b6c2b0ec44c4fe oci_runtime_inventory.py diff --git a/oci_runtime_inventory.py b/oci_runtime_inventory.py index 3fa7fa0..9679b95 100644 --- a/oci_runtime_inventory.py +++ b/oci_runtime_inventory.py @@ -324,7 +324,16 @@ def image_plans(stream, index, budget): raise InventoryError("image_descriptor_limit") try: manifest = blob_json(stream, index, descriptor, budget) - if isinstance(manifest, dict) and "manifests" in manifest: + media = descriptor.get("mediaType") + index_media = {"application/vnd.oci.image.index.v1+json", "application/vnd.docker.distribution.manifest.list.v2+json"} + image_media = {"application/vnd.oci.image.manifest.v1+json", "application/vnd.docker.distribution.manifest.v2+json"} + if not isinstance(media, str) or media not in index_media | image_media: + raise InventoryError("unsupported_manifest_media_type") + if not isinstance(manifest, dict) or ("mediaType" in manifest and manifest["mediaType"] != media): + raise InventoryError("unsupported_manifest_media_type") + if "artifactType" in manifest: + raise InventoryError("unsupported_oci_artifact") + if media in index_media: pending.append((manifest, depth + 1)) continue if not isinstance(manifest, dict) or type(manifest.get("schemaVersion")) is not int or manifest["schemaVersion"] != 2 or not isinstance(manifest.get("layers"), list): @@ -336,6 +345,9 @@ def image_plans(stream, index, budget): config_name = descriptor_path(config, index) if hashlib.sha256(read_member(stream, index, config_name, budget)).hexdigest() != config["digest"][7:]: raise InventoryError("config_digest_mismatch") + config_media = config.get("mediaType") + if not isinstance(config_media, str) or config_media not in {"application/vnd.oci.image.config.v1+json", "application/vnd.docker.container.image.v1+json"}: + raise InventoryError("unsupported_image_config_media_type") layers = [] for layer in manifest["layers"]: name = descriptor_path(layer, index) diff --git a/test_artifact_semantics.py b/test_artifact_semantics.py new file mode 100644 index 0000000..3cc5392 --- /dev/null +++ b/test_artifact_semantics.py @@ -0,0 +1,78 @@ +"""Offline fixtures distinguish verified artifact bytes from image filesystems.""" +import hashlib +import io +import json +import tarfile +import unittest + +import test_inventory as t + + +class ArtifactSemanticsTests(unittest.TestCase): + cli = t.InventoryTests.cli + scan = t.InventoryTests.scan + def test_unsupported_artifacts_never_supply_image_components(self): + base = t.oci_archive([t.tar_bytes([("app/package.json", t.package())])]) + with tarfile.open(fileobj=io.BytesIO(base)) as archive: + original = {m.name: archive.extractfile(m).read() for m in archive if m.isfile()} + for case in ("empty_config_artifact", "artifact_with_image_config", "unknown_descriptor", + "unknown_config", "missing_config_type", "unknown_manifest_type", + "non_string_descriptor", "non_string_config"): + with self.subTest(case=case): + files = dict(original) + index = json.loads(files["index.json"]) + valid = index["manifests"][0] + manifest = json.loads(files["blobs/sha256/" + valid["digest"][7:]]) + if case in ("empty_config_artifact", "artifact_with_image_config"): + manifest["artifactType"] = "application/vnd.example.attestation" + if case == "empty_config_artifact": + raw = b"{}" + digest = hashlib.sha256(raw).hexdigest() + files["blobs/sha256/" + digest] = raw + manifest["config"] = dict(digest="sha256:" + digest, size=len(raw), + mediaType="application/vnd.oci.empty.v1+json") + if case == "unknown_config": + manifest["config"]["mediaType"] = "application/vnd.example.config+json" + if case == "missing_config_type": + manifest["config"].pop("mediaType") + if case == "non_string_config": + manifest["config"]["mediaType"] = [] + if case == "unknown_manifest_type": + manifest["mediaType"] = "application/vnd.example.manifest+json" + raw = json.dumps(manifest).encode() + digest = hashlib.sha256(raw).hexdigest() + files["blobs/sha256/" + digest] = raw + bad = dict(digest="sha256:" + digest, size=len(raw), + mediaType="application/vnd.oci.image.manifest.v1+json") + if case == "unknown_descriptor": + bad["mediaType"] = "application/vnd.example.manifest+json" + if case == "non_string_descriptor": + bad["mediaType"] = [] + # Descriptor identity remains distinct even when only its media type changes. + for siblings in ([bad], [valid, bad], [bad, valid]): + index["manifests"] = siblings + files["index.json"] = json.dumps(index).encode() + payload = t.tar_bytes(list(files.items())) + code, report, _ = self.scan(payload) + self.assertEqual(2, code) + self.assertFalse(report["complete"]) + failed = [image for image in report["images"] if not image["coverage_complete"]] + self.assertEqual(1, len(failed)) + self.assertEqual(bad["digest"], failed[0]["digest"]) + self.assertEqual([], failed[0]["components"]) + self.assertTrue(any("unsupported" in note for note in failed[0]["notes"])) + healthy = [image for image in report["images"] if image["coverage_complete"]] + self.assertEqual(len(siblings) - 1, len(healthy)) + if healthy: + self.assertEqual("sharp", healthy[0]["components"][0]["name"]) + _, consumer, _ = self.scan(payload, "--consumer", "sharp") + # The failed artifact cannot create any additional consumer record. + if healthy: + self.assertEqual([["0.35.5"]], [row["sharp_versions"] for row in consumer["records"]]) + self.assertEqual("not_tested", healthy[0]["components"][0]["exploitability"]) + else: + self.assertEqual([{"asset_id": "metadata-coverage"}], consumer["records"]) + + +if __name__ == "__main__": + unittest.main() From e66135f7194ee381f4adbf2340ba1aef869b4bd7 Mon Sep 17 00:00:00 2001 From: Timothy Wayne Gregg Date: Sun, 25 Oct 2026 21:16:43 -0400 Subject: [PATCH 2/2] Keep checksum manifest line endings canonical --- SHA256SUMS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SHA256SUMS b/SHA256SUMS index 26b77cb..42e5548 100644 --- a/SHA256SUMS +++ b/SHA256SUMS @@ -1 +1 @@ -21d6cbd46b86c101b346d507ed0de30af6f6655fc8b4825ce7b6c2b0ec44c4fe oci_runtime_inventory.py +21d6cbd46b86c101b346d507ed0de30af6f6655fc8b4825ce7b6c2b0ec44c4fe oci_runtime_inventory.py