Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
security: lockfile audit must block non-registry sources and missing integrity by default (#8541)
Daniel Hanf5c64f4a08b6
diff --git a/.github/workflows/lockfile-audit.yml b/.github/workflows/lockfile-audit.ymlindex cc027c732c6..417e494faaa 100644--- a/.github/workflows/lockfile-audit.yml+++ b/.github/workflows/lockfile-audit.yml@@ -7,13 +7,12 @@# npm or cargo lockfile, on push to main, and on a daily schedule so# newly-published IOCs surface even when no PR opens.#-# Default behavior is "advisory": only public indicator-of-compromise-# strings, known-malicious pinned versions, and structurally broken-# lockfiles fail the build. Structural anomalies (missing integrity,-# non-default registry, etc.) are emitted as GitHub Actions warnings-# but do not block merges. This deliberately keeps the noise floor-# low while still failing the moment a checked-in lockfile starts-# pointing at known-bad bytes.+# Default behavior blocks public indicator-of-compromise strings,+# known-malicious pinned versions, structurally broken lockfiles, and+# provenance/integrity failures (non-registry resolved URL or cargo+# source, missing integrity hash or cargo checksum) -- the pre-install+# fetches this gate stops before `npm ci` runs lifecycle scripts.+# Lesser anomalies warn; --strict escalates them to blocking.## This workflow is intentionally separate from security-audit.yml:# - security-audit.yml is the umbrella job (pip-audit + npm audit +@@ -80,8 +79,7 @@ jobs:run: python3 -c "import ast; ast.parse(open('scripts/lockfile_supply_chain_audit.py').read())"- name: Run lockfile supply-chain audit- # Default mode: only known-malicious pinned versions, known IOC- # strings, and structurally broken lockfiles fail the build.- # Missing-integrity and other structural anomalies are emitted- # as ::warning:: annotations and do not gate merges.+ # Blocks known-malicious versions, IOC strings, broken lockfiles,+ # and provenance/integrity failures. Lesser anomalies stay+ # ::warning:: unless --strict is passed.run: python3 scripts/lockfile_supply_chain_audit.pydiff --git a/scripts/lockfile_supply_chain_audit.py b/scripts/lockfile_supply_chain_audit.pyindex f9cf726dc16..a87d8fcab72 100644--- a/scripts/lockfile_supply_chain_audit.py+++ b/scripts/lockfile_supply_chain_audit.py@@ -617,12 +617,19 @@ def audit_cargo_lockfile(path: Path) -> list[Finding]:# Finding kinds split into BLOCKING vs ADVISORY for the default run mode.# Blocking = public attack indicators (known-malicious version, IOC-# string). Advisory = structural anomalies that warn but don't block.-# --strict makes every finding blocking.+# string) plus the provenance/integrity checks this gate must enforce+# before `npm ci` / `cargo fetch` runs lifecycle scripts. Advisory =+# incomplete-but-not-fetchable anomalies. --strict blocks everything.BLOCKING_KINDS: frozenset[str] = frozenset({"blocked-known-malicious","known-ioc-string",+ # A non-registry URL or an unverifiable tarball is the exact+ # pre-install fetch this gate exists to stop.+ "non-registry-resolved-url",+ "missing-integrity-hash",+ "non-registry-cargo-source",+ "missing-cargo-checksum",# A structurally broken lockfile might hide a real attack."malformed-lockfile","missing-lockfile",@@ -670,11 +677,13 @@ def main(argv: list[str] | None = None) -> int:action = "store_true",help = ("Treat every finding as blocking (exit 1). "- "Default mode only blocks on known-malicious versions, "- "indicator-of-compromise strings, or structurally broken "- "lockfiles; everything else is printed as an advisory "- "warning with exit 0. CI should use the default; local "- "audits aiming for zero noise can opt in via --strict."+ "Default mode already blocks on known-malicious versions, "+ "indicator-of-compromise strings, structurally broken "+ "lockfiles, and dependency provenance/integrity failures "+ "(non-registry npm URL or cargo source, missing integrity "+ "hash or cargo checksum). Remaining anomalies, such as an "+ "entry with no resolved URL, are printed as an advisory "+ "warning with exit 0; --strict escalates those too."),)args = parser.parse_args(argv)@@ -769,7 +778,8 @@ def main(argv: list[str] | None = None) -> int:print("[lockfile-audit] Refusing to proceed. Each blocking finding ""above is either a public indicator-of-compromise, a known-"- "malicious pinned version, or a structurally broken lockfile. "+ "malicious pinned version, an unverifiable / non-registry "+ "dependency source, or a structurally broken lockfile. ""Investigate before running `npm ci` or `cargo fetch`.",file = sys.stderr,)diff --git a/tests/security/test_lockfile_supply_chain_audit.py b/tests/security/test_lockfile_supply_chain_audit.pyindex d464fe44d42..b1b7ebccd00 100644--- a/tests/security/test_lockfile_supply_chain_audit.py+++ b/tests/security/test_lockfile_supply_chain_audit.py@@ -2,6 +2,7 @@from __future__ import annotations+import jsonimport osimport subprocessimport sys@@ -168,8 +169,8 @@ def test_malicious_cargo_lockfile_refused(tmp_path):assert "git+https://example.com" in combined-def test_malicious_cargo_lockfile_default_mode_advisory(tmp_path):- """Default mode emits non-registry-cargo-source as advisory ::warning:: but exits 0."""+def test_malicious_cargo_lockfile_default_mode_blocks(tmp_path):+ """Default mode refuses a non-registry cargo source; provenance blocks without --strict."""lockfile = tmp_path / "Cargo.lock"lockfile.write_text(_MALICIOUS_CARGO_LOCK)proc = _run_auditor(@@ -177,13 +178,53 @@ def test_malicious_cargo_lockfile_default_mode_advisory(tmp_path):npm_lockfiles = [FIXTURES / "clean_lockfile.json"],cargo_lockfiles = [lockfile],)- assert proc.returncode == 0, (- f"expected exit 0 (advisory), got {proc.returncode}\n"+ assert proc.returncode == 1, (+ f"expected exit 1 (blocking), got {proc.returncode}\n"f"--- stdout ---\n{proc.stdout}\n--- stderr ---\n{proc.stderr}")combined = proc.stdout + proc.stderrassert "non-registry-cargo-source" in combined- assert "advisory finding" in combined+ assert "blocking finding" in combined+++def test_provenance_kinds_block_by_default():+ """The four provenance/integrity kinds must stay in BLOCKING_KINDS."""+ for kind in (+ "non-registry-resolved-url",+ "missing-integrity-hash",+ "non-registry-cargo-source",+ "missing-cargo-checksum",+ ):+ assert kind in lsa.BLOCKING_KINDS, f"{kind} must block in default mode"+++def test_non_registry_npm_tarball_blocks_by_default(tmp_path):+ """A file: tarball with a valid-looking integrity must not pass the default audit,+ or `npm ci` runs its lifecycle scripts on the runner."""+ lockfile = tmp_path / "package-lock.json"+ lockfile.write_text(+ json.dumps(+ {+ "name": "victim",+ "version": "1.0.0",+ "lockfileVersion": 3,+ "packages": {+ "": {"name": "victim", "version": "1.0.0"},+ "node_modules/evil-pkg": {+ "version": "1.0.0",+ "resolved": "file:evil-pkg-1.0.0.tgz",+ "integrity": "sha512-" + "A" * 86 + "==",+ },+ },+ }+ )+ )+ proc = _run_auditor(root = tmp_path, npm_lockfiles = [lockfile])+ assert proc.returncode == 1, (+ f"expected exit 1 (blocking), got {proc.returncode}\n"+ f"--- stdout ---\n{proc.stdout}\n--- stderr ---\n{proc.stderr}"+ )+ assert "non-registry-resolved-url" in proc.stdout + proc.stderrdef test_audit_cargo_lockfile_direct_call(tmp_path):@@ -223,8 +264,8 @@ def test_gha_escape_collapses_finding_to_one_line():assert "bad stuff" in escaped-def test_advisory_finding_emitted_as_single_line_annotation(tmp_path):- """Advisory ::warning:: must be one physical line (%0A-escaped). Regression for PR #5604."""+def test_blocking_finding_emitted_as_single_line_annotation(tmp_path):+ """The ::error:: annotation must be one physical line (%0A-escaped)."""lockfile = tmp_path / "Cargo.lock"lockfile.write_text(_MALICIOUS_CARGO_LOCK)proc = _run_auditor(@@ -232,14 +273,12 @@ def test_advisory_finding_emitted_as_single_line_annotation(tmp_path):npm_lockfiles = [FIXTURES / "clean_lockfile.json"],cargo_lockfiles = [lockfile],)- warning_lines = [line for line in proc.stderr.splitlines() if line.startswith("::warning::")]- assert warning_lines, (- "expected at least one ::warning:: annotation; " f"stderr was:\n{proc.stderr}"- )- for line in warning_lines:+ error_lines = [line for line in proc.stderr.splitlines() if line.startswith("::error::")]+ assert error_lines, f"expected at least one ::error:: annotation; stderr was:\n{proc.stderr}"+ for line in error_lines:# One physical line: kind/package/detail joined via %0A, not split.assert "%0A" in line, (- f"::warning:: line has no %0A escape; multi-line text "+ f"::error:: line has no %0A escape; multi-line text "f"would be truncated by GH Actions:\n{line}")assert "non-registry-cargo-source" in line@@ -247,6 +286,35 @@ def test_advisory_finding_emitted_as_single_line_annotation(tmp_path):assert "detail:" in line+def test_advisory_finding_emitted_as_single_line_annotation(tmp_path):+ """The advisory ::warning:: path stays %0A-escaped too. `missing-resolved-url` is+ incompleteness, not a fetchable source, so it stays advisory."""+ lockfile = tmp_path / "package-lock.json"+ lockfile.write_text(+ json.dumps(+ {+ "name": "victim",+ "version": "1.0.0",+ "lockfileVersion": 3,+ "packages": {+ "": {"name": "victim", "version": "1.0.0"},+ "node_modules/incomplete-pkg": {"version": "1.0.0"},+ },+ }+ )+ )+ proc = _run_auditor(root = tmp_path, npm_lockfiles = [lockfile])+ assert proc.returncode == 0, (+ f"expected exit 0 (advisory), got {proc.returncode}\n"+ f"--- stdout ---\n{proc.stdout}\n--- stderr ---\n{proc.stderr}"+ )+ warning_lines = [line for line in proc.stderr.splitlines() if line.startswith("::warning::")]+ assert warning_lines, f"expected a ::warning:: annotation; stderr was:\n{proc.stderr}"+ for line in warning_lines:+ assert "%0A" in line+ assert "missing-resolved-url" in line++# ---------------------------------------------------------------------------# SF4: skip env var requires a justification value.# ---------------------------------------------------------------------------