Skip to content

Security: baseline seven reviewed scan_packages findings - #8096

Merged
danielhanchen merged 1 commit into
mainfrom
security-baseline-refresh
Aug 7, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
security-baseline-refresh

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

pip scan-packages :: studio and pip scan-packages :: hf-stack have been red on main since 2026-08-06, so every PR branched from it inherits two red checks that have nothing to do with its own changes. Four consecutive Security audit runs on main failed on exactly these two jobs (31141376695, 31139785578, 31137295689, 31130227244).

Seven CRITICAL/HIGH findings are no longer suppressed by scripts/scan_packages_baseline.json:

  • Five were never baselined. caio and torchao are newly resolved into the dependency set, and two unsloth-zoo test files are new.
  • Two unsloth-zoo entries exist under the same (package, file, check) key but their flagged code changed, which reopens them by design.

unsloth_zoo/mlx/loader.py already 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.

Severity Package / file Matched Why it is benign
CRITICAL torchao torchao/prototype/gptq/gptq_example.py /tmp + execution /tmp appears only inside an argparse help= string, "Prefix for the output directory (e.g. /home/user/tmp/20260420)". The value feeds save_pretrained(). The file's one subprocess.run invokes the lm_eval CLI with fixed arguments.
CRITICAL unsloth-zoo tests/test_hf_xet_fallback.py /tmp + execution monkeypatch.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.
CRITICAL unsloth-zoo unsloth_zoo/hf_xet_health.py reads HF_TOKEN + network This is the Xet health probe. _endpoint() returns HF_ENDPOINT or https://huggingface.co, and the token is only ever attached as an Authorization: Bearer header to that host. It is optional, since the endpoint answers anonymously.
HIGH unsloth-zoo tests/test_mlx_vlm_label_masks.py obfuscation + exec __import__("threading").Lock() with a literal argument, plus mx.eval(...), which is MLX array evaluation and not Python eval.
HIGH unsloth-zoo unsloth_zoo/compiler.py obfuscation + exec __import__(model_location, fromlist=items) inside a try/except that checks TRL internal names still import. The other match is the training banner using chr(92) for backslashes.
HIGH unsloth-zoo unsloth_zoo/mlx/loader.py obfuscation + exec __import__(module_name, fromlist=["_"]) iterating a hardcoded patch_targets tuple of mlx_lm.tuner.* module names.
CRITICAL caio tests/test_raw_low_level.py reverse / bind shell os.dup2(good_fd, closed_fd) 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, not regenerated

--write-baseline rewrites 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-reqs transform from security-audit.yml. The local output matches CI exactly:

Shard Before After
hf-stack 3 CRITICAL, 3 HIGH, 190 MEDIUM, 121 suppressed, exit 1 exit 0
studio 1 CRITICAL, 295 MEDIUM, 152 suppressed, exit 1 exit 0
extras 182 MEDIUM, exit 0 exit 0

Checks run on the merged file:

  • Key-set invariant: 215 before, 222 after, 0 removed, 7 added, computed with the scanner's own _norm_pkg / _relpath_in_package / _evidence_hash, so the keys are the ones the scanner will actually match rather than hand-written.
  • The first 215 entries compare equal to the pre-merge file element by element, so nothing was reordered or rewritten.
  • JSON parses, and version and _comment are 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 on main and the next person pays the same cost. Three of the seven are in vendored tests/ 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.

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +1746 to +1747
"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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@danielhanchen
danielhanchen merged commit 6afcf22 into main Aug 7, 2026
19 checks passed
@danielhanchen
danielhanchen deleted the security-baseline-refresh branch August 7, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant