Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: managed accounts use the server's own HF endpoint for recipe seeds (#14187)

Daniel Hane42df82c897e
diff --git a/studio/backend/routes/data_recipe/jobs.py b/studio/backend/routes/data_recipe/jobs.py
index 35da05c462d..7518d0c16ab 100644
--- a/studio/backend/routes/data_recipe/jobs.py
+++ b/studio/backend/routes/data_recipe/jobs.py
@@ -12,7 +12,7 @@ from utils.account_context import (
current_account,
reset_account,
)
-from core.training.account_jobs import account_event_stream
+from core.training.account_jobs import account_event_stream, managed_account
import copy
import hashlib
import hmac
@@ -527,7 +527,10 @@ def _resolve_seed_endpoint(recipe: dict[str, Any]) -> None:
HF_ENDPOINT resolved here, which matters for a remote browser: /api/health
reports the public default to it for a loopback mirror, and shipping that
back would bypass the mirror on the deployments that need it most. An
- endpoint the user typed into the seed node is left alone.
+ endpoint the user typed into the seed node is left alone, except that a managed
+ account may only use this server's own endpoint: the fetch runs in this process,
+ outside the recipe worker's egress guard, and follows redirects, so checking the
+ typed address alone would not keep it off loopback, LAN or metadata services.
"""
seed_config = recipe.get("seed_config")
if not isinstance(seed_config, dict):
@@ -535,8 +538,14 @@ def _resolve_seed_endpoint(recipe: dict[str, Any]) -> None:
source = seed_config.get("source")
if not isinstance(source, dict) or source.get("seed_type") != "hf":
return
- if not str(source.get("endpoint") or "").strip():
+ typed = str(source.get("endpoint") or "").strip()
+ if not typed:
source["endpoint"] = get_hf_endpoint()
+ elif typed.rstrip("/") != get_hf_endpoint().rstrip("/") and managed_account():
+ raise HTTPException(
+ status_code = 403,
+ detail = "Managed accounts use this server's Hugging Face endpoint; leave the seed endpoint blank.",
+ )
@router.post("/jobs", response_class = JSONResponse, response_model = JobCreateResponse)
diff --git a/studio/backend/tests/test_managed_provider_url_policy.py b/studio/backend/tests/test_managed_provider_url_policy.py
index 21e8448263d..5aebcbf2a78 100644
--- a/studio/backend/tests/test_managed_provider_url_policy.py
+++ b/studio/backend/tests/test_managed_provider_url_policy.py
@@ -290,3 +290,43 @@ def test_a_link_local_provider_that_saves_can_also_be_dialled(monkeypatch, as_al
for literal in ("http://169.254.169.254/v1", "http://169.254.3.7/v1"):
with pytest.raises(ValueError):
provider_address_excluding_metadata(literal)
+
+
+def _hf_seed(endpoint):
+ return {"seed_config": {"source": {"seed_type": "hf", "path": "a/b", "endpoint": endpoint}}}
+
+
[email protected]("allowed", [False, True])
[email protected]("url", PRIVATE_URLS + METADATA_URLS + ["https://hub.example.com"])
+def test_a_managed_hf_seed_endpoint_must_be_this_servers(monkeypatch, as_alice, url, allowed):
+ # Validate reads the seed in the API process, outside the recipe worker's egress guard, and the
+ # HF client follows redirects, so even a public HTTPS endpoint could bounce to an internal one.
+ from routes.data_recipe.jobs import _resolve_seed_endpoint
+
+ _allow(monkeypatch, allowed)
+ with pytest.raises(Exception) as refusal:
+ _resolve_seed_endpoint(_hf_seed(url))
+ assert getattr(refusal.value, "status_code", None) == 403
+
+
+def test_hf_seed_endpoints_that_stay_allowed(monkeypatch, as_alice):
+ from routes.data_recipe.jobs import _resolve_seed_endpoint
+
+ _allow(monkeypatch, False)
+ monkeypatch.setenv("HF_ENDPOINT", "http://127.0.0.1:9700")
+ # Blank resolves to this server's own endpoint, and naming that endpoint is the same thing.
+ for typed in (None, "", "http://127.0.0.1:9700", "http://127.0.0.1:9700/"):
+ recipe = _hf_seed(typed)
+ _resolve_seed_endpoint(recipe)
+ assert recipe["seed_config"]["source"]["endpoint"] in (
+ "http://127.0.0.1:9700",
+ "http://127.0.0.1:9700/",
+ )
+ # The owner may name any endpoint, a private mirror included.
+ token = bind_account(OWNER)
+ try:
+ recipe = _hf_seed("http://192.168.1.50:8080")
+ _resolve_seed_endpoint(recipe)
+ assert recipe["seed_config"]["source"]["endpoint"] == "http://192.168.1.50:8080"
+ finally:
+ reset_account(token)