Repository navigation
Stop committing the two fixture archives that antivirus vendors flag - #10979
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
`tests/security/fixtures/malicious_sdist.tar.gz` and `malicious_wheel.whl` embed the May-12 IOC literal on purpose, so the `scan_packages.py` regression tests can prove the scanner trips on it. That makes them true positives for other vendors too. Per the per-file scan in discussion #9577, they are the only two detected files in the whole fixture set: the sdist scores 2/60 and the wheel 2/65 (Tencent, Rising), and their presence is what makes Panda report `Exploit/CVE-2014-6271` against GitHub's `unsloth-main.zip`. #10060 took the test tree out of the PyPI artifacts, which fixed those. A repository archive contains `tests/` by construction, so it kept matching and users kept re-reporting it, twice in that thread alone. I said there that no packaging change can affect it. That is true, but a fixture change can: `fixtures/_build.py` is already a complete deterministic builder for exactly these archives, and nothing invoked it. The built outputs were simply committed beside it. So build them at session start instead: - `tests/security/conftest.py` gains a session-scoped autouse fixture calling `_build.build_all()`. It generates in place, so all dozen-odd `FIXTURES / "malicious_wheel.whl"` call sites keep working unchanged. Unlike the `network_blocker` fixture above it, this patches nothing and has no teardown, so session scope carries none of the leak-past-the-suite risk that docstring records. - The three archives are removed from git and added to `.gitignore`. - `_build.py` assembles the IOC host and artifact names from concatenated pieces, the way `test_scan_packages.py` already writes `_ioc_host = "git-tanstack." + "com"`. Insurance only: the #9577 scan found the `.py` sources undetected, so the archives leaving git is the part that matters. - New `test_no_archive_fixture_is_committed` reads `git ls-files`, not the directory, because the files are present on disk in every run and it is the index that has to stay empty. Determinism is already pinned by `SOURCE_DATE_EPOCH = 0` and the 1980 DOS-epoch zip dates, and I checked it rather than assumed it: the generated archives are byte-identical to the committed ones for all three. `test_fixture_bytes_are_deterministic` still compares a rebuild against the copy the suite is using, so it keeps its meaning. Verification: 589 passed, 6 skipped across `tests/security/`, with the archives deleted from disk first so the fixture is what produces them. The new guard was confirmed to bite by re-adding the three files to the index, reproducing main's state, where it fails. This does not clean the hashes already on VirusTotal, and Panda will keep flagging an archive of any older commit. It stops new ones.
191043f to
c56be3f
Compare
…race each other
`.github/workflows/workflow-trigger-lint.yml:130` runs `pytest -q -n 4` over `tests/security` with
the default `--dist load`, which scatters tests from ONE file across all four workers. Each worker
runs the session-scoped autouse fixture and rewrote these three archives at their fixed paths while
the others were reading them, and `write_bytes` truncates before it writes.
The failure this produces is the nasty kind. A reader that catches the truncated window does not get
a corrupt-file error; it gets a short member list and fails asserting scanner semantics --
`assert any("setup.py" in f.filename for f in blockers)` -- which nobody would trace back to a write
race.
Two guards, because either alone leaves a hole. The write is skipped entirely when the bytes on disk
are already correct, so in the normal case only the first worker writes at all; otherwise it goes to
a pid-unique temp name and `os.replace`, which is atomic on POSIX and on Windows. Without the pid the
workers would collide on the temp file instead of the final one.
What makes this sound rather than merely narrower: the build is deterministic (SOURCE_DATE_EPOCH,
1980 DOS times), so a reader sees either the complete old file or the complete new one and those are
byte-identical. The three archives still hash to fe6927b5, 0c327818 and 7516530a -- the same bytes
that were committed before they were generated -- and a test now pins that, because the equivalence
argument depends on it.
Honest note on how this was found and confirmed: a review flagged it and reported reproducing it at
16-28% with `-n 8`. I could NOT reproduce it in 22 runs on this box. The hazard is real by
construction and the CI invocation that exposes it is real, but I am not going to claim a
reproduction I did not get.
Fixed: the generated fixtures could race four CI workers
The failure this produces is the nasty kind. A reader that catches the truncated window does not get a corrupt-archive error; it gets a short member list and fails asserting scanner semantics -- Two guards, because either alone leaves a hole:
What makes this sound rather than merely narrower: the build is deterministic ( Honest note on the evidenceA review flagged this and reported reproducing it at 16-28% with Two things independently proven clean
|
|
@codex security review |
The assignment had no teardown. That was harmless while this file was run as a script, and is not harmless now that a session fixture calls it partway through a broader pytest run: it overwrote any caller-provided value for the remainder of the worker, and every later test and subprocess inherited the false epoch. Nothing in the builder read it either. Each writer is handed the fixed timestamp directly and zipfile takes the 1980 DOS tuple, so the assignment bought nothing in exchange for that reach. The generated bytes are unchanged, confirmed by hash before and after: fe6927b5, 0c327818, 7516530a.
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…nslothai#10979) * Stop committing the two fixture archives that antivirus vendors flag `tests/security/fixtures/malicious_sdist.tar.gz` and `malicious_wheel.whl` embed the May-12 IOC literal on purpose, so the `scan_packages.py` regression tests can prove the scanner trips on it. That makes them true positives for other vendors too. Per the per-file scan in discussion unslothai#9577, they are the only two detected files in the whole fixture set: the sdist scores 2/60 and the wheel 2/65 (Tencent, Rising), and their presence is what makes Panda report `Exploit/CVE-2014-6271` against GitHub's `unsloth-main.zip`. unslothai#10060 took the test tree out of the PyPI artifacts, which fixed those. A repository archive contains `tests/` by construction, so it kept matching and users kept re-reporting it, twice in that thread alone. I said there that no packaging change can affect it. That is true, but a fixture change can: `fixtures/_build.py` is already a complete deterministic builder for exactly these archives, and nothing invoked it. The built outputs were simply committed beside it. So build them at session start instead: - `tests/security/conftest.py` gains a session-scoped autouse fixture calling `_build.build_all()`. It generates in place, so all dozen-odd `FIXTURES / "malicious_wheel.whl"` call sites keep working unchanged. Unlike the `network_blocker` fixture above it, this patches nothing and has no teardown, so session scope carries none of the leak-past-the-suite risk that docstring records. - The three archives are removed from git and added to `.gitignore`. - `_build.py` assembles the IOC host and artifact names from concatenated pieces, the way `test_scan_packages.py` already writes `_ioc_host = "git-tanstack." + "com"`. Insurance only: the unslothai#9577 scan found the `.py` sources undetected, so the archives leaving git is the part that matters. - New `test_no_archive_fixture_is_committed` reads `git ls-files`, not the directory, because the files are present on disk in every run and it is the index that has to stay empty. Determinism is already pinned by `SOURCE_DATE_EPOCH = 0` and the 1980 DOS-epoch zip dates, and I checked it rather than assumed it: the generated archives are byte-identical to the committed ones for all three. `test_fixture_bytes_are_deterministic` still compares a rebuild against the copy the suite is using, so it keeps its meaning. Verification: 589 passed, 6 skipped across `tests/security/`, with the archives deleted from disk first so the fixture is what produces them. The new guard was confirmed to bite by re-adding the three files to the index, reproducing main's state, where it fails. This does not clean the hashes already on VirusTotal, and Panda will keep flagging an archive of any older commit. It stops new ones. * Publish the generated fixtures atomically, so four CI workers cannot race each other `.github/workflows/workflow-trigger-lint.yml:130` runs `pytest -q -n 4` over `tests/security` with the default `--dist load`, which scatters tests from ONE file across all four workers. Each worker runs the session-scoped autouse fixture and rewrote these three archives at their fixed paths while the others were reading them, and `write_bytes` truncates before it writes. The failure this produces is the nasty kind. A reader that catches the truncated window does not get a corrupt-file error; it gets a short member list and fails asserting scanner semantics -- `assert any("setup.py" in f.filename for f in blockers)` -- which nobody would trace back to a write race. Two guards, because either alone leaves a hole. The write is skipped entirely when the bytes on disk are already correct, so in the normal case only the first worker writes at all; otherwise it goes to a pid-unique temp name and `os.replace`, which is atomic on POSIX and on Windows. Without the pid the workers would collide on the temp file instead of the final one. What makes this sound rather than merely narrower: the build is deterministic (SOURCE_DATE_EPOCH, 1980 DOS times), so a reader sees either the complete old file or the complete new one and those are byte-identical. The three archives still hash to fe6927b5, 0c327818 and 7516530a -- the same bytes that were committed before they were generated -- and a test now pins that, because the equivalence argument depends on it. Honest note on how this was found and confirmed: a review flagged it and reported reproducing it at 16-28% with `-n 8`. I could NOT reproduce it in 22 runs on this box. The hazard is real by construction and the CI invocation that exposes it is real, but I am not going to claim a reproduction I did not get. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Stop build_all leaking SOURCE_DATE_EPOCH into the rest of the worker The assignment had no teardown. That was harmless while this file was run as a script, and is not harmless now that a session fixture calls it partway through a broader pytest run: it overwrote any caller-provided value for the remainder of the worker, and every later test and subprocess inherited the false epoch. Nothing in the builder read it either. Each writer is handed the fixed timestamp directly and zipfile takes the 1980 DOS tuple, so the assignment bought nothing in exchange for that reach. The generated bytes are unchanged, confirmed by hash before and after: fe6927b5, 0c327818, 7516530a. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Follows up discussion #9577, where you and @Sermoris tracked the repeated
unsloth-main.zipdetections down to two specific files.What is happening
tests/security/fixtures/malicious_sdist.tar.gzandmalicious_wheel.whlembed the May-12 IOC literal on purpose, so thescan_packages.pyregression tests can prove the scanner trips on it. That makes them true positives for other vendors too. Per the per-file scan in #9577, they are the only two detected files in the whole fixture set:malicious_sdist.tar.gzmalicious_wheel.whlfixtures/And their presence is what makes Panda report
Exploit/CVE-2014-6271against GitHub's repository archive.#10060 took the test tree out of the PyPI artifacts, which fixed those. A repository archive contains
tests/by construction, so it kept matching and users kept re-reporting it, twice in that thread alone. I said there that no packaging change can affect it. That is true, but a fixture change can:fixtures/_build.pyis already a complete, deterministic builder for exactly these archives, and nothing invoked it. The built outputs were simply committed beside it.Change
Build them at session start instead of committing them.
tests/security/conftest.pygains a session-scoped autouse fixture calling_build.build_all(). It generates in place, so all dozen-oddFIXTURES / "malicious_wheel.whl"call sites keep working unchanged. Unlike thenetwork_blockerfixture directly above it, this patches nothing and has no teardown, so session scope carries none of the leak-past-the-suite risk that docstring records..gitignore._build.pyassembles the IOC host and artifact names from concatenated pieces, the waytest_scan_packages.pyalready writes_ioc_host = "git-tanstack." + "com". Insurance only, since the CVE detection report on virus total #9577 scan found the.pysources undetected. The archives leaving git is the part that matters.test_no_archive_fixture_is_committedreadsgit ls-files, not the directory, because the files are present on disk in every run and it is the index that has to stay empty.The scanner pattern tables in
scripts/scan_packages.py,scan_npm_packages.pyandlockfile_supply_chain_audit.pyare untouched: they have to contain the IOC to function, and all were undetected.The bytes are unchanged
Determinism is already pinned by
SOURCE_DATE_EPOCH = 0and the 1980 DOS-epoch zip dates, and I checked it rather than assumed it. The generated archives are byte-identical to the committed ones for all three, so the scanner trips on exactly what it tripped on before.test_fixture_bytes_are_deterministicstill compares a rebuild against the copy the suite is using, so it keeps its meaning.Verification
tests/security/, with the three archives deleted from disk first, so the fixture is what produces them.main's state, where it fails.sha256of each generated archive compared against the committed copy: identical.What this does and does not do
It stops new detections against the repository archive. It does not retroactively clean the hashes already on VirusTotal, and Panda will keep flagging an archive of any older commit, since those still contain the files. Worth saying in the #9577 thread so nobody expects the existing report to change.