Skip to content

Follow only same-origin and Hugging Face CDN redirects for MiMo prompt fixtures - #1924

Merged
davidtai merged 2 commits into
devfrom
ci/mimo-prompt-hf-cdn-redirect
Nov 9, 2026
Merged

davidtai merged 2 commits into
devfrom
ci/mimo-prompt-hf-cdn-redirect

Conversation

@davidtai

@davidtai davidtai commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

scripts/prepare-mimo-prompt-fixtures.py now follows a redirect only in two cases (David's ruling, 2026-11-09):

  • The target has the origin (scheme, host and port) of the URL that answered with the redirect.
  • https://huggingface.co redirects over HTTPS to a Hugging Face CDN host on port 443: hf.co, or a name that ends in .hf.co.

A target with credentials is always refused. Any other redirect (another host, another port, plain HTTP) raises ValueError before its target is requested, and it is not retried. The SHA-256 pins still protect the bytes.

Before this PR, the script let urlopen follow any redirect and then refused only a final plain-HTTP URL. So it could request another host, or a plain-HTTP URL, before the check ran.

Why the CDN allowance, and how narrow it is

On 2026-11-08 I checked what the Hub answers for the four pinned files at revision 5711b268…:

File Hub answer
tokenizer.json 302 to https://us.aws.cdn.hf.co/xet-bridge-us/…?Expires=…&Signature=…, which answers 200 with the pinned SHA-256 ff15eb92…
config.json, tokenizer_config.json, chat_template.jinja 307 to /api/resolve-cache/… on huggingface.co (same origin)

A strict same-origin rule would therefore refuse tokenizer.json on every cache miss. Hugging Face serves Xet and LFS files from names under hf.co, for example us.aws.cdn.hf.co, cas-bridge.xethub.hf.co and cdn-lfs*.hf.co. The allowance is therefore:

  • only for a redirect whose source origin is exactly https://huggingface.co:443;
  • only to https, port 443, with no credentials;
  • only to the host hf.co or a name that ends in .hf.co. The check is an exact name or a dot-separated suffix, so hf.co.evil.example and evilhf.co do not match;
  • for one hop only. A CDN host cannot redirect onward to another host, not even to another *.hf.co host.

The legacy cdn-lfs.huggingface.co is not allowed. These files do not use it.

Shared rule, no third copy

The rule is in the new scripts/fixture_redirects.py (origin, redirect_allowed, and the urllib handler OriginRedirect). All three downloaders now use it:

  • prepare-mimo-prompt-fixtures.py: opens through OriginRedirect(hugging_face_cdn=True).
  • prepare-mimo-image-http-fixtures.py (Keep MiMo image fixture redirects on the requested origin #1865): its curl loop calls redirect_allowed instead of its own origin() copy. It is still same-origin only.
  • prepare-prompt-fixtures.py: SameOriginRedirect now extends OriginRedirect and still refuses a target with a query or fragment (https_url). The final-response check uses the same origin(). Before, it compared (scheme, netloc), so a same-origin hop with an explicit :443 would have been followed and then refused.

The CI component paths (scripts/ci-component-paths.py and its test), the release-cache workflow paths and the docs-impact rules name the new module.

Before and after

No Mermaid, at the requester's instruction. Text diagrams:

Before:

huggingface.co/resolve/... --302--> any host, any scheme (requested at once)
                                   -> after the body is read: refuse only if the final URL is http

After:

huggingface.co/resolve/... --307--> huggingface.co/api/resolve-cache/...  followed (same origin)
huggingface.co/resolve/... --302--> https://*.hf.co:443/...               followed (Hub -> CDN only)
any URL                   --3xx--> anything else                          ValueError, target never requested, no retry

Validation

  • Self-tests (scripts/test-prepare-mimo-prompt-fixtures.py) drive the script's own redirect handler through urllib, with a fake origin that records every request:
    • Followed: a same-origin redirect (with and without an explicit :443), and huggingface.co to us.aws.cdn.hf.co, cas-bridge.xethub.hf.co, cdn-lfs-us-1.hf.co and hf.co.
    • Refused at once, target never requested, no retry: http://us.aws.cdn.hf.co, http://huggingface.co, evil.example, huggingface.co:8443, us.aws.cdn.hf.co:8443, a credentialed CDN URL, hf.co.evil.example, evilhf.co and huggingface.co.hf.co.evil.example.
    • A CDN host that redirects onward (to evil.example or to cas-bridge.xethub.hf.co) is refused. The allowance does not apply from a source other than https://huggingface.co:443.
  • The existing image and prompt-asset self-tests still cover their redirect cases unchanged.
  • CI (dev) run 42558488831 on the head f42e459f is green. That covers Check the CI plans, both Provider Unit Tests shards, the Provider Tests gate and every cluster job. SDK 27 release preparation run 42558488912 is also green. In the offline downloader step, the self-tests passed: prompt-asset 18 tests, MiMo prompt 15 tests (3 of them new) and MiMo image 12 tests. The two Vercel deployments (d-inference and d-inference-console-ui-dev) failed, as they do on every PR.
  • Nothing was built or tested on the laptop.

Components touched

  • provider-swift (Swift CLI)
  • native runtime / MLX
  • landing (Next.js)
  • enclave (Swift)
  • CI / provider release: fixture download scripts and their CI path lists
  • docs

Protocol / interface changes

  • No protocol/interface changes

Documentation impact

  • Canonical documentation updated: docs/developer/test.md (Public Fixtures And Private Qualification) and docs/developer/mimo-prompt-fixtures.md.

Changelog

  • Added changelog.d/mimo-prompt-fixture-redirects.md.

Refactor Pass

A separate refactor reviewer read the diff and checked it against the urllib source. It found no correctness bug. It confirmed:

  • A refused redirect's ValueError reaches the caller unwrapped, so it is not retried.
  • The fake origin handler answers before urllib's HTTPS handler.
  • Every test proves what it claims.

It made two cleanups, in f42e459f: redirect_allowed returns early outside the Hub hop (with the constant renamed to HUGGING_FACE_HUB_ORIGIN), and the test comments on why it copies the handler. It also pointed out that the final-response check in prepare-prompt-fixtures.py compared netlocs. That check now uses the shared origin(), in the same commit.

🤖 Generated with Claude Code

davidtai and others added 2 commits November 8, 2026 21:45
…t fixtures

prepare-mimo-prompt-fixtures.py let urllib follow any redirect and refused
only a final plain-HTTP URL, so a download could request another host, or a
plain-HTTP URL, before the check ran. It now opens each file through
OriginRedirect: a redirect is followed only when the target has the scheme,
host and port of the URL that answered with it and carries no credentials,
or, from https://huggingface.co only, when the target is an HTTPS Hugging
Face CDN host on port 443 (hf.co or a name that ends in .hf.co). The Hub
answers tokenizer.json at the pinned revision with a 302 to
us.aws.cdn.hf.co; the other three files take a same-origin 307. Any other
redirect raises ValueError before its target is requested and is not
retried. The SHA-256 pins still protect the bytes.

The rule lives in scripts/fixture_redirects.py. The image fixture script's
curl loop and prepare-prompt-fixtures.py's SameOriginRedirect now use it
instead of their own origin comparisons; the latter still refuses a target
with a query or fragment. The CI component paths, the release-cache
workflow paths and the docs-impact rules name the new module.

The self-test drives the script's own redirect handler through urllib with
a recording fake origin: same-origin and *.hf.co redirects are followed;
plain-HTTP, other-host, other-port, credentialed and suffix-trick targets
(hf.co.evil.example, evilhf.co) fail at once, unrequested and unretried;
a CDN host cannot redirect onward.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-asset origins the same way

The refactor reviewer's cleanups: redirect_allowed returns early when the
CDN allowance is off or the source is not the Hub, and the constant is
named HUGGING_FACE_HUB_ORIGIN; the test says why it copies the handler.

prepare-prompt-fixtures.py compared the final response with
(scheme, netloc) while each hop now compares (scheme, host, port with its
default). It now uses fixture_redirects.origin for both, so a same-origin
hop with an explicit :443 is not refused afterwards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference Error Error Nov 9, 2026 3:50am UTC
d-inference-console-ui-dev Error Error Nov 9, 2026 3:50am UTC
d-inference-landing Ready Ready Preview Nov 9, 2026 3:50am UTC
darkbloom-status Ready Ready Preview Nov 9, 2026 3:50am UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 9, 2026 3:50am UTC

Request Review

This branch had an error being deployed

2 failed and 3 active deployments
Preview – eigen-homepages-darkbloom — f42e459f Deployed Nov 9, 2026 by vercel[bot]
Preview – d-inference-landing — f42e459f Deployed Nov 9, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — f42e459f Deployed Nov 9, 2026 by vercel[bot]
Preview – darkbloom-status — f42e459f Deployed Nov 9, 2026 by vercel[bot]
Preview – d-inference — f42e459f Deployed Nov 9, 2026 by vercel[bot]
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