Skip to content

fix(security): re-baseline the huggingface-hub HTTP backoff loop for 1.x - #8135

Merged
danielhanchen merged 1 commit into
mainfrom
fix/scan-baseline-hf-hub-1x
Aug 8, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix/scan-baseline-hf-hub-1x

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

All three pip scan-packages shards are red on main, and all three fail on the same single unsuppressed CRITICAL:

[1] CRITICAL  C2 polling/beaconing loop detected
    Package:  huggingface-hub
    File:     huggingface_hub/utils/_http.py
    Evidence: L461:     while True: sha256:0c9641548adea74be4a8b0e86e8b75cc937a2b0f833b57dfa3d30d3e24d2537a

Each shard reports 1 CRITICAL and 0 HIGH, so this one finding is the whole reason SCAN_ENFORCE=1 exits 1 on studio, hf-stack and extras alike.

Why it reopened

RE_C2_POLLING looks for a while True loop containing a sleep and an HTTP call. That is the right shape for malware beaconing and also the exact shape of any retry-with-backoff helper, so huggingface_hub/utils/_http.py has been reviewed and baselined before, twice, at L462 and L298 against huggingface-hub 0.x.

huggingface-hub has since released 1.x, which moves from requests to httpx and refactors http_backoff into a shared _http_backoff_impl. The check uses a greedy DOTALL span, so its recorded evidence digest covers a large region of the file; that region is now different code and the digest changed. The baseline did exactly what it is documented to do and reopened the finding for review instead of suppressing changed code under a coarse key. This is dependency drift, not a regression in this repo.

Review of the new code

huggingface_hub/utils/_http.py:461 in 1.27.0 is _http_backoff_impl, described upstream as "Internal implementation of HTTP backoff logic shared between http_backoff and http_stream_backoff". It retries an httpx request on caller-configured exception types and status codes, sleeps with exponential backoff bounded by max_wait_time, and honours a 429 rate-limit reset. There is no beaconing, no remote-controlled interval, and no payload execution. Benign, the same judgement as the two entries it succeeds.

The change

One entry added. I added the 1.x entry rather than replacing the 0.x ones, matching how this file already carries several entries per file across versions (hf_api.py has three), so a pinned older huggingface-hub stays covered.

Verification

Locally, python scripts/scan_packages.py huggingface-hub goes from Summary: 1 CRITICAL, 6 MEDIUM (3 suppressed) to Summary: 6 MEDIUM (4 suppressed), exit 0.

I also ran the real Security audit workflow on a staging replica of this branch rather than queueing it here. All three shards pass, each with exactly one more finding suppressed and the CRITICAL gone:

Shard Before After Suppressed
studio 1 CRITICAL, 295 MEDIUM 295 MEDIUM 152 to 153
hf-stack 1 CRITICAL, 190 MEDIUM 190 MEDIUM 126 to 127
extras 1 CRITICAL, 182 MEDIUM 182 MEDIUM 98 to 99

Worth considering separately

This will recur. The baseline pins a digest over a greedy DOTALL span of a third-party file, so any upstream release that edits anywhere in that span reopens the entry and turns the security gate red with no change on our side. That is a deliberate and defensible trade, precision over stability, but it does mean routine dependency bumps can block CI. Narrowing the recorded span for this check, or pinning huggingface-hub, would both reduce the churn. Out of scope here.

All three pip scan-packages shards fail on the same single unsuppressed
CRITICAL:

  [1] CRITICAL  C2 polling/beaconing loop detected
      Package:  huggingface-hub
      File:     huggingface_hub/utils/_http.py
      Evidence: L461:     while True: sha256:0c9641548adea74be4a8b0e86e8b75cc937a2b0f833b57dfa3d30d3e24d2537a

Each shard reports 1 CRITICAL and 0 HIGH, so this one finding is what turns
SCAN_ENFORCE=1 into exit 1 on studio, hf-stack and extras alike.

The finding is the retry-with-exponential-backoff loop RE_C2_POLLING is meant
to catch in malware, matching here on a legitimate library. It was already
reviewed and baselined twice, at L462 and L298, against huggingface-hub 0.x.
huggingface-hub has since released 1.x, which moved from requests to httpx and
refactored http_backoff into a shared _http_backoff_impl. The greedy DOTALL
span the check records therefore covers different code, its digest changed, and
the baseline correctly reopened the finding for review rather than suppressing
changed code under a coarse key.

Reviewed the new code in 1.27.0. huggingface_hub/utils/_http.py:461 is
_http_backoff_impl, "Internal implementation of HTTP backoff logic shared
between http_backoff and http_stream_backoff": it retries an httpx request on
configured exception types and status codes, sleeps with exponential backoff
bounded by max_wait_time, and honours a 429 rate-limit reset. No beaconing, no
remote-controlled interval, no payload execution. Benign, same as the two
entries it succeeds.

Adds the 1.x entry rather than replacing the 0.x ones, matching how this file
already carries several entries per file across versions (hf_api.py has three),
so a pinned older huggingface-hub stays covered.

Verified: scan_packages.py huggingface-hub goes from
"Summary: 1 CRITICAL, 6 MEDIUM" (3 suppressed) to
"Summary: 6 MEDIUM" (4 suppressed), exit 0.
@danielhanchen
danielhanchen force-pushed the fix/scan-baseline-hf-hub-1x branch from a31e633 to 22b9c82 Compare August 8, 2026 02:54
@danielhanchen
danielhanchen merged commit 4e19313 into main Aug 8, 2026
17 of 19 checks passed
@danielhanchen
danielhanchen deleted the fix/scan-baseline-hf-hub-1x branch August 8, 2026 02:55
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Aug 8, 2026
unslothai#8135 re-baselined the huggingface_hub 1.x backoff loop, so that half of this
branch is done upstream. What is left is a defect it did not touch: the shipped
baseline carries five openai entries twice.

  openai/_base_client.py                          C2 polling/beaconing loop
  openai/auth/_workload.py                        IMDS + network calls
  openai/resources/beta/responses/responses.py    C2 polling/beaconing loop
  openai/resources/realtime/realtime.py           C2 polling/beaconing loop
  openai/resources/responses/responses.py         C2 polling/beaconing loop

223 entries, 218 distinct. A duplicated suppression is not harmless: whoever
removes one copy to un-suppress a finding still gets no finding, because the
second copy is still matching.

The 111 tests here cover the baseline's shape and matching semantics, including
the duplicate check that caught this. Every one passes against main once the
five copies are gone.
danielhanchen added a commit that referenced this pull request Aug 8, 2026
#8135 re-baselined the huggingface_hub 1.x backoff loop, so that half of this
branch is done upstream. What is left is a defect it did not touch: the shipped
baseline carries five openai entries twice.

  openai/_base_client.py                          C2 polling/beaconing loop
  openai/auth/_workload.py                        IMDS + network calls
  openai/resources/beta/responses/responses.py    C2 polling/beaconing loop
  openai/resources/realtime/realtime.py           C2 polling/beaconing loop
  openai/resources/responses/responses.py         C2 polling/beaconing loop

223 entries, 218 distinct. A duplicated suppression is not harmless: whoever
removes one copy to un-suppress a finding still gets no finding, because the
second copy is still matching.

The 111 tests here cover the baseline's shape and matching semantics, including
the duplicate check that caught this. Every one passes against main once the
five copies are gone.

Co-authored-by: danielhanchen <[email protected]>
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