Skip to content

pull: gated and private repos come down with a Hugging Face token, sent only to the hub's own host - #3524

Merged
ashhart merged 2 commits into
mainfrom
lead/pull-hf-token
Nov 20, 2026
Merged

ashhart merged 2 commits into
mainfrom
lead/pull-hf-token

Conversation

@ashhart

@ashhart ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

tensorfold pull can't download gated or private Hugging Face repos today. No request carries a token, so Llama and Gemma repos fail at config.json with a bare HubStatus, and a private repo exits 1 with no message. This sends the user's token, only to the hub's own origin.

What this changes

  • Token: HF_TOKEN, then HUGGING_FACE_HUB_TOKEN, then the one token file the hf tools read: the file HF_TOKEN_PATH names, else $HF_HOME/token, else ~/.cache/huggingface/token (where hf auth login saves it). Surrounding whitespace is trimmed. An empty variable counts as unset, so no file named token in the working directory is ever read.

  • Where it goes: only to the hub endpoint's own scheme, host and port (huggingface.co, or HF_ENDPOINT's). Zig 0.17's std.http.Client keeps an Authorization header on redirects to any host, so pull now follows redirects itself (Auth.send) and decides the header on each hop. Downloads redirected to the storage hosts go without it. Each caller keeps its redirect limit.

  • Refusals: a 401 or 403 from the hub's own origin is refused by name and not retried.

    • Without a token: the repo is gated or private, or the name is wrong (Hugging Face answers a mistyped name the same way). Accept its terms, then set HF_TOKEN or run hf auth login.
    • With a token: the token from HF_TOKEN (or whichever source) lacks access.
    • A 403 from another host, such as an expired signed link, keeps today's handling.
  • Unusable tokens: a token with a space or control character inside, one over 4096 bytes, or an unreadable token file is refused by its source before any request. The token itself never appears in output, errors or files.

  • No token set: every request is unchanged.

  • The EXLR8 node pull behaves the same way.

  • Issue: n/a. This came from the 16 Nov check of competitor gap docs against main: three engines' docs list gated pulls, and main had no Authorization header anywhere in zig/src/cli.

  • Stacked on: main.

  • atc overlap --json: to run after review; no open PR touches zig/src/cli/pull*.zig or hub.zig (checked with gh pr list file lists on 16 Nov).

Checks on this head

  • Head commit: ede86cf on main e7e2424.
  • Lean checker: 337 on base and head, 0 new (tools/pr_check.py --base origin/main: 0 errors, 1 advisory warning, "pass --pr NUMBER").
  • Tests:
    • zig build test-pull-host: 41/41. Before the change the two gated tests failed in fetchOne with HubStatus (33/35).
    • zig build test-pull-security: 67/67 steps, 17/17 tests. The new "security:" tests reach the Linux and Windows CI runs.
    • zig build test-cli: 48/63 (15 existing info and plan tests skip as before).
    • zig build test-cli-memory-host test-info-config: 18/18.
    • zig build test-cuda-host: 6777/6817 (40 skipped).
    • zig build check-native-cuda-host: 7/7 steps.
    • zig build test-golden: 55/55 equal.
    • zig fmt --check build.zig zig and git diff --check: clean.
  • What the tests cover:
    • Token order, and only one file consulted.
    • Unusable tokens are refused by source.
    • The origin rule: subdomain, lookalike host, http downgrade, other port, mirror.
    • A gated pull redirected to a CDN on another host, whole and in pieces.
    • The token never appears in output or files.
    • Refusal texts and request counts, with a refused download asked for once.
    • Same-origin redirects and the 3-hop limit.
    • The EXLR8 whole-file path.
  • Negative controls failed as planted: a std-style redirect that keeps the header, a token sent to every host, and either no-retry rule removed.
  • CI: pending.
  • Not run: no Windows run (pull_auth.zig was compiled for x86_64 and aarch64 Windows and Linux), and no real Hugging Face request.

Receipt

n/a: a CLI download path that can't reach inference. Host checks are above.

Checklist

  • The title and description match the head commit.

  • New tests fail before the change, pass after it, and skip cleanly without their dependency.

  • Comments and docstrings are one line. No measurements or history in the source.

  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines. The test tokens are fictional (hf_Example...).

  • Synthena (Ash's Agent)

…nt only to the hub's own host

The token is HF_TOKEN, then HUGGING_FACE_HUB_TOKEN, then the one token file the hf tools read: HF_TOKEN_PATH,
else $HF_HOME/token, else ~/.cache/huggingface/token. Pull follows redirects itself, so a hop to another scheme,
host or port, such as the storage a download is redirected to, goes without it; std.http.Client keeps the header
on such hops. A 401 or 403 from the hub names the repo and whether a token is missing or lacks access, and is not
retried.
@ashhart
ashhart merged commit 664a522 into main Nov 20, 2026
2 of 11 checks passed
@ashhart
ashhart deleted the lead/pull-hf-token branch November 20, 2026 11:23
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