Skip to content

Security audit: re-baseline the benign findings that reopened on main - #7741

Merged
danielhanchen merged 1 commit into
mainfrom
fix-scan-baseline
Aug 2, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix-scan-baseline

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

All three pip scan-packages shards in Security audit are failing on main, and have been for several commits (3f2fc5af, 8c3c7511, bba8e395, c67410a7, f0d88d7b). This re-baselines the findings that reopened.

Before

Shard Unsuppressed Exit
studio 6 CRITICAL 1
hf-stack 3 CRITICAL, 3 HIGH 1
extras 3 CRITICAL 1

After

Shard Unsuppressed Exit
studio none 0
hf-stack none 0
extras none 0

Why they reopened

The allowlist key is (package, package-relative file, check, evidence_hash), and the hash is taken over the matched code with the L<NN>: markers stripped. Line shifts and version bumps are absorbed by design; a change to the flagged code itself moves the hash and reopens the entry for re-review.

The scanner resolves unpinned dependencies fresh from PyPI on every run, so when an upstream release edits a flagged line, the entry reopens. Ten of these eleven (package, file, check) tuples already had an entry in the baseline under an older hash. fastapi/routing.py, huggingface_hub/hf_api.py, openai/_base_client.py and unsloth_zoo/mlx/loader.py have each been through this before, which is why the file already carries an appended block at the end from a previous round. So this is the mechanism behaving as intended rather than a new exposure.

No dependency manifest changed, and nothing here is a new package or a new version pin.

The eleven findings

Each was read in the actual source rather than taken from the report line.

Loops flagged as C2 beaconing

  • fastapi/routing.py:594, huggingface_hub/hf_api.py:4811, openai/_base_client.py:276. The latter two are paginators: yield a page, advance while has_next_page(), return otherwise.

huggingface_hub/_sandbox.py:84-88, flagged as a staged dropper

The one finding that genuinely downloads and executes, so I checked it against upstream rather than assuming. It is the bootstrap for the Sandboxes feature, Apache-2.0, authored by the huggingface_hub team, and it fetches sbx-server from the endpoint configured on the HfApi client rather than a hardcoded third-party host. Documented at https://huggingface.co/docs/huggingface_hub/main/guides/sandbox.

exec(compile(...)) flagged as downloading and executing remote code

  • IPython/core/interactiveshell.py:2998 and traitlets/config/loader.py:646. Both compile and execute a local file: running user code is what an interactive shell does, and loading a Python config file is what the config loader does. The paired "network" evidence on the second IPython finding is urlopen in the %load magic, matched against a HistoryManager import for the filesystem half.

Our own published package

  • unsloth_zoo/mlx/loader.py:4096: __import__(module_name, fromlist=["_"]) where module_name iterates a hardcoded tuple of mlx_lm.tuner.lora and mlx_lm.tuner.dora, not caller input. The paired exec evidence is a dozen mx.eval(model.parameters()) calls, which evaluate MLX arrays and are unrelated to Python eval.
  • tests/test_mlx_save_export_regressions.py:246: a literal temporary_location="/tmp/ignored" kwarg in a call-forwarding assertion.
  • tests/test_compiler_decorated_forward.py: compile() and exec() over source the test generated and asserted against a line earlier.
  • tests/test_mlx_trainer_internals.py:2355: __import__("math").exp(2.5) inside a pytest.approx assert.

Shape of the change

One append hunk, 88 lines, no deletions. The existing 203 entries are byte identical and _comment and version are unchanged, so nothing was reordered or rewritten.

Checked on the merged file: all 214 entries' stored evidence_hash recompute to themselves under the scanner's own _evidence_hash, so there are no hand-edited hashes. The file has 5 duplicate keys, all openai pairs that predate this change; none of the new entries duplicates an existing key.

Verification

Reproduced all three shards locally against the same inputs the workflow builds, on Python 3.12 to match the setup-python pin. This matters: on 3.13 the studio shard reports two extra multiprocess findings, because multiprocess ships per-interpreter wheels that vendor the corresponding CPython multiprocessing. Those two are not in this change, since they do not occur under the pinned version.

Before the change the local runs match CI exactly. hf-stack reproduces 3 CRITICAL, 3 HIGH, 184 MEDIUM with 117 suppressed (80 CRITICAL, 37 HIGH), the same numbers as the failing job, and every evidence hash matches.

After the change:

Shard MEDIUM before / after Suppressed before Suppressed after
studio 293 / 293 145 (91 C, 54 H) 151 (97 C, 54 H)
hf-stack 184 / 184 117 (80 C, 37 H) 123 (83 C, 40 H)
extras 181 / 181 96 (61 C, 35 H) 99 (64 C, 35 H)

Each shard's suppressed count rises by exactly the number of findings it was failing on, and no MEDIUM count moves, so the new entries match only their own keys and nothing broader.

Follow-up worth considering separately

This will recur on the next upstream release that touches any flagged line, which is the cost of the content-hash key. Options are to pin the scanned set, or to let an entry match on (package, file, check) with the hash recorded but advisory. Both are policy changes to the scanner rather than a baseline refresh, so I have kept them out of this PR.

All three pip scan-packages shards fail on main. Every unsuppressed finding is
a pattern false positive in a mainstream library or in our own published test
files, and each one already has an entry in the allowlist under an older
evidence hash.

The baseline key is (package, package-relative file, check, evidence_hash),
and the hash is over the matched code. Line shifts and version bumps are
absorbed, but when an upstream release edits a flagged line the hash moves and
the entry reopens for re-review. That is what happened here.

Reviewed and appended the 11 reopened findings:

- fastapi/routing.py, huggingface_hub/hf_api.py, openai/_base_client.py:
  flagged as C2 beaconing. All three are ordinary loops, hf_api and
  _base_client being paginators that advance until there is no next page.
- huggingface_hub/_sandbox.py: flagged as a staged dropper. This is the
  Sandbox feature bootstrap, fetching sbx-server from the endpoint configured
  on the HfApi client.
- IPython/core/interactiveshell.py and traitlets/config/loader.py: flagged as
  downloading and executing remote code. Both are exec(compile(...)) over a
  local file, which is what an interactive shell and a config loader do.
- unsloth_zoo/mlx/loader.py: __import__ over a hardcoded tuple of mlx_lm
  module names, paired with mx.eval() calls that evaluate MLX arrays rather
  than Python source.
- unsloth-zoo tests: a literal temporary_location="/tmp/ignored" kwarg,
  compile()/exec() over codegen the test itself produced, and
  __import__("math").exp inside a pytest.approx assert.

Existing entries are untouched: the diff is a single append hunk with no
deletions, and the first 203 entries are byte identical.

Verified by reproducing all three shards locally on Python 3.12, matching the
workflow pin. Before the change the shards reproduce the exact CI counts. After
it, all three exit 0 with unchanged MEDIUM counts and suppressed counts up by
exactly the number of findings each shard was failing on.
@danielhanchen
danielhanchen merged commit aa4ea75 into main Aug 2, 2026
19 checks passed
@danielhanchen
danielhanchen deleted the fix-scan-baseline branch August 2, 2026 10:07
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