From b53e2ec27f5957767d16fc083185b5ef9e3a9fd3 Mon Sep 17 00:00:00 2001 From: Dragan Spiridonov Date: Thu, 19 Nov 2026 14:36:13 +0100 Subject: [PATCH 1/3] fix(security): patch Wasmtime36 and verify exact advisory range corrections --- .github/workflows/ci.yml | 3 +- .github/workflows/security-scan.yml | 11 +- docs/security/wasmtime-audit-20261119.md | 80 ++++++++ scripts/ci/audit_rust_advisories.py | 175 ++++++++++++++++++ .../wasmtime-primary-scopes-20261119.json | 60 ++++++ .../wasmtime-rustsec-metadata-20261119.json | 68 +++++++ scripts/ci/test_audit_rust_advisories.py | 125 +++++++++++++ v2/Cargo.lock | 132 ++++++------- v2/Cargo.toml | 4 +- v2/crates/homecore-plugins/Cargo.toml | 2 +- .../tests/wasmtime_advisory_regression.rs | 23 +++ .../RUVIEW-PROVENANCE.md | 13 -- .../Cargo.toml | 2 +- .../LICENSE | 0 .../RUVIEW-PROVENANCE.md | 13 ++ .../build.rs | 0 .../src/config.rs | 0 .../src/config/tests.rs | 0 .../src/lib.rs | 0 .../src/tests.rs | 0 .../src/worker.rs | 0 .../src/worker/tests.rs | 0 .../src/worker/tests/system_time_stub.rs | 0 .../tests/cache_write_default_config.rs | 0 24 files changed, 624 insertions(+), 87 deletions(-) create mode 100644 docs/security/wasmtime-audit-20261119.md create mode 100644 scripts/ci/audit_rust_advisories.py create mode 100644 scripts/ci/fixtures/wasmtime-primary-scopes-20261119.json create mode 100644 scripts/ci/fixtures/wasmtime-rustsec-metadata-20261119.json create mode 100644 scripts/ci/test_audit_rust_advisories.py create mode 100644 v2/crates/homecore-plugins/tests/wasmtime_advisory_regression.rs delete mode 100644 v2/vendor/security/wasmtime-internal-cache-36.0.20/RUVIEW-PROVENANCE.md rename v2/vendor/security/{wasmtime-internal-cache-36.0.20 => wasmtime-internal-cache-36.0.21}/Cargo.toml (99%) rename v2/vendor/security/{wasmtime-internal-cache-36.0.20 => wasmtime-internal-cache-36.0.21}/LICENSE (100%) create mode 100644 v2/vendor/security/wasmtime-internal-cache-36.0.21/RUVIEW-PROVENANCE.md rename v2/vendor/security/{wasmtime-internal-cache-36.0.20 => wasmtime-internal-cache-36.0.21}/build.rs (100%) rename v2/vendor/security/{wasmtime-internal-cache-36.0.20 => wasmtime-internal-cache-36.0.21}/src/config.rs (100%) rename v2/vendor/security/{wasmtime-internal-cache-36.0.20 => wasmtime-internal-cache-36.0.21}/src/config/tests.rs (100%) rename v2/vendor/security/{wasmtime-internal-cache-36.0.20 => wasmtime-internal-cache-36.0.21}/src/lib.rs (100%) rename v2/vendor/security/{wasmtime-internal-cache-36.0.20 => wasmtime-internal-cache-36.0.21}/src/tests.rs (100%) rename v2/vendor/security/{wasmtime-internal-cache-36.0.20 => wasmtime-internal-cache-36.0.21}/src/worker.rs (100%) rename v2/vendor/security/{wasmtime-internal-cache-36.0.20 => wasmtime-internal-cache-36.0.21}/src/worker/tests.rs (100%) rename v2/vendor/security/{wasmtime-internal-cache-36.0.20 => wasmtime-internal-cache-36.0.21}/src/worker/tests/system_time_stub.rs (100%) rename v2/vendor/security/{wasmtime-internal-cache-36.0.20 => wasmtime-internal-cache-36.0.21}/tests/cache_write_default_config.rs (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1d9aa6668..97b05eab93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -405,6 +405,7 @@ jobs: # workflow, so it doesn't gate the rest of the pipeline. docker-build: name: Docker Build & Test + if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest needs: [code-quality, test, rust-tests] continue-on-error: true @@ -525,7 +526,7 @@ jobs: name: Notify runs-on: ubuntu-latest needs: [code-quality, test, rust-tests, ui-tests, performance-test, docker-build, docs] - if: always() + if: always() && github.event_name == 'push' && github.ref == 'refs/heads/main' permissions: contents: write # required by softprops/action-gh-release # GitHub Actions does not allow `secrets.X` directly in step-level `if:` diff --git a/.github/workflows/security-scan.yml b/.github/workflows/security-scan.yml index 4b406ed775..4cdd250c73 100644 --- a/.github/workflows/security-scan.yml +++ b/.github/workflows/security-scan.yml @@ -36,16 +36,21 @@ jobs: # reviewed ignores in v2/.cargo/audit.toml. Run inside the v2 workspace # so that policy file is actually loaded. working-directory: v2 + env: + GH_TOKEN: ${{ github.token }} run: | - set -o pipefail - cargo audit --file Cargo.lock --json | tee cargo-audit.json + python3 ../scripts/ci/test_audit_rust_advisories.py + python3 ../scripts/ci/audit_rust_advisories.py --lockfile Cargo.lock - name: Upload Rust advisory report uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 if: always() with: name: cargo-audit-report - path: v2/cargo-audit.json + path: | + v2/cargo-audit.json + v2/cargo-audit-classification.json + v2/cargo-audit-upstream.json if-no-files-found: error # Static Application Security Testing (SAST) diff --git a/docs/security/wasmtime-audit-20261119.md b/docs/security/wasmtime-audit-20261119.md new file mode 100644 index 0000000000..24b7eed33b --- /dev/null +++ b/docs/security/wasmtime-audit-20261119.md @@ -0,0 +1,80 @@ +# Wasmtime 36.x patch and advisory metadata reconciliation + +## Problem and actual patch + +RustSec database7133866a reported five entries against core wasmtime36.0.20. +Primary upstream advisory HTML and repository advisory API distinguish the actual +package/version scopes from those raw matches: + +| RustSec ID | Upstream scope | Result for this workspace | +|---|---|---| +|0569|[Core below36.0.21](https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-hj27-mpw9-ff4c)|Version-applicable; patch to36.0.21| +|0567|[Core branches starting at39](https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-2674-w29h-wqvj)|36.x outside affected ranges| +|0573|[Core branches starting at47](https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-wvgq-g5hf-6gm6)|36.x outside affected ranges| +|0566|[wasmtime-wasi](https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-5m8g-xhq4-4h93)|Package absent; RustSec matched the wrong package| +|0571|[wasmtime-wasi-http](https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-f8mm-ggr3-89wh)|Package absent; RustSec matched the wrong package| + +The compatible36.0.21 patch updates32 Wasmtime/Cranelift family lock entries, +retains Rust1.89 compatibility and keeps the optional backend default-off. The +internal cache is re-vendored from its actual36.0.21 archive, preserving the +reviewed zstd0.14.3 manifest correction and byte-identical upstream executable +source/tests/licenses. Existing audit.toml ignores are unchanged. + +An independent controlled imported/re-exported host-function regression panics in +36.0.20's get_module_export implementation. The same test passes with36.0.21. +It is retained under the optional Wasmtime feature. This tests the dependency +patch; it is not a claim that the existing application invokes that faulty API or +that a deployed exploit was demonstrated. + +## Why native cargo-audit still reports two matches + +With36.0.21, the native report drops from five to two. Its remaining0567/0573 +entries omit the upstream lower bounds and therefore incorrectly match36.x. +The two wrongly named WASI entries stop matching after the patch; no special +coverage for those entries is implemented. + +The existing security workflow uses audit_rust_advisories.py to retain the exact +native report and reconcile only these two reviewed range errors. This is not a +native audit-clean result: native exit1/two findings remain recorded separately +from zero unresolved findings after verified metadata reconciliation. + +A correction applies only when ALL of the following hold: + +- The RustSec selector fingerprint matches the checked-in ID/package/aliases/URL, + affected-function/platform selectors and patched/unaffected ranges. +- The finding is registry core wasmtime exactly36.0.21, with its checksum matching + both the verified registry archive and current Cargo.lock. Other versions, sources or checksums are not covered. +- Neither wasmtime-wasi nor wasmtime-wasi-http appears in the reviewed lockfile. + A different graph requires reassessment; those packages cannot gain coverage. +- A fresh read of the fixed official GitHub repository advisory endpoint matches + the reviewed primary package/version-range fingerprint. Network failure, + changed identity/ranges or missing evidence cannot fall back to the fixture. +- The report's existing ignore settings match the unchanged local audit policy. + +All unknown findings remain unresolved, including the version-applicable0569 if +it reappears. Malformed or incomplete reports fail closed. Fingerprints deliberately +cover scope selectors, not cosmetic prose. The primary scopes are checked live; +fixtures are used only by offline tests and never as a successful CI fallback. + +## Evidence and operating boundary + +The job retains cargo-audit.json (unmodified native output), +cargo-audit-classification.json (including native exit and unresolved findings), +and cargo-audit-upstream.json (live scopes and retrieval time). The existing +read-only GitHub Actions token is used by gh to read public published advisories; +no extra token, permission, secret or write operation is introduced. + +Offline negative tests exercise unknown advisories, changed RustSec/primary +selectors, affected/future versions, wrong registry/checksum, missing lock records, +WASI additions, policy injection, malformed reports, unreviewed network IDs and +live-provider failure. Existing ignores remain explicit; no blanket ignore, +severity-threshold change, raw report rewrite or advisory database edit is made. + +Native audit reproduction on snapshot7133866a after the patch reports two entries; +live primary verification classifies those two scope mismatches and leaves zero +unresolved entries. Remove this reconciliation when RustSec's ranges are corrected. +A future version or altered scope must be reassessed, not silently covered. + +No plugin is enabled, helper replaced, application installed, physical sensor +qualified or production configuration changed by this source repair. Merge/release +remain the maintainers' separate decisions. diff --git a/scripts/ci/audit_rust_advisories.py b/scripts/ci/audit_rust_advisories.py new file mode 100644 index 0000000000..78fa10b987 --- /dev/null +++ b/scripts/ci/audit_rust_advisories.py @@ -0,0 +1,175 @@ +#!/usr/bin/env python3 +"""Preserve cargo-audit output and reconcile two reviewed upstream range errors. + +This is not an advisory ignore list. Only the exact reviewed RustSec selectors, +registry Wasmtime 36.0.21, matching lockfile checksum and absent WASI packages can +qualify. Corrected/new metadata or other versions remain unresolved. See the +docs/security/wasmtime-audit-20261119.md assessment for authoritative package/range evidence. +""" +import argparse +import datetime +import hashlib +import json +from pathlib import Path +import subprocess +import sys +import tomllib + +REGISTRY = "registry+https://github.com/rust-lang/crates.io-index" +WASMTIME_ARCHIVE_SHA256 = "c58d2cbba3817454af39ec9f0b39279870a9a98ef4c52bbbcdd9c1ffc1f5f17f" +REVIEWED = { + "RUSTSEC-2026-0567": "99da727f7424b8b1f70c570e7347f7c2ad1d23ac7f7d1534654324e12297ee4c", + "RUSTSEC-2026-0573": "1716fc0fdcf2acae357882632f7ee3a3b6551116e6c18ba32f2f79ddf140ad08", +} + +PRIMARY = { + 'RUSTSEC-2026-0567': ('GHSA-2674-w29h-wqvj', + 'fe62715ac8a8ae324420af60d2ba36d55be25ede888c045cdfdbf5b18ffbd9ca'), + 'RUSTSEC-2026-0573': ('GHSA-wvgq-g5hf-6gm6', + '4a1af44d4f625d4efdf6585593ec47fb73e89fc162fe1ba525090ca9d43f5b70'), +} + + +def primary_scope(document): + if not isinstance(document, dict) or not isinstance(document.get("vulnerabilities"), list): + raise ValueError("invalid upstream advisory metadata") + values = [] + for value in document["vulnerabilities"]: + package = value["package"] + values.append({"package": {"name": package["name"], "ecosystem": package["ecosystem"].lower()}, + "vulnerable_version_range": "".join(value["vulnerable_version_range"].split()), + "patched_versions": "".join(value["patched_versions"].split())}) + values.sort(key=lambda value: json.dumps(value, sort_keys=True)) + return {"ghsa_id": document["ghsa_id"], "vulnerabilities": values} + + +def primary_digest(document): + return hashlib.sha256(json.dumps(primary_scope(document), sort_keys=True, separators=(",", ":")).encode()).hexdigest() + + +def fetch_primary(ghsa): + # IDs come only from PRIMARY constants, never from an untrusted report URL. + if ghsa not in {value[0] for value in PRIMARY.values()}: + raise ValueError("unreviewed upstream advisory identifier") + completed = subprocess.run(["gh", "api", "--hostname", "github.com", + "repos/bytecodealliance/wasmtime/security-advisories/" + ghsa], + capture_output=True, text=True, timeout=45) + if completed.returncode != 0 or len(completed.stdout) > 512 * 1024: + raise ValueError(f"live upstream verification failed for {ghsa} (gh exit {completed.returncode}); no offline fallback") + scope = primary_scope(json.loads(completed.stdout)) + if scope["ghsa_id"] != ghsa: + raise ValueError("upstream advisory identity changed") + return scope + + +def selector_digest(finding): + advisory = finding.get("advisory", {}) + selectors = {key: finding.get(key) for key in ("affected", "versions")} + selectors["advisory"] = {key: advisory.get(key) for key in ("id", "package", "aliases", "url")} + return hashlib.sha256(json.dumps(selectors, sort_keys=True, separators=(",", ":")).encode()).hexdigest() + + +def metadata_mismatch(finding, packages, primary): + advisory = finding.get("advisory", {}) + expected = REVIEWED.get(advisory.get("id")) + if expected is None or selector_digest(finding) != expected: + return False + ghsa, expected_primary = PRIMARY[advisory["id"]] + if ghsa not in primary or primary_digest(primary[ghsa]) != expected_primary: + return False + package = finding.get("package", {}) + if (package.get("name"), package.get("version"), package.get("source")) != ("wasmtime", "36.0.21", REGISTRY): + return False + checksum = package.get("checksum") + if checksum != WASMTIME_ARCHIVE_SHA256: + return False + identity = ("name", "version", "source", "checksum") + if not any(all(p.get(key) == package.get(key) for key in identity) for p in packages): + return False + if any(p.get("name") in {"wasmtime-wasi", "wasmtime-wasi-http"} for p in packages): + return False + return True + + +def classify(report, lock, ignored=(), primary=None): + primary = primary or {} + if not isinstance(report, dict) or report.get("error") or not isinstance(lock.get("package"), list): + raise ValueError("invalid cargo-audit report or lockfile") + vulnerability = report.get("vulnerabilities", {}) + findings = vulnerability.get("list") + count = vulnerability.get("count") + if (not isinstance(findings, list) or type(count) is not int or count < 0 + or count != len(findings) or type(vulnerability.get("found")) is not bool + or vulnerability["found"] != bool(findings)): + raise ValueError("cargo-audit omitted or malformed vulnerability findings") + configured = report.get("settings", {}).get("ignore", []) + if not isinstance(configured, list) or set(configured) != set(ignored): + raise ValueError("cargo-audit policy does not match the existing local policy") + result = {"raw_vulnerability_count": count, "metadata_corrections": [], "existing_policy_ignored": [], "unresolved": []} + for finding in findings: + if not isinstance(finding, dict) or not isinstance(finding.get("advisory"), dict): + raise ValueError("invalid advisory finding") + advisory_id = finding["advisory"].get("id") + if advisory_id in ignored: + result["existing_policy_ignored"].append(advisory_id) + elif metadata_mismatch(finding, lock["package"], primary): + result["metadata_corrections"].append({"id": advisory_id, "package": "wasmtime", "version": "36.0.21", "selector_sha256": REVIEWED[advisory_id], "upstream_advisory": PRIMARY[advisory_id][0], "upstream_scope_sha256": PRIMARY[advisory_id][1]}) + else: + result["unresolved"].append(finding) + return result + + +def decision(native_exit, result, policy): + if native_exit not in (0, 1): + raise ValueError("cargo-audit execution failed") + if native_exit == 1 and result["raw_vulnerability_count"] == 0: + raise ValueError("unexplained native failure without vulnerability findings") + # Never turn an explicitly denied native warning into success. + denied_output = bool(policy.get("output", {}).get("deny", [])) + return 1 if result["unresolved"] or (native_exit == 1 and denied_output) else 0 + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--lockfile", type=Path, default=Path("Cargo.lock")) + parser.add_argument("--raw-output", type=Path, default=Path("cargo-audit.json")) + parser.add_argument("--classified-output", type=Path, default=Path("cargo-audit-classification.json")) + parser.add_argument("--upstream-output", type=Path, default=Path("cargo-audit-upstream.json")) + parser.add_argument("--database", type=Path, help="explicit local advisory snapshot for reproducible local verification") + args = parser.parse_args() + lockfile = args.lockfile.resolve() + lock = tomllib.loads(lockfile.read_text()) + policy_file = lockfile.parent / ".cargo/audit.toml" + policy = tomllib.loads(policy_file.read_text()) if policy_file.exists() else {} + ignored = policy.get("advisories", {}).get("ignore", []) + command = ["cargo", "audit", "--file", str(lockfile), "--json"] + if args.database is not None: + command += ["--db", str(args.database.resolve()), "--no-fetch"] + completed = subprocess.run(command, cwd=lockfile.parent, capture_output=True, text=True, timeout=300) + args.raw_output.write_text(completed.stdout) + sys.stdout.write(completed.stdout) + sys.stderr.write(completed.stderr) + if completed.returncode not in (0, 1) or len(completed.stdout) > 16 * 1024 * 1024: + raise ValueError("cargo-audit execution failed or returned an oversized report") + report = json.loads(completed.stdout) + primary = {} + for finding in report.get("vulnerabilities", {}).get("list", []): + advisory_id = finding.get("advisory", {}).get("id") + if advisory_id in PRIMARY and advisory_id not in ignored: + ghsa = PRIMARY[advisory_id][0] + primary[ghsa] = fetch_primary(ghsa) + args.upstream_output.write_text(json.dumps({"retrieved_at": datetime.datetime.now(datetime.timezone.utc).isoformat(), "scopes": primary}, indent=2) + "\n") + result = classify(report, lock, ignored, primary) + exit_code = decision(completed.returncode, result, policy) + result["native_exit_code"] = completed.returncode + args.classified_output.write_text(json.dumps(result, indent=2) + "\n") + print(json.dumps({key: value for key, value in result.items() if key != "unresolved"} | {"unresolved_count": len(result["unresolved"])})) + return exit_code + + +if __name__ == "__main__": + try: + sys.exit(main()) + except (ValueError, OSError, subprocess.SubprocessError) as error: + print(f"RUST AUDIT FAILED: {error}", file=sys.stderr) + sys.exit(2) diff --git a/scripts/ci/fixtures/wasmtime-primary-scopes-20261119.json b/scripts/ci/fixtures/wasmtime-primary-scopes-20261119.json new file mode 100644 index 0000000000..1aae735d11 --- /dev/null +++ b/scripts/ci/fixtures/wasmtime-primary-scopes-20261119.json @@ -0,0 +1,60 @@ +{ + "GHSA-2674-w29h-wqvj": { + "ghsa_id": "GHSA-2674-w29h-wqvj", + "vulnerabilities": [ + { + "package": { + "name": "wasmtime", + "ecosystem": "rust" + }, + "vulnerable_version_range": ">=39.0.0,<48.0.9", + "patched_versions": "48.0.9" + }, + { + "package": { + "name": "wasmtime", + "ecosystem": "rust" + }, + "vulnerable_version_range": ">=49.0.0,<49.0.6", + "patched_versions": "49.0.6" + }, + { + "package": { + "name": "wasmtime", + "ecosystem": "rust" + }, + "vulnerable_version_range": ">=50.0.0,<50.0.2", + "patched_versions": "50.0.2" + } + ] + }, + "GHSA-wvgq-g5hf-6gm6": { + "ghsa_id": "GHSA-wvgq-g5hf-6gm6", + "vulnerabilities": [ + { + "package": { + "name": "wasmtime", + "ecosystem": "rust" + }, + "vulnerable_version_range": ">=47.0.0,<=48.0.8", + "patched_versions": "48.0.9" + }, + { + "package": { + "name": "wasmtime", + "ecosystem": "rust" + }, + "vulnerable_version_range": ">=49.0.0,<=49.0.5", + "patched_versions": "49.0.6" + }, + { + "package": { + "name": "wasmtime", + "ecosystem": "rust" + }, + "vulnerable_version_range": ">=50.0.0,<=50.0.1", + "patched_versions": "50.0.2" + } + ] + } +} diff --git a/scripts/ci/fixtures/wasmtime-rustsec-metadata-20261119.json b/scripts/ci/fixtures/wasmtime-rustsec-metadata-20261119.json new file mode 100644 index 0000000000..b328e152e3 --- /dev/null +++ b/scripts/ci/fixtures/wasmtime-rustsec-metadata-20261119.json @@ -0,0 +1,68 @@ +[ + { + "advisory": { + "id": "RUSTSEC-2026-0567", + "package": "wasmtime", + "title": "Abort in Wasmtime builds without the `threads` cargo feature", + "description": "This is an entry in the RustSec database for the Wasmtime security advisory\nlocated at\nhttps://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-2674-w29h-wqvj\nFor more information see the GitHub-hosted security advisory.", + "date": "2026-11-16", + "aliases": [ + "GHSA-2674-w29h-wqvj" + ], + "related": [], + "collection": "crates", + "categories": [], + "keywords": [], + "cvss": null, + "informational": null, + "references": [], + "source": null, + "url": "https://github.com/bytecodealliance/wasmtime/pull/15314", + "withdrawn": null, + "license": "CC0-1.0", + "expect-deleted": false + }, + "versions": { + "patched": [ + ">=48.0.9, <49.0.0", + ">=49.0.6, <50.0.0", + ">=50.0.2" + ], + "unaffected": [] + }, + "affected": null + }, + { + "advisory": { + "id": "RUSTSEC-2026-0573", + "package": "wasmtime", + "title": "Process abort when a GC heap's reservation isn't a multiple of the page size", + "description": "This is an entry in the RustSec database for the Wasmtime security advisory\nlocated at\nhttps://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-wvgq-g5hf-6gm6\nFor more information see the GitHub-hosted security advisory.", + "date": "2026-11-16", + "aliases": [ + "GHSA-wvgq-g5hf-6gm6" + ], + "related": [], + "collection": "crates", + "categories": [], + "keywords": [], + "cvss": null, + "informational": null, + "references": [], + "source": null, + "url": "https://github.com/bytecodealliance/wasmtime/pull/15320", + "withdrawn": null, + "license": "CC0-1.0", + "expect-deleted": false + }, + "versions": { + "patched": [ + ">=48.0.9, <49.0.0", + ">=49.0.6, <50.0.0", + ">=50.0.2" + ], + "unaffected": [] + }, + "affected": null + } +] diff --git a/scripts/ci/test_audit_rust_advisories.py b/scripts/ci/test_audit_rust_advisories.py new file mode 100644 index 0000000000..ba6304110b --- /dev/null +++ b/scripts/ci/test_audit_rust_advisories.py @@ -0,0 +1,125 @@ +import copy +import json +from pathlib import Path +import unittest +from unittest import mock +from audit_rust_advisories import classify as classify_report, REGISTRY, fetch_primary, decision, WASMTIME_ARCHIVE_SHA256 + +def classify(report, lock, ignored=(), primary=None): + if primary is None: + primary = json.loads((Path(__file__).parent / "fixtures/wasmtime-primary-scopes-20261119.json").read_text()) + return classify_report(report, lock, ignored, primary) + + +class AuditMetadataTests(unittest.TestCase): + def setUp(self): + self.findings = json.loads((Path(__file__).parent / "fixtures/wasmtime-rustsec-metadata-20261119.json").read_text()) + self.package = {"name": "wasmtime", "version": "36.0.21", "source": REGISTRY, "checksum": WASMTIME_ARCHIVE_SHA256} + for finding in self.findings: + finding["package"] = self.package.copy() + self.lock = {"package": [self.package.copy()]} + + def report(self, findings=None): + findings = self.findings if findings is None else findings + return {"vulnerabilities": {"found": bool(findings), "count": len(findings), "list": findings}, "settings": {"ignore": []}} + + def test_exact_reviewed_false_matches_are_reported_separately(self): + result = classify(self.report(), self.lock) + self.assertEqual(len(result["metadata_corrections"]), 2) + self.assertEqual(result["raw_vulnerability_count"], 2) + self.assertEqual(result["unresolved"], []) + + def test_old_or_future_affected_versions_cannot_use_the_correction(self): + for version in ("36.0.20", "36.0.22", "39.0.0", "47.0.0", "50.0.1"): + with self.subTest(version=version): + findings = copy.deepcopy(self.findings) + for finding in findings: + finding["package"]["version"] = version + lock = {"package": [{**self.package, "version": version}]} + self.assertEqual(len(classify(self.report(findings), lock)["unresolved"]), 2) + + def test_wasi_presence_prevents_wrong_package_coverage(self): + for name in ("wasmtime-wasi", "wasmtime-wasi-http"): + with self.subTest(package=name): + lock = {"package": [self.package.copy(), {"name": name, "version": "36.0.20"}]} + self.assertEqual(len(classify(self.report(), lock)["unresolved"]), 2) + + def test_actual_wasi_findings_remain_unresolved(self): + findings = copy.deepcopy(self.findings) + findings[0]["package"]["name"] = "wasmtime-wasi" + self.assertEqual(len(classify(self.report(findings), self.lock)["unresolved"]), 1) + + def test_changed_advisory_selectors_fail_closed(self): + for change in ("versions", "affected", "aliases", "url"): + findings = copy.deepcopy(self.findings) + if change == "versions": findings[0]["versions"]["patched"] = [">=99.0.0"] + elif change == "affected": findings[0]["affected"] = {"os": ["macos"]} + elif change == "aliases": findings[0]["advisory"]["aliases"] = ["GHSA-new-advisory"] + else: findings[0]["advisory"]["url"] = "https://example.invalid/unreviewed" + self.assertEqual(len(classify(self.report(findings), self.lock)["unresolved"]), 1) + + def test_unknown_or_version_applicable_advisory_is_not_covered(self): + for advisory in ("RUSTSEC-2099-0001", "RUSTSEC-2026-0569"): + findings = copy.deepcopy(self.findings) + findings[0]["advisory"]["id"] = advisory + self.assertEqual(len(classify(self.report(findings), self.lock)["unresolved"]), 1) + + def test_registry_identity_and_checksum_must_match_the_lockfile(self): + for change in ("checksum", "source"): + findings = copy.deepcopy(self.findings) + findings[0]["package"][change] = "unreviewed" + self.assertEqual(len(classify(self.report(findings), self.lock)["unresolved"]), 1) + self.assertEqual(len(classify(self.report(), {"package": []})["unresolved"]), 2) + + def test_coordinated_report_and_lock_checksum_tamper_is_rejected(self): + findings = copy.deepcopy(self.findings) + for finding in findings: finding["package"]["checksum"] = "b" * 64 + lock = {"package": [{**self.package, "checksum": "b" * 64}]} + self.assertEqual(len(classify(self.report(findings), lock)["unresolved"]), 2) + + def test_malformed_or_omitted_findings_fail_closed(self): + for report in ({}, {"vulnerabilities": {"found": False, "count": 0, "list": self.findings}}): + with self.assertRaises(ValueError): classify(report, self.lock) + + def test_existing_policy_is_honored_but_cannot_be_broadened_by_report(self): + findings = copy.deepcopy(self.findings) + findings[0]["advisory"]["id"] = "RUSTSEC-2099-0001" + report = self.report(findings) + report["settings"]["ignore"] = ["RUSTSEC-2099-0001"] + with self.assertRaises(ValueError): classify(report, self.lock) + result = classify(report, self.lock, ["RUSTSEC-2099-0001"]) + self.assertEqual(result["unresolved"], []) + self.assertEqual(result["existing_policy_ignored"], ["RUSTSEC-2099-0001"]) + + def test_missing_primary_evidence_does_not_cover_any_finding(self): + self.assertEqual(len(classify(self.report(), self.lock, primary={})["unresolved"]), 2) + + def test_changed_primary_package_or_range_revokes_coverage(self): + for field in ("package", "vulnerable_version_range"): + primary = json.loads((Path(__file__).parent / "fixtures/wasmtime-primary-scopes-20261119.json").read_text()) + target = primary["GHSA-2674-w29h-wqvj"]["vulnerabilities"][0] + if field == "package": target["package"]["name"] = "other-package" + else: target[field] = ">=36.0.0,<48.0.9" + self.assertEqual(len(classify(self.report(), self.lock, primary=primary)["unresolved"]), 1) + + def test_unknown_advisory_cannot_choose_a_network_location(self): + with mock.patch("audit_rust_advisories.subprocess.run") as execute: + with self.assertRaises(ValueError): fetch_primary("https://untrusted.invalid/advisory") + execute.assert_not_called() + + def test_live_primary_failure_has_no_offline_success_fallback(self): + with mock.patch("audit_rust_advisories.subprocess.run", return_value=mock.Mock(returncode=1, stdout="")): + with self.assertRaises(ValueError): fetch_primary("GHSA-2674-w29h-wqvj") + + def test_native_warning_denial_cannot_be_overridden(self): + result = classify(self.report(), self.lock) + self.assertEqual(decision(1, result, {"output": {"deny": ["warnings"]}}), 1) + self.assertEqual(decision(1, result, {}), 0) + with self.assertRaises(ValueError): decision(1, classify(self.report([]), self.lock), {}) + + def test_native_clean_report_remains_clean(self): + self.assertEqual(classify(self.report([]), self.lock)["unresolved"], []) + + +if __name__ == "__main__": + unittest.main() diff --git a/v2/Cargo.lock b/v2/Cargo.lock index 3ed1589569..9c481c692f 100644 --- a/v2/Cargo.lock +++ b/v2/Cargo.lock @@ -1825,36 +1825,36 @@ dependencies = [ [[package]] name = "cranelift-assembler-x64" -version = "0.123.20" +version = "0.123.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40d4018626c25bb153a72738b261bdfed97ad6b7f21b100d556c0b8457fa9b3b" +checksum = "142696a120a5dc298df74bcfb8c5ec43f0f8c53ff2f3607b3cffe67c1bc3fe0b" dependencies = [ "cranelift-assembler-x64-meta", ] [[package]] name = "cranelift-assembler-x64-meta" -version = "0.123.20" +version = "0.123.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c69b47b7ffbd42f8d162ee958886e685b374b102b3bd116b0470c911153428b4" +checksum = "24a12a121860c44ba6dc9d0bd2b4b9284f409c2f305aa04093184a7878148726" dependencies = [ "cranelift-srcgen", ] [[package]] name = "cranelift-bforest" -version = "0.123.20" +version = "0.123.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d1994514a2e498d42a7173804fb0618472c94176b72c54ef8d64acdada05d0f" +checksum = "26e0347ec8886cfe409616aeeeb3d1ee4ae0ec6ae0e053fc111e0214f67c830c" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-bitset" -version = "0.123.20" +version = "0.123.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "019bfe57e970cf56fd9ad9ea45e4290457eb1ceb9bea954646abbe9d657a4a61" +checksum = "b8a8d504f1c49cf5b3c59166fa77c990d6618987baa16095a8adbc125218a710" dependencies = [ "serde", "serde_derive", @@ -1862,9 +1862,9 @@ dependencies = [ [[package]] name = "cranelift-codegen" -version = "0.123.20" +version = "0.123.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "397c0a3cc8a67f9f85dbe47fbba2c1e88430293b130f91f3c98411f6ae4e0e80" +checksum = "0826e7db0453c2e4def6cc16e661309b88acfe5c688727d2bd14f210c5979228" dependencies = [ "bumpalo", "cranelift-assembler-x64", @@ -1889,9 +1889,9 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.123.20" +version = "0.123.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5bc504c51980615d594a685367584d1fa95d36c32c14a15b0eb4b1d9cc0dc2e" +checksum = "5466899a46c1b457a2c40e62c0db595ead52ce070283349f24f1ea3e3ab95e59" dependencies = [ "cranelift-assembler-x64-meta", "cranelift-codegen-shared", @@ -1902,24 +1902,24 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.123.20" +version = "0.123.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc8ae2c52ca44f49719cd78e48480c076e115a490b4e51ae28a89535ec4d76df" +checksum = "4cb2af0ddf040bc688bb1c7c3f98026caf1f7be9735a90abe5210fb3ed61b31e" [[package]] name = "cranelift-control" -version = "0.123.20" +version = "0.123.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d94159e930a391bb589c8c4832769c3e2f9c81d8f1cd1266083a33a1787d41a9" +checksum = "23928359f722201147e559d1ad68b26e04f542df2da609615883373ca95488f9" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.123.20" +version = "0.123.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc0257dc68c7d282dabc1b3c9effec3f5d00fff56a964a80e7c08af7a3aa4dc" +checksum = "544a5be17891f159c85d2a1200cbd1846d5ffdc9fbb26fa9140f4c0040cde8fe" dependencies = [ "cranelift-bitset", "serde", @@ -1928,9 +1928,9 @@ dependencies = [ [[package]] name = "cranelift-frontend" -version = "0.123.20" +version = "0.123.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a60aa092dbffc0b8e501845afc3f67a3c987d780d22dd302829aa9f0255738e" +checksum = "41a1775f555a016d16b212b38b7f4b4759f258ae90c7139ffc198bb3cb63829c" dependencies = [ "cranelift-codegen", "log", @@ -1940,15 +1940,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.123.20" +version = "0.123.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e62bea43dd7767887c6b7861021846b0f0a03d9cc72bafddd0827e79b5f5deb5" +checksum = "3cc4649f050a50eaf0ee29b47d797e76a7dbd6f4a1fa1247e21667fd50ccc197" [[package]] name = "cranelift-native" -version = "0.123.20" +version = "0.123.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f410a5e75d4758d0564106931a1809d50d17681385ea1686518d029593a06b2a" +checksum = "90b5fbff9fd5b0fef29865a393f77d1706f9ed50ff90ca40f2768ea2f53ccc7c" dependencies = [ "cranelift-codegen", "libc", @@ -1957,9 +1957,9 @@ dependencies = [ [[package]] name = "cranelift-srcgen" -version = "0.123.20" +version = "0.123.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f98d0e96c17d2654a95820c77403050754561f2b2cd737dbf59462c64896f3" +checksum = "d2877cb00084918ff719184b88e247a2b46ebd0dca27fac3569a168590053ae1" [[package]] name = "crc" @@ -8102,9 +8102,9 @@ dependencies = [ [[package]] name = "pulley-interpreter" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f6a7699ba3c24456c4235f6578a5f182386a1a9230653e8783f165ea1085bbe" +checksum = "0781f03b600890175c17522913366e8543c96acd76d074b39a27835879f89702" dependencies = [ "cranelift-bitset", "log", @@ -8114,9 +8114,9 @@ dependencies = [ [[package]] name = "pulley-macros" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1efdd17eb6ed2d844c29350fffb7230c550ddb0cbe93e1fd2b9cfcc345d77450" +checksum = "dc7ad6f328adda4f2d169d9338402fad5f726630e9c9fdc26660771b13d1a788" dependencies = [ "proc-macro2", "quote", @@ -8213,7 +8213,7 @@ dependencies = [ "quinn-udp", "rustc-hash 2.1.1", "rustls", - "socket2 0.5.10", + "socket2 0.6.5", "thiserror 2.0.18", "tokio", "tracing", @@ -8253,9 +8253,9 @@ dependencies = [ "cfg_aliases", "libc", "once_cell", - "socket2 0.5.10", + "socket2 0.6.5", "tracing", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -12643,9 +12643,9 @@ dependencies = [ [[package]] name = "wasmtime" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a32143e651d97f1b8d749713d242f70a72c9a0d7e16fd498a7e5a3f5574ed10b" +checksum = "c58d2cbba3817454af39ec9f0b39279870a9a98ef4c52bbbcdd9c1ffc1f5f17f" dependencies = [ "addr2line", "anyhow", @@ -12698,9 +12698,9 @@ dependencies = [ [[package]] name = "wasmtime-environ" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0501ad47df09ae57fbb76e3bdc6513b1f6d9dd0eadf3a115bb39360798890c7" +checksum = "2e64cbeb0aa73682360f848c931ec7e024a59bb15e855fc461c21c6ec665775e" dependencies = [ "anyhow", "cpp_demangle", @@ -12725,16 +12725,16 @@ dependencies = [ [[package]] name = "wasmtime-internal-asm-macros" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de4c70c3fb098b9b28b73f7fc2b0147c5624621fb017a5354cdedb660f273e07" +checksum = "ead251813500a15bb1fc31db43f8d2e612fcc0c723f3efff69c5d7bedd9edaf9" dependencies = [ "cfg-if", ] [[package]] name = "wasmtime-internal-cache" -version = "36.0.20" +version = "36.0.21" dependencies = [ "anyhow", "base64 0.22.1", @@ -12755,9 +12755,9 @@ dependencies = [ [[package]] name = "wasmtime-internal-component-macro" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28729d33f5731506bcfe774a4b9eaf9e7e713449e1e3d848748f7de9978bea53" +checksum = "c6aba235e8bfa25cf76312a8b8295964968164cbd4e3fb6e2d9be167128ae3d7" dependencies = [ "anyhow", "proc-macro2", @@ -12770,15 +12770,15 @@ dependencies = [ [[package]] name = "wasmtime-internal-component-util" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91abf6b751d0f135cab1e78448f402af00a0f3e0638be858d18cc93170ab1009" +checksum = "0e1b1657d77558b86ace8e85e0f016655f7b68b8a8c5b8ad875515f4880aece3" [[package]] name = "wasmtime-internal-cranelift" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3840e7bb2d2593f3178b13a6717f215ad63e233ef54b61892f3cee80582f098" +checksum = "0dc2e39983f07c0e85ba5f83df2dfb8a4e8607a5cab01c761a3a5deb15abc5bd" dependencies = [ "anyhow", "cfg-if", @@ -12803,9 +12803,9 @@ dependencies = [ [[package]] name = "wasmtime-internal-fiber" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "458d24ab006050e9b5fcf79f2d83ccc236f69846685fb27a7bf4c50a1583f1ea" +checksum = "3d8f744e4eea04b2b1070b941d32138c1c34e50887b27d9f11c47f9ce8187cd6" dependencies = [ "anyhow", "cc", @@ -12819,9 +12819,9 @@ dependencies = [ [[package]] name = "wasmtime-internal-jit-debug" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eca1ce583227e82e6370939f48395ae902acdcd4c91ca32ea1ae7abbc86232a7" +checksum = "7e12bcf0d25fa4e1c4346d0ecea325d0ef850505ca1fabec5711b7a86679ae3e" dependencies = [ "cc", "object", @@ -12831,9 +12831,9 @@ dependencies = [ [[package]] name = "wasmtime-internal-jit-icache-coherence" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c110f07b222a8eb29d957eabf90dce38f41461f883099ab28dc50861913ba17" +checksum = "147bdb5ff208cf503adb480a9bd9a3c9012b3289007e69d46117ca31cef51ed6" dependencies = [ "anyhow", "cfg-if", @@ -12843,24 +12843,24 @@ dependencies = [ [[package]] name = "wasmtime-internal-math" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a273dd4ec37457d435538c00b30f3ec9ae99e04a4f6ba89a737048e8de6095df" +checksum = "4e77a4cd77f1aa48a23ef9cc544cdc8732de512f2ad50f628a39092fb53cb34c" dependencies = [ "libm", ] [[package]] name = "wasmtime-internal-slab" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d12c7b3ae65639ab90d8d29135348dfd16de6d96eb36ab5b63861f3e12cf8e0" +checksum = "2652fc800965c03acb4e5a2a2bb0ce52650a1f1b3d23e91cd3f65ebafbd68ff0" [[package]] name = "wasmtime-internal-unwinder" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6da6131cb87700e06ffb7a83cc933658f521176f04d6d73511f1ee60db58c515" +checksum = "cb5796bfab805bdb0f13e8a8502c0ebd643f11bc209c9199da71c97c17234da3" dependencies = [ "anyhow", "cfg-if", @@ -12871,9 +12871,9 @@ dependencies = [ [[package]] name = "wasmtime-internal-versioned-export-macros" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71efc44d34bb86408d7f620d308dad19457f34543e5c44ace680bdbe2d819917" +checksum = "f534370e1ccf59b3d903c6f4db72036c43b5d2b94a77ccd39c43239e90b07e61" dependencies = [ "proc-macro2", "quote", @@ -12882,9 +12882,9 @@ dependencies = [ [[package]] name = "wasmtime-internal-winch" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af4da8c46ddb215374f023c0e3ec8917185b878b3d9874fbfaaefdc2d2df38e0" +checksum = "f286941452a9d79b9e681f7272354280129ef38c55497b757bfc9d5810277afd" dependencies = [ "anyhow", "cranelift-codegen", @@ -12899,9 +12899,9 @@ dependencies = [ [[package]] name = "wasmtime-internal-wit-bindgen" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "356a1ae3cfc0534a84df35d9df214a241ca454983c0d311f8169b1674b4979a3" +checksum = "f0f67e6dc46acb465d17902b302f19bf29018d05b7cc00c8d6eeb2e8aa703399" dependencies = [ "anyhow", "bitflags 2.11.0", @@ -13825,9 +13825,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "winch-codegen" -version = "36.0.20" +version = "36.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09aff830750e48ca9828e9df5ba4589688f49f2748e4a1d43fd543d6a673d272" +checksum = "48ff4619adfdac753592c13508b49067f857cb41a1e5c2579e12580ad7470ce6" dependencies = [ "anyhow", "cranelift-assembler-x64", diff --git a/v2/Cargo.toml b/v2/Cargo.toml index d546e97b36..e0ec3b0d89 100644 --- a/v2/Cargo.toml +++ b/v2/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = [ # Checksum-verified dependency patches; keep their upstream tests in CI. "vendor/security/zip-0.6.6", - "vendor/security/wasmtime-internal-cache-36.0.20", + "vendor/security/wasmtime-internal-cache-36.0.21", "vendor/security/sqlx-sqlite-0.8.6", "crates/wifi-densepose-core", "crates/wifi-densepose-physics", # ADR-323 bounded pose assessment/correction @@ -357,5 +357,5 @@ zip-legacy = { package = "zip", path = "vendor/security/zip-0.6.6" } # Candle 0.9 expects ZIP 7's filename access. The private adapter validates # filename decoding and delegates ZIP operations to patched upstream ZIP 9. zip-candle = { package = "zip", path = "vendor/security/zip-candle-compat" } -wasmtime-internal-cache = { path = "vendor/security/wasmtime-internal-cache-36.0.20" } +wasmtime-internal-cache = { path = "vendor/security/wasmtime-internal-cache-36.0.21" } sqlx-sqlite = { path = "vendor/security/sqlx-sqlite-0.8.6" } diff --git a/v2/crates/homecore-plugins/Cargo.toml b/v2/crates/homecore-plugins/Cargo.toml index 5adb536849..f9815fde03 100644 --- a/v2/crates/homecore-plugins/Cargo.toml +++ b/v2/crates/homecore-plugins/Cargo.toml @@ -64,7 +64,7 @@ base64 = "0.22" # Upgraded from 25.0.3 to remediate the Cranelift/Winch sandbox advisories; # 40.0.4 was subsequently replaced because of RUSTSEC-2026-0114. # Patched 36.x retains HOMECORE's Rust 1.89 MSRV. -wasmtime = { version = "36.0.20", optional = true } +wasmtime = { version = "36.0.21", optional = true } [dev-dependencies] diff --git a/v2/crates/homecore-plugins/tests/wasmtime_advisory_regression.rs b/v2/crates/homecore-plugins/tests/wasmtime_advisory_regression.rs new file mode 100644 index 0000000000..b218bebf4b --- /dev/null +++ b/v2/crates/homecore-plugins/tests/wasmtime_advisory_regression.rs @@ -0,0 +1,23 @@ +//! RUSTSEC-2026-0569: a re-exported host function has no calling Wasm module. +#![cfg(feature = "wasmtime")] + +#[test] +fn reexported_host_function_has_no_calling_module() { + use wasmtime::{Caller, Engine, Linker, Module, Store}; + let engine = Engine::default(); + let module = Module::new(&engine, "(module (import \"host\" \"inspect\" (func)) (memory (export \"memory\") 1) (export \"run\" (func 0)))").unwrap(); + let memory = module.get_export_index("memory").unwrap(); + let mut linker = Linker::new(&engine); + linker + .func_wrap("host", "inspect", move |mut caller: Caller<'_, ()>| { + assert!(caller.get_module_export(&memory).is_none()); + }) + .unwrap(); + let mut store = Store::new(&engine, ()); + let instance = linker.instantiate(&mut store, &module).unwrap(); + instance + .get_typed_func::<(), ()>(&mut store, "run") + .unwrap() + .call(&mut store, ()) + .unwrap(); +} diff --git a/v2/vendor/security/wasmtime-internal-cache-36.0.20/RUVIEW-PROVENANCE.md b/v2/vendor/security/wasmtime-internal-cache-36.0.20/RUVIEW-PROVENANCE.md deleted file mode 100644 index cb51c691fb..0000000000 --- a/v2/vendor/security/wasmtime-internal-cache-36.0.20/RUVIEW-PROVENANCE.md +++ /dev/null @@ -1,13 +0,0 @@ -# Dependency compatibility patch - -Source: crates.io `wasmtime-internal-cache` 36.0.20. -Published archive SHA-256: `65f09c789d1bb2e7ab1618ac8336d783c1ff0babc38430c7f1940d01c546722b` (verified against crates.io version metadata). - -Executable source, tests, fixtures and licenses are byte-for-byte upstream. -Only the normalized Cargo.toml dependency requirement changes: -`zstd` from `0.13.0` to `0.14.3`, retaining the upstream feature selection. -Registry bookkeeping, the nested lockfile, the unconsumed original manifest -and upstream CI files are omitted. No advisory suppression is added. - -This preserves the parent API while selecting the patched registry dependency. -Remove this override when a compatible parent release includes the fixed dependency. diff --git a/v2/vendor/security/wasmtime-internal-cache-36.0.20/Cargo.toml b/v2/vendor/security/wasmtime-internal-cache-36.0.21/Cargo.toml similarity index 99% rename from v2/vendor/security/wasmtime-internal-cache-36.0.20/Cargo.toml rename to v2/vendor/security/wasmtime-internal-cache-36.0.21/Cargo.toml index 9b86a5661b..b41f628f52 100644 --- a/v2/vendor/security/wasmtime-internal-cache-36.0.20/Cargo.toml +++ b/v2/vendor/security/wasmtime-internal-cache-36.0.21/Cargo.toml @@ -13,7 +13,7 @@ edition = "2024" rust-version = "1.86.0" name = "wasmtime-internal-cache" -version = "36.0.20" +version = "36.0.21" authors = ["The Wasmtime Project Developers"] build = "build.rs" autolib = false diff --git a/v2/vendor/security/wasmtime-internal-cache-36.0.20/LICENSE b/v2/vendor/security/wasmtime-internal-cache-36.0.21/LICENSE similarity index 100% rename from v2/vendor/security/wasmtime-internal-cache-36.0.20/LICENSE rename to v2/vendor/security/wasmtime-internal-cache-36.0.21/LICENSE diff --git a/v2/vendor/security/wasmtime-internal-cache-36.0.21/RUVIEW-PROVENANCE.md b/v2/vendor/security/wasmtime-internal-cache-36.0.21/RUVIEW-PROVENANCE.md new file mode 100644 index 0000000000..e9d78a01ff --- /dev/null +++ b/v2/vendor/security/wasmtime-internal-cache-36.0.21/RUVIEW-PROVENANCE.md @@ -0,0 +1,13 @@ +# Dependency compatibility patch + +Source: crates.io `wasmtime-internal-cache` 36.0.21. +Published archive SHA-256: `1ff2377df26271c42d9649ac4ee13656ef89a51f02f0daa7917e67c635d9bc1d`. + +Executable source, tests, fixtures and licenses are byte-for-byte upstream. +Only the normalized Cargo.toml zstd requirement changes from0.13.0 to0.14.3, +retaining upstream features and the previously reviewed compatibility repair. +Registry bookkeeping, nested lockfile, unconsumed original manifest and upstream +CI files are omitted. No source backport or advisory ignore is added here. + +This version matches the compatible Wasmtime36.0.21 core security update. +Remove the override when a compatible parent selects the fixed zstd dependency. diff --git a/v2/vendor/security/wasmtime-internal-cache-36.0.20/build.rs b/v2/vendor/security/wasmtime-internal-cache-36.0.21/build.rs similarity index 100% rename from v2/vendor/security/wasmtime-internal-cache-36.0.20/build.rs rename to v2/vendor/security/wasmtime-internal-cache-36.0.21/build.rs diff --git a/v2/vendor/security/wasmtime-internal-cache-36.0.20/src/config.rs b/v2/vendor/security/wasmtime-internal-cache-36.0.21/src/config.rs similarity index 100% rename from v2/vendor/security/wasmtime-internal-cache-36.0.20/src/config.rs rename to v2/vendor/security/wasmtime-internal-cache-36.0.21/src/config.rs diff --git a/v2/vendor/security/wasmtime-internal-cache-36.0.20/src/config/tests.rs b/v2/vendor/security/wasmtime-internal-cache-36.0.21/src/config/tests.rs similarity index 100% rename from v2/vendor/security/wasmtime-internal-cache-36.0.20/src/config/tests.rs rename to v2/vendor/security/wasmtime-internal-cache-36.0.21/src/config/tests.rs diff --git a/v2/vendor/security/wasmtime-internal-cache-36.0.20/src/lib.rs b/v2/vendor/security/wasmtime-internal-cache-36.0.21/src/lib.rs similarity index 100% rename from v2/vendor/security/wasmtime-internal-cache-36.0.20/src/lib.rs rename to v2/vendor/security/wasmtime-internal-cache-36.0.21/src/lib.rs diff --git a/v2/vendor/security/wasmtime-internal-cache-36.0.20/src/tests.rs b/v2/vendor/security/wasmtime-internal-cache-36.0.21/src/tests.rs similarity index 100% rename from v2/vendor/security/wasmtime-internal-cache-36.0.20/src/tests.rs rename to v2/vendor/security/wasmtime-internal-cache-36.0.21/src/tests.rs diff --git a/v2/vendor/security/wasmtime-internal-cache-36.0.20/src/worker.rs b/v2/vendor/security/wasmtime-internal-cache-36.0.21/src/worker.rs similarity index 100% rename from v2/vendor/security/wasmtime-internal-cache-36.0.20/src/worker.rs rename to v2/vendor/security/wasmtime-internal-cache-36.0.21/src/worker.rs diff --git a/v2/vendor/security/wasmtime-internal-cache-36.0.20/src/worker/tests.rs b/v2/vendor/security/wasmtime-internal-cache-36.0.21/src/worker/tests.rs similarity index 100% rename from v2/vendor/security/wasmtime-internal-cache-36.0.20/src/worker/tests.rs rename to v2/vendor/security/wasmtime-internal-cache-36.0.21/src/worker/tests.rs diff --git a/v2/vendor/security/wasmtime-internal-cache-36.0.20/src/worker/tests/system_time_stub.rs b/v2/vendor/security/wasmtime-internal-cache-36.0.21/src/worker/tests/system_time_stub.rs similarity index 100% rename from v2/vendor/security/wasmtime-internal-cache-36.0.20/src/worker/tests/system_time_stub.rs rename to v2/vendor/security/wasmtime-internal-cache-36.0.21/src/worker/tests/system_time_stub.rs diff --git a/v2/vendor/security/wasmtime-internal-cache-36.0.20/tests/cache_write_default_config.rs b/v2/vendor/security/wasmtime-internal-cache-36.0.21/tests/cache_write_default_config.rs similarity index 100% rename from v2/vendor/security/wasmtime-internal-cache-36.0.20/tests/cache_write_default_config.rs rename to v2/vendor/security/wasmtime-internal-cache-36.0.21/tests/cache_write_default_config.rs From 2dd4eab1f97374f8c6c56d3b646d4153c925c87d Mon Sep 17 00:00:00 2001 From: Dragan Spiridonov Date: Thu, 19 Nov 2026 15:15:16 +0100 Subject: [PATCH 2/3] fix(security): invoke auditor directly and reject CLI argument overrides --- docs/security/wasmtime-audit-20261119.md | 11 ++++++ scripts/ci/audit_rust_advisories.py | 10 +++--- scripts/ci/test_audit_rust_advisories.py | 43 ++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/docs/security/wasmtime-audit-20261119.md b/docs/security/wasmtime-audit-20261119.md index 24b7eed33b..277abef3a6 100644 --- a/docs/security/wasmtime-audit-20261119.md +++ b/docs/security/wasmtime-audit-20261119.md @@ -78,3 +78,14 @@ A future version or altered scope must be reassessed, not silently covered. No plugin is enabled, helper replaced, application installed, physical sensor qualified or production configuration changed by this source repair. Merge/release remain the maintainers' separate decisions. + +The CLI invokes cargo-audit directly with a fixed argument vector and shell=False. +It requires a standard Cargo.lock basename and has no alternate-database switch; +Cargo aliases and CLI-selected advisory arguments do not enter the process command. +Local pinned-snapshot evidence is reproduced by calling the native tool directly, +then exercising the pure classifier with fresh upstream evidence. + +A controlled negative probe confirmed the previous Cargo dispatcher could execute +a project-defined audit alias and accept an artificial clean result. The direct +auditor ignored that alias. This is a negative-control fixture, not a real clean +audit or a claim that any repository alias was used maliciously. diff --git a/scripts/ci/audit_rust_advisories.py b/scripts/ci/audit_rust_advisories.py index 78fa10b987..afa8ecd751 100644 --- a/scripts/ci/audit_rust_advisories.py +++ b/scripts/ci/audit_rust_advisories.py @@ -135,17 +135,17 @@ def main(): parser.add_argument("--raw-output", type=Path, default=Path("cargo-audit.json")) parser.add_argument("--classified-output", type=Path, default=Path("cargo-audit-classification.json")) parser.add_argument("--upstream-output", type=Path, default=Path("cargo-audit-upstream.json")) - parser.add_argument("--database", type=Path, help="explicit local advisory snapshot for reproducible local verification") args = parser.parse_args() lockfile = args.lockfile.resolve() + if lockfile.name != "Cargo.lock": + raise ValueError("the workspace audit requires a standard Cargo.lock filename") lock = tomllib.loads(lockfile.read_text()) policy_file = lockfile.parent / ".cargo/audit.toml" policy = tomllib.loads(policy_file.read_text()) if policy_file.exists() else {} ignored = policy.get("advisories", {}).get("ignore", []) - command = ["cargo", "audit", "--file", str(lockfile), "--json"] - if args.database is not None: - command += ["--db", str(args.database.resolve()), "--no-fetch"] - completed = subprocess.run(command, cwd=lockfile.parent, capture_output=True, text=True, timeout=300) + # A fixed direct auditor invocation avoids Cargo aliases and option injection. + completed = subprocess.run(["cargo-audit", "audit", "--file", "Cargo.lock", "--json"], + cwd=lockfile.parent, capture_output=True, text=True, timeout=300, shell=False) args.raw_output.write_text(completed.stdout) sys.stdout.write(completed.stdout) sys.stderr.write(completed.stderr) diff --git a/scripts/ci/test_audit_rust_advisories.py b/scripts/ci/test_audit_rust_advisories.py index ba6304110b..8a8eba24f4 100644 --- a/scripts/ci/test_audit_rust_advisories.py +++ b/scripts/ci/test_audit_rust_advisories.py @@ -1,5 +1,9 @@ import copy import json +import os +import subprocess +import sys +import tempfile from pathlib import Path import unittest from unittest import mock @@ -117,6 +121,45 @@ def test_native_warning_denial_cannot_be_overridden(self): self.assertEqual(decision(1, result, {}), 0) with self.assertRaises(ValueError): decision(1, classify(self.report([]), self.lock), {}) + def test_cli_rejects_option_like_or_shell_like_lockfile_names(self): + script = Path(__file__).parent / "audit_rust_advisories.py" + with tempfile.TemporaryDirectory(prefix="ruview-audit-cli-") as directory: + marker = Path(directory) / "must-not-exist" + lock = Path(directory) / "Cargo.lock; touch must-not-exist" + lock.write_text("version = 4\npackage = []\n") + result = subprocess.run([sys.executable, str(script), "--lockfile", str(lock)], + cwd=directory, capture_output=True, text=True, timeout=5) + self.assertEqual(result.returncode, 2) + self.assertIn("standard Cargo.lock", result.stderr) + self.assertFalse(marker.exists()) + + def test_cli_cannot_select_an_unreviewed_advisory_database(self): + script = Path(__file__).parent / "audit_rust_advisories.py" + result = subprocess.run([sys.executable, str(script), "--database", "/unreviewed"], + capture_output=True, text=True, timeout=5) + self.assertEqual(result.returncode, 2) + self.assertIn("unrecognized arguments", result.stderr) + + def test_project_cargo_entrypoint_is_never_executed(self): + script = Path(__file__).parent / "audit_rust_advisories.py" + with tempfile.TemporaryDirectory(prefix="ruview-audit-entrypoint-") as directory: + root = Path(directory) + (root / "Cargo.lock").write_text("version = 4\npackage = []\n") + marker = root / "unexpected-cargo" + clean = json.dumps({"vulnerabilities": {"found": False, "count": 0, "list": []}, "settings": {"ignore": []}}) + for binary in ("cargo", "cargo-audit"): + text = f"#!{sys.executable}\nfrom pathlib import Path\n" + if binary == "cargo": text += f"Path({str(marker)!r}).write_text('unexpected Cargo dispatch')\n" + text += f"print({clean!r})\n" + executable = root / binary + executable.write_text(text) + executable.chmod(0o755) + result = subprocess.run([sys.executable, str(script), "--lockfile", str(root / "Cargo.lock")], + cwd=root, env={**os.environ, "PATH": str(root) + os.pathsep + os.defpath}, + capture_output=True, text=True, timeout=5) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertFalse(marker.exists()) + def test_native_clean_report_remains_clean(self): self.assertEqual(classify(self.report([]), self.lock)["unresolved"], []) From 4bae2c739836309f994e0849f3aff540c2a84b12 Mon Sep 17 00:00:00 2001 From: Dragan Spiridonov Date: Fri, 20 Nov 2026 10:03:59 +0100 Subject: [PATCH 3/3] Remove temporary advisory reconciliation after upstream range correction --- .github/workflows/security-scan.yml | 12 +- docs/security/wasmtime-audit-20261119.md | 92 +++------ scripts/ci/audit_rust_advisories.py | 175 ------------------ .../wasmtime-primary-scopes-20261119.json | 60 ------ .../wasmtime-rustsec-metadata-20261119.json | 68 ------- scripts/ci/test_audit_rust_advisories.py | 168 ----------------- 6 files changed, 33 insertions(+), 542 deletions(-) delete mode 100644 scripts/ci/audit_rust_advisories.py delete mode 100644 scripts/ci/fixtures/wasmtime-primary-scopes-20261119.json delete mode 100644 scripts/ci/fixtures/wasmtime-rustsec-metadata-20261119.json delete mode 100644 scripts/ci/test_audit_rust_advisories.py diff --git a/.github/workflows/security-scan.yml b/.github/workflows/security-scan.yml index 4cdd250c73..897fda29de 100644 --- a/.github/workflows/security-scan.yml +++ b/.github/workflows/security-scan.yml @@ -36,21 +36,17 @@ jobs: # reviewed ignores in v2/.cargo/audit.toml. Run inside the v2 workspace # so that policy file is actually loaded. working-directory: v2 - env: - GH_TOKEN: ${{ github.token }} run: | - python3 ../scripts/ci/test_audit_rust_advisories.py - python3 ../scripts/ci/audit_rust_advisories.py --lockfile Cargo.lock + set -o pipefail + # Direct invocation avoids project-defined Cargo aliases. + cargo-audit audit --file Cargo.lock --json | tee cargo-audit.json - name: Upload Rust advisory report uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 if: always() with: name: cargo-audit-report - path: | - v2/cargo-audit.json - v2/cargo-audit-classification.json - v2/cargo-audit-upstream.json + path: v2/cargo-audit.json if-no-files-found: error # Static Application Security Testing (SAST) diff --git a/docs/security/wasmtime-audit-20261119.md b/docs/security/wasmtime-audit-20261119.md index 277abef3a6..77d09f9aa4 100644 --- a/docs/security/wasmtime-audit-20261119.md +++ b/docs/security/wasmtime-audit-20261119.md @@ -26,66 +26,32 @@ It is retained under the optional Wasmtime feature. This tests the dependency patch; it is not a claim that the existing application invokes that faulty API or that a deployed exploit was demonstrated. -## Why native cargo-audit still reports two matches - -With36.0.21, the native report drops from five to two. Its remaining0567/0573 -entries omit the upstream lower bounds and therefore incorrectly match36.x. -The two wrongly named WASI entries stop matching after the patch; no special -coverage for those entries is implemented. - -The existing security workflow uses audit_rust_advisories.py to retain the exact -native report and reconcile only these two reviewed range errors. This is not a -native audit-clean result: native exit1/two findings remain recorded separately -from zero unresolved findings after verified metadata reconciliation. - -A correction applies only when ALL of the following hold: - -- The RustSec selector fingerprint matches the checked-in ID/package/aliases/URL, - affected-function/platform selectors and patched/unaffected ranges. -- The finding is registry core wasmtime exactly36.0.21, with its checksum matching - both the verified registry archive and current Cargo.lock. Other versions, sources or checksums are not covered. -- Neither wasmtime-wasi nor wasmtime-wasi-http appears in the reviewed lockfile. - A different graph requires reassessment; those packages cannot gain coverage. -- A fresh read of the fixed official GitHub repository advisory endpoint matches - the reviewed primary package/version-range fingerprint. Network failure, - changed identity/ranges or missing evidence cannot fall back to the fixture. -- The report's existing ignore settings match the unchanged local audit policy. - -All unknown findings remain unresolved, including the version-applicable0569 if -it reappears. Malformed or incomplete reports fail closed. Fingerprints deliberately -cover scope selectors, not cosmetic prose. The primary scopes are checked live; -fixtures are used only by offline tests and never as a successful CI fallback. - -## Evidence and operating boundary - -The job retains cargo-audit.json (unmodified native output), -cargo-audit-classification.json (including native exit and unresolved findings), -and cargo-audit-upstream.json (live scopes and retrieval time). The existing -read-only GitHub Actions token is used by gh to read public published advisories; -no extra token, permission, secret or write operation is introduced. - -Offline negative tests exercise unknown advisories, changed RustSec/primary -selectors, affected/future versions, wrong registry/checksum, missing lock records, -WASI additions, policy injection, malformed reports, unreviewed network IDs and -live-provider failure. Existing ignores remain explicit; no blanket ignore, -severity-threshold change, raw report rewrite or advisory database edit is made. - -Native audit reproduction on snapshot7133866a after the patch reports two entries; -live primary verification classifies those two scope mismatches and leaves zero -unresolved entries. Remove this reconciliation when RustSec's ranges are corrected. -A future version or altered scope must be reassessed, not silently covered. - -No plugin is enabled, helper replaced, application installed, physical sensor -qualified or production configuration changed by this source repair. Merge/release -remain the maintainers' separate decisions. - -The CLI invokes cargo-audit directly with a fixed argument vector and shell=False. -It requires a standard Cargo.lock basename and has no alternate-database switch; -Cargo aliases and CLI-selected advisory arguments do not enter the process command. -Local pinned-snapshot evidence is reproduced by calling the native tool directly, -then exercising the pure classifier with fresh upstream evidence. - -A controlled negative probe confirmed the previous Cargo dispatcher could execute -a project-defined audit alias and accept an artificial clean result. The direct -auditor ignored that alias. This is a negative-control fixture, not a real clean -audit or a claim that any repository alias was used maliciously. +## Upstream correction and native audit — 2026-11-20 + +RustSec commit `074ea9a7ed619f511b5b7374c7a97e98d1e98be4` corrected both +range errors by recording `<39.0.0` and `<47.0.0` as unaffected for0567/0573. +With the patched lockfile, the CI-pinned cargo-audit0.22.2 now exits0 with zero +native registry findings under the unchanged audit policy. + +The temporary selector reconciliation, fixtures and live GitHub advisory API +calls have therefore been removed. CI again retains only the unmodified native +JSON report and uses its exit status, with pipefail preserving auditor failure. +No custom classification, extra token, offline database or advisory exception +is needed. Any future native advisory failure remains a job failure. + +Invoke `cargo-audit audit --file Cargo.lock --json` directly from `v2/`. +Direct binary invocation avoids executing a project-defined Cargo audit alias; +the installed tool remains pinned to0.22.2. An actual controlled Cargo-alias +negative probe established that the old dispatcher could execute a benign marker +and return artificial clean data; the direct auditor ignored that alias. Those +negative-control reports are not real security evidence. + +The dependency patch remains necessary:36.x before36.0.21 is still affected by +0569. The controlled API regression and archive provenance checks above remain. +Historical raw reports and reconciliation receipts describe the earlier database, +not the current native result. cargo-audit0.22.1 separately reports local path ZIP +packages as registry matches; it is not the pinned CI tool. Actual registry ZIP9 +and adapter tests remain separately relevant to the held server integration. + +No plugin is enabled, helper replaced, app installed or physical sensor qualified +by this change. Merge and release remain separate maintainer decisions. diff --git a/scripts/ci/audit_rust_advisories.py b/scripts/ci/audit_rust_advisories.py deleted file mode 100644 index afa8ecd751..0000000000 --- a/scripts/ci/audit_rust_advisories.py +++ /dev/null @@ -1,175 +0,0 @@ -#!/usr/bin/env python3 -"""Preserve cargo-audit output and reconcile two reviewed upstream range errors. - -This is not an advisory ignore list. Only the exact reviewed RustSec selectors, -registry Wasmtime 36.0.21, matching lockfile checksum and absent WASI packages can -qualify. Corrected/new metadata or other versions remain unresolved. See the -docs/security/wasmtime-audit-20261119.md assessment for authoritative package/range evidence. -""" -import argparse -import datetime -import hashlib -import json -from pathlib import Path -import subprocess -import sys -import tomllib - -REGISTRY = "registry+https://github.com/rust-lang/crates.io-index" -WASMTIME_ARCHIVE_SHA256 = "c58d2cbba3817454af39ec9f0b39279870a9a98ef4c52bbbcdd9c1ffc1f5f17f" -REVIEWED = { - "RUSTSEC-2026-0567": "99da727f7424b8b1f70c570e7347f7c2ad1d23ac7f7d1534654324e12297ee4c", - "RUSTSEC-2026-0573": "1716fc0fdcf2acae357882632f7ee3a3b6551116e6c18ba32f2f79ddf140ad08", -} - -PRIMARY = { - 'RUSTSEC-2026-0567': ('GHSA-2674-w29h-wqvj', - 'fe62715ac8a8ae324420af60d2ba36d55be25ede888c045cdfdbf5b18ffbd9ca'), - 'RUSTSEC-2026-0573': ('GHSA-wvgq-g5hf-6gm6', - '4a1af44d4f625d4efdf6585593ec47fb73e89fc162fe1ba525090ca9d43f5b70'), -} - - -def primary_scope(document): - if not isinstance(document, dict) or not isinstance(document.get("vulnerabilities"), list): - raise ValueError("invalid upstream advisory metadata") - values = [] - for value in document["vulnerabilities"]: - package = value["package"] - values.append({"package": {"name": package["name"], "ecosystem": package["ecosystem"].lower()}, - "vulnerable_version_range": "".join(value["vulnerable_version_range"].split()), - "patched_versions": "".join(value["patched_versions"].split())}) - values.sort(key=lambda value: json.dumps(value, sort_keys=True)) - return {"ghsa_id": document["ghsa_id"], "vulnerabilities": values} - - -def primary_digest(document): - return hashlib.sha256(json.dumps(primary_scope(document), sort_keys=True, separators=(",", ":")).encode()).hexdigest() - - -def fetch_primary(ghsa): - # IDs come only from PRIMARY constants, never from an untrusted report URL. - if ghsa not in {value[0] for value in PRIMARY.values()}: - raise ValueError("unreviewed upstream advisory identifier") - completed = subprocess.run(["gh", "api", "--hostname", "github.com", - "repos/bytecodealliance/wasmtime/security-advisories/" + ghsa], - capture_output=True, text=True, timeout=45) - if completed.returncode != 0 or len(completed.stdout) > 512 * 1024: - raise ValueError(f"live upstream verification failed for {ghsa} (gh exit {completed.returncode}); no offline fallback") - scope = primary_scope(json.loads(completed.stdout)) - if scope["ghsa_id"] != ghsa: - raise ValueError("upstream advisory identity changed") - return scope - - -def selector_digest(finding): - advisory = finding.get("advisory", {}) - selectors = {key: finding.get(key) for key in ("affected", "versions")} - selectors["advisory"] = {key: advisory.get(key) for key in ("id", "package", "aliases", "url")} - return hashlib.sha256(json.dumps(selectors, sort_keys=True, separators=(",", ":")).encode()).hexdigest() - - -def metadata_mismatch(finding, packages, primary): - advisory = finding.get("advisory", {}) - expected = REVIEWED.get(advisory.get("id")) - if expected is None or selector_digest(finding) != expected: - return False - ghsa, expected_primary = PRIMARY[advisory["id"]] - if ghsa not in primary or primary_digest(primary[ghsa]) != expected_primary: - return False - package = finding.get("package", {}) - if (package.get("name"), package.get("version"), package.get("source")) != ("wasmtime", "36.0.21", REGISTRY): - return False - checksum = package.get("checksum") - if checksum != WASMTIME_ARCHIVE_SHA256: - return False - identity = ("name", "version", "source", "checksum") - if not any(all(p.get(key) == package.get(key) for key in identity) for p in packages): - return False - if any(p.get("name") in {"wasmtime-wasi", "wasmtime-wasi-http"} for p in packages): - return False - return True - - -def classify(report, lock, ignored=(), primary=None): - primary = primary or {} - if not isinstance(report, dict) or report.get("error") or not isinstance(lock.get("package"), list): - raise ValueError("invalid cargo-audit report or lockfile") - vulnerability = report.get("vulnerabilities", {}) - findings = vulnerability.get("list") - count = vulnerability.get("count") - if (not isinstance(findings, list) or type(count) is not int or count < 0 - or count != len(findings) or type(vulnerability.get("found")) is not bool - or vulnerability["found"] != bool(findings)): - raise ValueError("cargo-audit omitted or malformed vulnerability findings") - configured = report.get("settings", {}).get("ignore", []) - if not isinstance(configured, list) or set(configured) != set(ignored): - raise ValueError("cargo-audit policy does not match the existing local policy") - result = {"raw_vulnerability_count": count, "metadata_corrections": [], "existing_policy_ignored": [], "unresolved": []} - for finding in findings: - if not isinstance(finding, dict) or not isinstance(finding.get("advisory"), dict): - raise ValueError("invalid advisory finding") - advisory_id = finding["advisory"].get("id") - if advisory_id in ignored: - result["existing_policy_ignored"].append(advisory_id) - elif metadata_mismatch(finding, lock["package"], primary): - result["metadata_corrections"].append({"id": advisory_id, "package": "wasmtime", "version": "36.0.21", "selector_sha256": REVIEWED[advisory_id], "upstream_advisory": PRIMARY[advisory_id][0], "upstream_scope_sha256": PRIMARY[advisory_id][1]}) - else: - result["unresolved"].append(finding) - return result - - -def decision(native_exit, result, policy): - if native_exit not in (0, 1): - raise ValueError("cargo-audit execution failed") - if native_exit == 1 and result["raw_vulnerability_count"] == 0: - raise ValueError("unexplained native failure without vulnerability findings") - # Never turn an explicitly denied native warning into success. - denied_output = bool(policy.get("output", {}).get("deny", [])) - return 1 if result["unresolved"] or (native_exit == 1 and denied_output) else 0 - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--lockfile", type=Path, default=Path("Cargo.lock")) - parser.add_argument("--raw-output", type=Path, default=Path("cargo-audit.json")) - parser.add_argument("--classified-output", type=Path, default=Path("cargo-audit-classification.json")) - parser.add_argument("--upstream-output", type=Path, default=Path("cargo-audit-upstream.json")) - args = parser.parse_args() - lockfile = args.lockfile.resolve() - if lockfile.name != "Cargo.lock": - raise ValueError("the workspace audit requires a standard Cargo.lock filename") - lock = tomllib.loads(lockfile.read_text()) - policy_file = lockfile.parent / ".cargo/audit.toml" - policy = tomllib.loads(policy_file.read_text()) if policy_file.exists() else {} - ignored = policy.get("advisories", {}).get("ignore", []) - # A fixed direct auditor invocation avoids Cargo aliases and option injection. - completed = subprocess.run(["cargo-audit", "audit", "--file", "Cargo.lock", "--json"], - cwd=lockfile.parent, capture_output=True, text=True, timeout=300, shell=False) - args.raw_output.write_text(completed.stdout) - sys.stdout.write(completed.stdout) - sys.stderr.write(completed.stderr) - if completed.returncode not in (0, 1) or len(completed.stdout) > 16 * 1024 * 1024: - raise ValueError("cargo-audit execution failed or returned an oversized report") - report = json.loads(completed.stdout) - primary = {} - for finding in report.get("vulnerabilities", {}).get("list", []): - advisory_id = finding.get("advisory", {}).get("id") - if advisory_id in PRIMARY and advisory_id not in ignored: - ghsa = PRIMARY[advisory_id][0] - primary[ghsa] = fetch_primary(ghsa) - args.upstream_output.write_text(json.dumps({"retrieved_at": datetime.datetime.now(datetime.timezone.utc).isoformat(), "scopes": primary}, indent=2) + "\n") - result = classify(report, lock, ignored, primary) - exit_code = decision(completed.returncode, result, policy) - result["native_exit_code"] = completed.returncode - args.classified_output.write_text(json.dumps(result, indent=2) + "\n") - print(json.dumps({key: value for key, value in result.items() if key != "unresolved"} | {"unresolved_count": len(result["unresolved"])})) - return exit_code - - -if __name__ == "__main__": - try: - sys.exit(main()) - except (ValueError, OSError, subprocess.SubprocessError) as error: - print(f"RUST AUDIT FAILED: {error}", file=sys.stderr) - sys.exit(2) diff --git a/scripts/ci/fixtures/wasmtime-primary-scopes-20261119.json b/scripts/ci/fixtures/wasmtime-primary-scopes-20261119.json deleted file mode 100644 index 1aae735d11..0000000000 --- a/scripts/ci/fixtures/wasmtime-primary-scopes-20261119.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "GHSA-2674-w29h-wqvj": { - "ghsa_id": "GHSA-2674-w29h-wqvj", - "vulnerabilities": [ - { - "package": { - "name": "wasmtime", - "ecosystem": "rust" - }, - "vulnerable_version_range": ">=39.0.0,<48.0.9", - "patched_versions": "48.0.9" - }, - { - "package": { - "name": "wasmtime", - "ecosystem": "rust" - }, - "vulnerable_version_range": ">=49.0.0,<49.0.6", - "patched_versions": "49.0.6" - }, - { - "package": { - "name": "wasmtime", - "ecosystem": "rust" - }, - "vulnerable_version_range": ">=50.0.0,<50.0.2", - "patched_versions": "50.0.2" - } - ] - }, - "GHSA-wvgq-g5hf-6gm6": { - "ghsa_id": "GHSA-wvgq-g5hf-6gm6", - "vulnerabilities": [ - { - "package": { - "name": "wasmtime", - "ecosystem": "rust" - }, - "vulnerable_version_range": ">=47.0.0,<=48.0.8", - "patched_versions": "48.0.9" - }, - { - "package": { - "name": "wasmtime", - "ecosystem": "rust" - }, - "vulnerable_version_range": ">=49.0.0,<=49.0.5", - "patched_versions": "49.0.6" - }, - { - "package": { - "name": "wasmtime", - "ecosystem": "rust" - }, - "vulnerable_version_range": ">=50.0.0,<=50.0.1", - "patched_versions": "50.0.2" - } - ] - } -} diff --git a/scripts/ci/fixtures/wasmtime-rustsec-metadata-20261119.json b/scripts/ci/fixtures/wasmtime-rustsec-metadata-20261119.json deleted file mode 100644 index b328e152e3..0000000000 --- a/scripts/ci/fixtures/wasmtime-rustsec-metadata-20261119.json +++ /dev/null @@ -1,68 +0,0 @@ -[ - { - "advisory": { - "id": "RUSTSEC-2026-0567", - "package": "wasmtime", - "title": "Abort in Wasmtime builds without the `threads` cargo feature", - "description": "This is an entry in the RustSec database for the Wasmtime security advisory\nlocated at\nhttps://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-2674-w29h-wqvj\nFor more information see the GitHub-hosted security advisory.", - "date": "2026-11-16", - "aliases": [ - "GHSA-2674-w29h-wqvj" - ], - "related": [], - "collection": "crates", - "categories": [], - "keywords": [], - "cvss": null, - "informational": null, - "references": [], - "source": null, - "url": "https://github.com/bytecodealliance/wasmtime/pull/15314", - "withdrawn": null, - "license": "CC0-1.0", - "expect-deleted": false - }, - "versions": { - "patched": [ - ">=48.0.9, <49.0.0", - ">=49.0.6, <50.0.0", - ">=50.0.2" - ], - "unaffected": [] - }, - "affected": null - }, - { - "advisory": { - "id": "RUSTSEC-2026-0573", - "package": "wasmtime", - "title": "Process abort when a GC heap's reservation isn't a multiple of the page size", - "description": "This is an entry in the RustSec database for the Wasmtime security advisory\nlocated at\nhttps://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-wvgq-g5hf-6gm6\nFor more information see the GitHub-hosted security advisory.", - "date": "2026-11-16", - "aliases": [ - "GHSA-wvgq-g5hf-6gm6" - ], - "related": [], - "collection": "crates", - "categories": [], - "keywords": [], - "cvss": null, - "informational": null, - "references": [], - "source": null, - "url": "https://github.com/bytecodealliance/wasmtime/pull/15320", - "withdrawn": null, - "license": "CC0-1.0", - "expect-deleted": false - }, - "versions": { - "patched": [ - ">=48.0.9, <49.0.0", - ">=49.0.6, <50.0.0", - ">=50.0.2" - ], - "unaffected": [] - }, - "affected": null - } -] diff --git a/scripts/ci/test_audit_rust_advisories.py b/scripts/ci/test_audit_rust_advisories.py deleted file mode 100644 index 8a8eba24f4..0000000000 --- a/scripts/ci/test_audit_rust_advisories.py +++ /dev/null @@ -1,168 +0,0 @@ -import copy -import json -import os -import subprocess -import sys -import tempfile -from pathlib import Path -import unittest -from unittest import mock -from audit_rust_advisories import classify as classify_report, REGISTRY, fetch_primary, decision, WASMTIME_ARCHIVE_SHA256 - -def classify(report, lock, ignored=(), primary=None): - if primary is None: - primary = json.loads((Path(__file__).parent / "fixtures/wasmtime-primary-scopes-20261119.json").read_text()) - return classify_report(report, lock, ignored, primary) - - -class AuditMetadataTests(unittest.TestCase): - def setUp(self): - self.findings = json.loads((Path(__file__).parent / "fixtures/wasmtime-rustsec-metadata-20261119.json").read_text()) - self.package = {"name": "wasmtime", "version": "36.0.21", "source": REGISTRY, "checksum": WASMTIME_ARCHIVE_SHA256} - for finding in self.findings: - finding["package"] = self.package.copy() - self.lock = {"package": [self.package.copy()]} - - def report(self, findings=None): - findings = self.findings if findings is None else findings - return {"vulnerabilities": {"found": bool(findings), "count": len(findings), "list": findings}, "settings": {"ignore": []}} - - def test_exact_reviewed_false_matches_are_reported_separately(self): - result = classify(self.report(), self.lock) - self.assertEqual(len(result["metadata_corrections"]), 2) - self.assertEqual(result["raw_vulnerability_count"], 2) - self.assertEqual(result["unresolved"], []) - - def test_old_or_future_affected_versions_cannot_use_the_correction(self): - for version in ("36.0.20", "36.0.22", "39.0.0", "47.0.0", "50.0.1"): - with self.subTest(version=version): - findings = copy.deepcopy(self.findings) - for finding in findings: - finding["package"]["version"] = version - lock = {"package": [{**self.package, "version": version}]} - self.assertEqual(len(classify(self.report(findings), lock)["unresolved"]), 2) - - def test_wasi_presence_prevents_wrong_package_coverage(self): - for name in ("wasmtime-wasi", "wasmtime-wasi-http"): - with self.subTest(package=name): - lock = {"package": [self.package.copy(), {"name": name, "version": "36.0.20"}]} - self.assertEqual(len(classify(self.report(), lock)["unresolved"]), 2) - - def test_actual_wasi_findings_remain_unresolved(self): - findings = copy.deepcopy(self.findings) - findings[0]["package"]["name"] = "wasmtime-wasi" - self.assertEqual(len(classify(self.report(findings), self.lock)["unresolved"]), 1) - - def test_changed_advisory_selectors_fail_closed(self): - for change in ("versions", "affected", "aliases", "url"): - findings = copy.deepcopy(self.findings) - if change == "versions": findings[0]["versions"]["patched"] = [">=99.0.0"] - elif change == "affected": findings[0]["affected"] = {"os": ["macos"]} - elif change == "aliases": findings[0]["advisory"]["aliases"] = ["GHSA-new-advisory"] - else: findings[0]["advisory"]["url"] = "https://example.invalid/unreviewed" - self.assertEqual(len(classify(self.report(findings), self.lock)["unresolved"]), 1) - - def test_unknown_or_version_applicable_advisory_is_not_covered(self): - for advisory in ("RUSTSEC-2099-0001", "RUSTSEC-2026-0569"): - findings = copy.deepcopy(self.findings) - findings[0]["advisory"]["id"] = advisory - self.assertEqual(len(classify(self.report(findings), self.lock)["unresolved"]), 1) - - def test_registry_identity_and_checksum_must_match_the_lockfile(self): - for change in ("checksum", "source"): - findings = copy.deepcopy(self.findings) - findings[0]["package"][change] = "unreviewed" - self.assertEqual(len(classify(self.report(findings), self.lock)["unresolved"]), 1) - self.assertEqual(len(classify(self.report(), {"package": []})["unresolved"]), 2) - - def test_coordinated_report_and_lock_checksum_tamper_is_rejected(self): - findings = copy.deepcopy(self.findings) - for finding in findings: finding["package"]["checksum"] = "b" * 64 - lock = {"package": [{**self.package, "checksum": "b" * 64}]} - self.assertEqual(len(classify(self.report(findings), lock)["unresolved"]), 2) - - def test_malformed_or_omitted_findings_fail_closed(self): - for report in ({}, {"vulnerabilities": {"found": False, "count": 0, "list": self.findings}}): - with self.assertRaises(ValueError): classify(report, self.lock) - - def test_existing_policy_is_honored_but_cannot_be_broadened_by_report(self): - findings = copy.deepcopy(self.findings) - findings[0]["advisory"]["id"] = "RUSTSEC-2099-0001" - report = self.report(findings) - report["settings"]["ignore"] = ["RUSTSEC-2099-0001"] - with self.assertRaises(ValueError): classify(report, self.lock) - result = classify(report, self.lock, ["RUSTSEC-2099-0001"]) - self.assertEqual(result["unresolved"], []) - self.assertEqual(result["existing_policy_ignored"], ["RUSTSEC-2099-0001"]) - - def test_missing_primary_evidence_does_not_cover_any_finding(self): - self.assertEqual(len(classify(self.report(), self.lock, primary={})["unresolved"]), 2) - - def test_changed_primary_package_or_range_revokes_coverage(self): - for field in ("package", "vulnerable_version_range"): - primary = json.loads((Path(__file__).parent / "fixtures/wasmtime-primary-scopes-20261119.json").read_text()) - target = primary["GHSA-2674-w29h-wqvj"]["vulnerabilities"][0] - if field == "package": target["package"]["name"] = "other-package" - else: target[field] = ">=36.0.0,<48.0.9" - self.assertEqual(len(classify(self.report(), self.lock, primary=primary)["unresolved"]), 1) - - def test_unknown_advisory_cannot_choose_a_network_location(self): - with mock.patch("audit_rust_advisories.subprocess.run") as execute: - with self.assertRaises(ValueError): fetch_primary("https://untrusted.invalid/advisory") - execute.assert_not_called() - - def test_live_primary_failure_has_no_offline_success_fallback(self): - with mock.patch("audit_rust_advisories.subprocess.run", return_value=mock.Mock(returncode=1, stdout="")): - with self.assertRaises(ValueError): fetch_primary("GHSA-2674-w29h-wqvj") - - def test_native_warning_denial_cannot_be_overridden(self): - result = classify(self.report(), self.lock) - self.assertEqual(decision(1, result, {"output": {"deny": ["warnings"]}}), 1) - self.assertEqual(decision(1, result, {}), 0) - with self.assertRaises(ValueError): decision(1, classify(self.report([]), self.lock), {}) - - def test_cli_rejects_option_like_or_shell_like_lockfile_names(self): - script = Path(__file__).parent / "audit_rust_advisories.py" - with tempfile.TemporaryDirectory(prefix="ruview-audit-cli-") as directory: - marker = Path(directory) / "must-not-exist" - lock = Path(directory) / "Cargo.lock; touch must-not-exist" - lock.write_text("version = 4\npackage = []\n") - result = subprocess.run([sys.executable, str(script), "--lockfile", str(lock)], - cwd=directory, capture_output=True, text=True, timeout=5) - self.assertEqual(result.returncode, 2) - self.assertIn("standard Cargo.lock", result.stderr) - self.assertFalse(marker.exists()) - - def test_cli_cannot_select_an_unreviewed_advisory_database(self): - script = Path(__file__).parent / "audit_rust_advisories.py" - result = subprocess.run([sys.executable, str(script), "--database", "/unreviewed"], - capture_output=True, text=True, timeout=5) - self.assertEqual(result.returncode, 2) - self.assertIn("unrecognized arguments", result.stderr) - - def test_project_cargo_entrypoint_is_never_executed(self): - script = Path(__file__).parent / "audit_rust_advisories.py" - with tempfile.TemporaryDirectory(prefix="ruview-audit-entrypoint-") as directory: - root = Path(directory) - (root / "Cargo.lock").write_text("version = 4\npackage = []\n") - marker = root / "unexpected-cargo" - clean = json.dumps({"vulnerabilities": {"found": False, "count": 0, "list": []}, "settings": {"ignore": []}}) - for binary in ("cargo", "cargo-audit"): - text = f"#!{sys.executable}\nfrom pathlib import Path\n" - if binary == "cargo": text += f"Path({str(marker)!r}).write_text('unexpected Cargo dispatch')\n" - text += f"print({clean!r})\n" - executable = root / binary - executable.write_text(text) - executable.chmod(0o755) - result = subprocess.run([sys.executable, str(script), "--lockfile", str(root / "Cargo.lock")], - cwd=root, env={**os.environ, "PATH": str(root) + os.pathsep + os.defpath}, - capture_output=True, text=True, timeout=5) - self.assertEqual(result.returncode, 0, result.stderr) - self.assertFalse(marker.exists()) - - def test_native_clean_report_remains_clean(self): - self.assertEqual(classify(self.report([]), self.lock)["unresolved"], []) - - -if __name__ == "__main__": - unittest.main()