Skip to content

[Sandbox] Require scoped credentials for pooled sandboxes - #4782

Merged
Wauplin merged 2 commits into
mainfrom
security/harden-pool-isolation
Sep 28, 2026
Merged

Wauplin merged 2 commits into
mainfrom
security/harden-pool-isolation

Conversation

@Wauplin

@Wauplin Wauplin commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Refuse pooled sandboxes with missing, empty or malformed capability tokens instead of substituting the host-management credential. A missing token-recovery route is now an error, not a legacy fallback.
  • Keep a concrete token on every Sandbox handle; proxy_headers never substitutes the host credential for a pooled sandbox. Dedicated sandboxes retain their job token.
  • Document the strict behavior and safe redirect settings when handing proxy_headers to an external HTTP client.

This replaces the original pre-audit implementation in this PR with a focused change on current main. Scoped credentials and internal redirect refusal already landed in #4832 and #4838; only the remaining compatibility fallback is removed here, as requested.

Breaking change: older pool hosts that do not provide scoped tokens must be upgraded/recycled. The currently published and pinned server 0.6.0 already provides them, so this PR needs no new binary pin. The companion server PR removes host-token acceptance on scoped routes entirely: huggingface/sandbox-server#29. Land this client first; release and pin that server afterward. No release is included here.

Validation: 162 sandbox tests passed; sandbox-module mypy passed. make style and make quality were run; formatting/lint/generated checks pass, with the same three unrelated local ty errors and one warning previously reproduced on main.

Manual malformed-token check:

SandboxError: The pool host returned no valid sandbox-scoped token; recycle it with an updated sbx-server.

Note

Medium Risk
This is a deliberate credential hardening break: pooled workloads on hosts without scoped tokens will fail until hosts are recycled, but dedicated sandboxes and correctly upgraded pools are unchanged.

Overview
Breaking change for pooled sandboxes: the client no longer substitutes the pool host-management credential when a per-sandbox capability token is missing, empty, or invalid. Shared Sandbox handles are constructed with _require_scoped_token, token recovery via sandbox_token() fails on 404 or empty JSON instead of falling back, and proxy_headers always sends the sandbox-scoped X-Sandbox-Token (never the host token).

Docs now state that users must upgrade/recycle older pool hosts, note redirect safety when using proxy_headers, and clarify that server 0.6.0 may still accept host tokens on scoped routes until compatibility is disabled or the server is upgraded.

Tests drop the legacy fallback case and add coverage for invalid tokens and non-fallback token recovery.

Reviewed by Cursor Bugbot for commit e34838e. Bugbot is set up for automated code reviews on this repo. Configure here.

@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit dce05c5. Configure here.

Comment thread src/huggingface_hub/_sandbox.py Resolved
@Wauplin
Wauplin marked this pull request as draft August 31, 2026 13:44
@Wauplin
Wauplin force-pushed the security/harden-pool-isolation branch from dce05c5 to f8505eb Compare September 14, 2026 13:04
@Wauplin Wauplin changed the title [Sandbox] Scope pooled sandbox credentials [Sandbox] Require scoped credentials for pooled sandboxes Sep 14, 2026
@Wauplin
Wauplin marked this pull request as ready for review September 28, 2026 14:32
@Wauplin
Wauplin merged commit f151320 into main Sep 28, 2026
17 of 25 checks passed
@Wauplin
Wauplin deleted the security/harden-pool-isolation branch September 28, 2026 14:55
@huggingface-hub-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v2.1.0 release.

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