Skip to content

Security: pin the credential-send allowlist entry to the reviewed file - #8104

Merged
danielhanchen merged 2 commits into
mainfrom
security-pin-credential-entry
Aug 7, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
security-pin-credential-entry

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Follow-up to #8096. That PR merged while this was still being verified, so the fix lands separately.

Problem

#8096 added an allowlist entry for unsloth_zoo/hf_xet_health.py under the check Harvests environment variables/secrets AND makes network calls. The evidence for that check records the Request and urlopen calls but not the destination they point at, so the entry keeps matching after the destination changes.

Verified two ways against the published wheel, which is what CI scans:

  • Replacing _endpoint()'s default with https://attacker.invalid leaves the evidence hash at 674a558c....
  • Replacing the url assignment itself with an attacker host leaves it at 674a558c....

In both cases the entry goes on suppressing the CRITICAL. For a file that attaches HF_TOKEN as a Bearer header, that is a blind spot for credential exfiltration in exactly the "malicious upload of a package we depend on" case the gate exists to catch.

Why not widen the evidence

Making the network evidence capture destinations would rehash every entry of every network-involving check. That is roughly 78 of the 222 entries across Harvests environment variables/secrets AND makes network calls, Enumerates filesystem AND makes network calls, C2 polling/beaconing loop detected, Downloads and executes remote code and others. They would all reopen at once and the gate would go red until each was re-reviewed. Binding the one entry that transmits a credential is the proportionate change.

What this does

Finding gains file_sha256, stamped by check_py_file from the file it scanned, and a baseline entry may pin it.

  • Absent: unpinned. The (package, file, check, evidence_hash) key alone suppresses, exactly as before. 216 of the 217 keys are untouched, so no existing entry changes behaviour.
  • Present: the entry covers only those file bytes. Any other edit to the file reopens the finding and forces a fresh review.

--write-baseline carries a pin over from the baseline in effect for the run rather than from its own output path. Reading it from the output would drop every pin whenever the output goes somewhere new, which is exactly the silent widening the carry-over exists to prevent.

Only unsloth_zoo/hf_xet_health.py is pinned. The cost is that any future change to that file re-reds the gate until someone re-reviews it. That is the right trade for a file that sends HF_TOKEN, and it is the property the entry was missing.

Note on the digest

The pin is taken from the published wheel through the scanner's own iter_archive_files, not from a source checkout. The two differ, and a checkout digest never matches what CI scans. My first attempt used the git clone and the shard went red, which is what caught it.

Verification

  • tests/security/test_scan_packages.py: 103 passed. Four new tests cover a pinned entry reopening on changed file bytes, an unpinned entry staying content-agnostic, --write-baseline preserving a pin, and check_py_file stamping the digest. Two existing tests move from == set() to == {} for the new return type.
  • All three scan shards reproduced locally on Python 3.12 with the exact audit-reqs transform from security-audit.yml: hf-stack 190 MEDIUM exit 0, studio 295 MEDIUM exit 0, extras 182 MEDIUM exit 0.
  • Against the wheel: unmodified file suppressed, _endpoint() repointed reopens, url assignment repointed reopens.
  • ruff check clean.

Still worth deciding separately

Four of the seven entries added in #8096 are in unsloth-zoo, which we publish, and three are in vendored tests/ paths that are never imported at install or import time. Excluding vendored tests/ from the CRITICAL/HIGH gate would cut how often a release re-reds this gate, but it narrows where a payload could hide, so it is not folded in here.

danielhanchen and others added 2 commits August 7, 2026 10:11
…gainst

The evidence for "Harvests environment variables/secrets AND makes network
calls" records the Request/urlopen calls but not the destination, so the
unsloth_zoo/hf_xet_health.py entry added in the previous commit kept the same
evidence hash after repointing _endpoint() at another host. Verified both ways:
swapping the default endpoint and swapping the url assignment each leave the
hash at 674a558c, so the entry would have gone on suppressing a credential send
to an attacker-controlled host.

Widening the network evidence to capture destinations would rehash and reopen
around 78 unrelated entries across every network-involving check, so bind the
one entry instead.

Finding now carries file_sha256, and a baseline entry may pin it. Absent means
unpinned and the key alone suppresses, exactly as before, so the other 216 keys
are untouched. Present means the entry covers only those file bytes, so any
other edit reopens the CRITICAL and forces a fresh review. --write-baseline
carries a pin over from the baseline in effect, not from its own output path,
which would drop pins whenever the output goes somewhere new.

Only hf_xet_health.py is pinned, being the one entry here that transmits a
credential. 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.

The digest is taken from the published wheel through the scanner's own archive
reader, not from a source checkout: the two differ, and a checkout digest never
matches what CI scans.

Tests: 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 move to the dict return type. 103 pass, and all three
scan shards exit 0.
@danielhanchen
danielhanchen merged commit d24f0f1 into main Aug 7, 2026
22 of 23 checks passed
@danielhanchen
danielhanchen deleted the security-pin-credential-entry branch August 7, 2026 10:15

