Repository navigation
Security: baseline seven reviewed scan_packages findings - #8096
Conversation
pip scan-packages :: studio and :: hf-stack have been red on main since 2026-08-06, so every PR branched from it inherits two red checks. Seven CRITICAL/HIGH findings are no longer suppressed: five were never baselined (caio and torchao are newly resolved, two unsloth-zoo test files are new), and two unsloth-zoo entries had their evidence change under the same key. Each was read against the package source before being added: - torchao/prototype/gptq/gptq_example.py: /tmp appears only inside an argparse help string. The path feeds save_pretrained; the file's one subprocess.run invokes the lm_eval CLI with fixed arguments. - unsloth-zoo tests/test_hf_xet_fallback.py: a monkeypatch lambda whose return value contains the literal "/tmp/warm". No write, no exec. - unsloth-zoo unsloth_zoo/hf_xet_health.py: the Xet health probe. _endpoint() is HF_ENDPOINT or https://huggingface.co, and the token is only ever sent there as a Bearer header. It is optional; the endpoint answers anonymously. - unsloth-zoo tests/test_mlx_vlm_label_masks.py: __import__("threading") with a literal argument, plus mx.eval, which is MLX array evaluation. - unsloth-zoo unsloth_zoo/compiler.py: __import__(model_location, ...) guarded by try/except to check TRL internal names still import, plus the banner's chr(92) backslashes. - unsloth-zoo unsloth_zoo/mlx/loader.py: __import__ over a hardcoded patch_targets tuple of mlx_lm.tuner module names. - caio tests/test_raw_low_level.py: os.dup2 re-points a closed fd number at a fresh temp file to prove a completed one-shot io_uring Operation cannot be resubmitted. No sockets, no stdio redirection. Appended rather than regenerated. --write-baseline rewrites the whole file from whichever shard invoked it, which would drop the other two shards' entries, so the three shards were regenerated separately and only new keys merged in. The 215 existing entries are byte-identical and in their original order, which keeps the diff reviewable.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3bdc82dd1a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| "evidence": "Env: L317: token = os.environ.get(\"HF_TOKEN\")\nNetwork: L313: import urllib.request | L316: request = urllib.request.Request(url, headers = {\"User-Agent\": \"unsloth-xet-probe\"}) | L329: with urllib.request.urlopen(request, timeout = PROBE_TIMEOUT_SECONDS) as response: | L342: head = urllib.request.Request(cas, method = \"HEAD\", headers = {\"User-Agent\": \"unsloth-xet-probe\"}) | L344: urllib.request.urlopen(head, timeout = remaining)", | ||
| "evidence_hash": "674a558cd1bdfa1470dc2a9a2cd44be98ecc27c0beb37497757c656674e71654" |
There was a problem hiding this comment.
Bind the allowlist entry to the credential destination
When a later unsloth_zoo>=2026.8.5 release changes _endpoint() or the url assignment to an attacker-controlled host but retains the shown HF_TOKEN, Request(url), and urlopen calls, this entry still suppresses the CRITICAL finding. I verified that check_py_file returns the same 674a... evidence hash after replacing the default endpoint with https://attacker.invalid, because RE_NETWORK records only the API calls—not the destination or the Authorization-header data flow. This defeats the security gate's new-malicious-upload threat model for a file that transmits credentials, so the key should incorporate that context or the finding should remain active.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and I reproduced it both ways before agreeing. Against the entry as first pushed, replacing _endpoint()'s default with https://attacker.invalid leaves the evidence hash at 674a558c..., and so does repointing the url assignment itself, because the evidence records the Request/urlopen calls and not the destination. The entry would have kept suppressing a credential send to an attacker host.
Fixed by binding that entry to the file it was reviewed against rather than by widening the evidence regex, which would have rehashed and reopened roughly 78 unrelated entries across every network-involving check.
Finding now carries file_sha256, and a baseline entry may pin it. Semantics: absent means unpinned and the key alone suppresses, exactly as before, so the other 216 keys are untouched. Present means the entry only covers those exact file bytes, so any other edit to the file reopens the CRITICAL and forces a fresh review. --write-baseline carries an existing pin forward so a later regeneration cannot silently widen it back.
Only unsloth_zoo/hf_xet_health.py is pinned, since it is the one entry here that transmits a credential. The cost is that any future change to that file re-reds the gate until someone re-reviews it, which is the right trade for a file that sends HF_TOKEN.
Tests added in tests/security/test_scan_packages.py: a pinned entry reopens on changed file bytes, an unpinned entry stays content-agnostic, --write-baseline preserves a pin, and check_py_file stamps the digest. Two existing tests moved from == set() to == {} for the new return type. 103 passed.
Problem
pip scan-packages :: studioandpip scan-packages :: hf-stackhave been red onmainsince 2026-08-06, so every PR branched from it inherits two red checks that have nothing to do with its own changes. Four consecutiveSecurity auditruns onmainfailed on exactly these two jobs (31141376695,31139785578,31137295689,31130227244).Seven CRITICAL/HIGH findings are no longer suppressed by
scripts/scan_packages_baseline.json:caioandtorchaoare newly resolved into the dependency set, and twounsloth-zootest files are new.unsloth-zooentries exist under the same(package, file, check)key but their flagged code changed, which reopens them by design.unsloth_zoo/mlx/loader.pyalready carries two entries from two earlier releases, so this file has drifted before.What each finding is
Every one was read against the package source before being added, not accepted because it looked routine.
torchaotorchao/prototype/gptq/gptq_example.py/tmp+ execution/tmpappears only inside an argparsehelp=string,"Prefix for the output directory (e.g. /home/user/tmp/20260420)". The value feedssave_pretrained(). The file's onesubprocess.runinvokes thelm_evalCLI with fixed arguments.unsloth-zootests/test_hf_xet_fallback.py/tmp+ executionmonkeypatch.setattr(xf, "_run_download_attempt", lambda *a, **k: ("ok", "/tmp/warm")). The literal is a return value, never a path that is written or executed.unsloth-zoounsloth_zoo/hf_xet_health.pyHF_TOKEN+ network_endpoint()returnsHF_ENDPOINTorhttps://huggingface.co, and the token is only ever attached as anAuthorization: Bearerheader to that host. It is optional, since the endpoint answers anonymously.unsloth-zootests/test_mlx_vlm_label_masks.py__import__("threading").Lock()with a literal argument, plusmx.eval(...), which is MLX array evaluation and not Pythoneval.unsloth-zoounsloth_zoo/compiler.py__import__(model_location, fromlist=items)inside atry/exceptthat checks TRL internal names still import. The other match is the training banner usingchr(92)for backslashes.unsloth-zoounsloth_zoo/mlx/loader.py__import__(module_name, fromlist=["_"])iterating a hardcodedpatch_targetstuple ofmlx_lm.tuner.*module names.caiotests/test_raw_low_level.pyos.dup2(good_fd, closed_fd)re-points a closed fd number at a fresh temp file, to prove a completed one-shot io_uringOperationcannot be resubmitted. No sockets, no stdio redirection.Appended, not regenerated
--write-baselinerewrites the whole file from whichever shard invoked it, so running it on one shard would silently delete the other two shards' entries. All three shards were regenerated separately and only genuinely new keys merged in.The 215 existing entries are byte-identical and in their original order, so the diff is 56 insertions and 0 deletions. That is deliberate: an append-only diff is what makes a security allowlist reviewable.
Verification
Both failing shards were reproduced locally on Python 3.12, matching the runner, using the exact
audit-reqstransform fromsecurity-audit.yml. The local output matches CI exactly:hf-stackstudioextrasChecks run on the merged file:
_norm_pkg/_relpath_in_package/_evidence_hash, so the keys are the ones the scanner will actually match rather than hand-written.versionand_commentare unchanged.MEDIUM findings are untouched. The gate only fails on non-baselined CRITICAL/HIGH, and the baseline holds no MEDIUM entries.
Worth deciding separately
Four of the seven are in
unsloth-zoo, which we publish ourselves, and its evidence hashes move whenever the flagged code changes. That means a release can re-break this gate onmainand the next person pays the same cost. Three of the seven are in vendoredtests/paths, which are not imported at install or import time.Excluding vendored
tests/paths from the CRITICAL/HIGH gate would cover those three and cut the recurrence, but it is a real loosening of a security gate and narrows where a payload could hide, so I did not fold it into this PR. Happy to open it separately if you want it.