@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: 0d05bd4a42

ℹ️ 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 thread scripts/scan_packages.py
# An unpinned entry wins, since it already suppresses the key on its own.
pin = e.get("file_sha256")
if key not in keys:
keys[key] = {pin} if pin else None

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 Reject malformed digest pins instead of treating them as unpinned

When a baseline entry explicitly contains a falsy malformed pin such as "file_sha256": "" or [], this branch stores None, which means the entry suppresses every file having the same finding key. Thus a typo or partially generated baseline silently disables the new whole-file protection and can allow a changed credential-send destination to remain suppressed; validate that a present pin is a 64-character hexadecimal string and skip or reject invalid entries rather than interpreting them as legacy unpinned entries.

Useful? React with 👍 / 👎.

danielhanchen added a commit that referenced this pull request Aug 18, 2026
…ies (#9148)

* Security audit: pin openai, and re-review the four digest-pinned entries

The extras shard of the security audit has been red on main since 2026-08-17
19:14Z with four non-baselined CRITICALs, all in `openai`:

    Harvests environment variables/secrets AND makes network calls
      openai/_client.py, openai/lib/azure.py, openai/lib/bedrock.py
    Accesses cloud metadata/IMDS AND makes network calls
      openai/auth/_workload.py

It is not a code change here. The last green run was 18:23Z and every run after
18:40Z failed on the same four findings, on main and on unrelated PR branches
alike, which is upstream drift rather than anything in the tree.

`openai>=2.7.2` is the only floating spec in extras.txt that carries digest-pinned
baseline entries. openai 3.2.0 published at 19:14Z and changed all four files.
Confirmed by digest: the four `file_sha256` values in the baseline match openai
3.0.0 and 3.1.0 exactly and none of 3.2.0's.

The pin is deliberate and correct (#8104, #8565): the evidence for these entries
records that a network call exists but not where it goes, so `client.post(...,
data=api_key)` appended to one of these files would leave the evidence hash
untouched. Only the file digest can reopen that, so any edit upstream makes must
red the gate until someone re-reads it.

Which is the review, done here. Every destination in the four files at 3.2.0 is
first-party or a documented cloud metadata endpoint: api.openai.com,
auth.openai.com, 169.254.169.254 (Azure IMDS), metadata.google.internal,
management.azure.com, and bedrock-mantle.{region}.api.aws. The one instance-level
POST is the workload-identity token exchange, which defaults to
https://auth.openai.com/oauth/token and sets follow_redirects=False. The env reads
are OPENAI_API_KEY, OPENAI_ADMIN_KEY, OPENAI_WEBHOOK_SECRET,
AZURE_OPENAI_API_KEY, AZURE_OPENAI_AD_TOKEN and AWS_BEARER_TOKEN_BEDROCK, each
used to authenticate to its own service. Same benign patterns as the reviewed
3.0.0, so the four entries are re-pinned to 3.2.0's digests and nothing else in
the 214-entry baseline is touched.

Re-baselining alone would only buy time until the next release, so the spec is
pinned too. Every other requirement in extras.txt is already an exact pin (#8408
pinned the bare ones and skipped this one because it had a specifier). Pinning
makes the bump deliberate: whoever raises the version is the one who re-runs
--write-baseline and re-reads the diff, instead of the gate going red on release
day for a change nobody here made.

The new test asserts that invariant directly, since it is the part that will be
got wrong again: a package with digest-pinned baseline entries must not float in
studio/backend/requirements. Reverting the spec to `openai>=2.7.2` fails it and
names extras.txt:62.

Verified:
  - `scan_packages.py 'openai==3.2.0'` exits 0; on 3.1.0 it exits 1, so the pin
    still bites and the entries were not widened.
  - The whole extras shard (`--with-deps -r extras.txt`, 128 archives) exits 0
    with 0 active CRITICAL/HIGH, against 4 CRITICAL and exit 1 before.
  - tests/security/test_scan_packages.py: 121 passed.

Unrelated, and not a defect: the `openai-whisper==20250625` line in the same log
is an INFO, not the failure. That version is on PyPI as an sdist only, and the
bulk resolve runs `--only-binary :all:` so it never executes a setup.py, which is
the scanner's whole security model. "from versions: none" is what pip says about
an sdist-only package under that flag, and the per-spec fallback plus the direct
sdist fetch that follow are the designed path working. The scipy
`assert_raises(ValueError, CubicSpline, ...)` evidence quoted alongside it is a
MEDIUM and cannot fail the gate; it is a false positive on `bc1`, a boundary
condition variable in scipy's own test file that looks like a bech32 address.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Keep the openai pin off Python 3.9, which the first version of it broke

`openai==3.2.0` on its own was a regression, caught simulating the install rather
than reading it. openai 3.x is `requires-python >=3.10` and this project is
`>=3.9,<3.15`, so an exact pin resolves to nothing at all on 3.9, where `>=2.7.2`
had quietly been selecting 2.48.0. Fixing a CI gate by breaking an install is not
a fix.

Split on the marker instead, which is what the rest of this file already does for
soundfile and tabulate. 2.48.0 is the newest release that accepts 3.9, so the 3.9
branch pins exactly what 3.9 was resolving to before.

Resolved with uv against every interpreter in requires-python, --no-deps, three
ways (main, the bad pin, this):

  spec           3.9        3.10     3.12     3.13     3.14
  >=2.7.2        2.48.0     3.2.0    3.2.0    3.2.0    3.2.0
  ==3.2.0        NO SOLUTION  3.2.0  3.2.0    3.2.0    3.2.0
  split          2.48.0     3.2.0    3.2.0    3.2.0    3.2.0

So this is behaviour-preserving: identical to main on every supported Python, and
the whole of extras.txt resolves to the same 31 packages on 3.10, 3.12, 3.13 and
3.14 before and after, differing only in the `# via -r` filename. 3.9 fails on
both sides for an unrelated and pre-existing reason (scikit-learn==1.7.1 is itself
>=3.10), so nothing here changes that either.

The security audit is unaffected: it runs on 3.12, markers are evaluated by pip,
and the scan of the two-line spec fetches only 3.2.0 and exits 0. The 3.9 branch
is never scanned, exactly as the floating spec's 3.9 resolution never was.

The guard is widened to the second half of the same invariant: the exact pins for
a digest-pinned package must cover every supported Python between them, so a
marker partition with a hole in it fails. Its limit is now written down rather
than implied. It is marker-only and offline, so it catches a `>= "3.11"` beside a
`< "3.10"`, but it cannot catch a single unmarked pin whose release does not
support 3.9, because that means asking PyPI for the release's requires-python.
The resolution simulation above is what covers that case, and the test module
stays network-free.

Verified: reverting to `openai>=2.7.2` still fails the guard naming extras.txt.
tests/security/test_scan_packages.py: 121 passed.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Widen the pin guard to the pyproject inputs, and make `==` mean one version

Two review findings, both real, both reproduced before fixing.

The guard read `studio/backend/requirements/*.txt` and stopped there, but
security-audit.yml builds `audit-reqs/unsloth-deps.txt` out of pyproject's
`project.dependencies` plus the `huggingfacenotorch` extra and feeds that to the
hf-stack shard. A digest-pinned package declared there was invisible to the guard,
which is the whole failure mode it exists to catch, one file over. It now reads
both halves, from one helper that mirrors the workflow's own input transform.

Reading pyproject turns up the counterexample the finding named: unsloth_zoo is
digest-pinned (hf_xet_health.py, the credential send that motivated #8104) and
declared `unsloth_zoo>=2026.8.12`. That one is deliberately not version-pinned and
must not be. The recurrence being prevented is an upstream release WE DO NOT
CONTROL changing the bytes and reddening main on a day nobody touched the repo;
unsloth_zoo is ours, released in lockstep, and an exact pin would break that. When
its digest reopens, the change is one of ours and re-reviewing it is the point of
the pin. So it is named in an exemption rather than quietly skipped, and the
exemption is itself asserted: it must contain only names that really are digest
pinned, and at least one third-party package must remain, so the guard cannot be
defused by growing the list. That assertion earned its keep immediately, failing
on `unsloth` until it was removed for having no pinned entry.

Second, `==` has to mean one version. The old prefix regex accepted `openai==3.*`,
which pip resolves as a prefix match to whatever 3.x is newest, recreating the
exact release-day failure. The specifier is now parsed with
packaging.requirements rather than pattern-matched: exactly one clause, operator
`==`, version not ending in `.*`. Parsing also drops the hand-rolled name and
marker splitting, so extras and whitespace stop being edge cases.

Four negative controls, each red with its own message and green after:
  - `openai>=2.7.2` in extras.txt: not pinned to one version, names extras.txt:68.
  - `openai==3.*`: same assertion, names the wildcard spec.
  - `< "3.9"` instead of `< "3.10"`: openai uncovered on 3.9.
  - `openai>=2.7.2` added to pyproject's dependencies: names pyproject.toml, which
    is the finding above and was green before this commit.

tests/security/test_scan_packages.py: 121 passed.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Read pyproject through tomli when tomllib is not there

pyproject sets requires-python >=3.9 and testpaths ["tests/security"], so a
bare pytest from the repo root collects this module on 3.9 and 3.10, where
tomllib does not exist (it landed in 3.11, PEP 680). The two helpers added
here imported it unguarded, so on those interpreters the file raised
ModuleNotFoundError instead of reporting a result. tomli is already pinned for
python_version < 3.11 in extras-no-deps.txt, and four other suites in this repo
already use exactly this fallback.

The regression test supplies the backport rather than requiring it. The
tests-security job installs only pytest and PyYAML, so a test that leaned on a
real tomli being importable would importorskip its way to green there and never
execute the branch at all. Registering the parser this interpreter does have
under the name the fallback looks for keeps it load-bearing everywhere, while
import tomllib is made to fail for the duration so the fallback is provably
what gets consulted. Checked red on the unfixed helpers and green on the fixed
ones, including with tomli hidden.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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