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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: account management needs a UI session (#14872)
Daniel Hanc764e13852ca
diff --git a/studio/backend/routes/accounts.py b/studio/backend/routes/accounts.pyindex 7f47f1da53a..ecf14966657 100644--- a/studio/backend/routes/accounts.py+++ b/studio/backend/routes/accounts.py@@ -11,7 +11,7 @@ from pathlib import Pathfrom fastapi import APIRouter, Depends, HTTPException, Response, statusfrom auth import policy, storage-from auth.authentication import get_current_subject+from auth.authentication import authenticated_via_api_key, get_current_subjectfrom models.auth import (AccountActiveRequest,AccountListResponse,@@ -26,7 +26,19 @@ from utils.account_context import AccountContext, run_asfrom utils.paths import storage_roots-router = APIRouter(dependencies = [Depends(get_current_subject), Depends(policy.require_owner)])+def _require_ui_session(via_api_key: bool = Depends(authenticated_via_api_key)) -> None:+ # A setup code signs in as the account, so an API key or keyless caller must not mint one.+ if via_api_key:+ raise HTTPException(status_code = 403, detail = "Account management requires a UI session.")+++router = APIRouter(+ dependencies = [+ Depends(get_current_subject),+ Depends(policy.require_owner),+ Depends(_require_ui_session),+ ]+)@contextmanagerdiff --git a/studio/backend/tests/test_account_lifecycle.py b/studio/backend/tests/test_account_lifecycle.pyindex 4a43eaf7a12..82e5860d14a 100644--- a/studio/backend/tests/test_account_lifecycle.py+++ b/studio/backend/tests/test_account_lifecycle.py@@ -900,3 +900,36 @@ def test_a_database_failure_after_retirement_puts_the_roots_back(matrix, monkeypassert (client.delete(f"/api/accounts/{account.account_id}", headers = headers()).status_code == 204)+++def test_api_keys_cannot_manage_accounts(auth_env):+ # A setup code signs in as the account, so a leaked owner API key must not mint one.+ client, _auth, _accounts = auth_env+ account = create(client).json()["account"]+ raw, _row = storage.create_api_key("unsloth", "script")+ key = {"Authorization": "Bearer " + raw}+ url = f"/api/accounts/{account['account_id']}"+ for response in (+ client.get("/api/accounts", headers = key),+ client.post("/api/accounts", headers = key, json = {"username": "mallory"}),+ client.post(url + "/setup-code", headers = key),+ client.patch(url, headers = key, json = {"is_active": False}),+ client.delete(url, headers = key),+ ):+ assert response.status_code == 403+ assert response.json()["detail"] == "Account management requires a UI session."+ assert client.get("/api/accounts", headers = headers()).status_code == 200+ assert client.post(url + "/setup-code", headers = headers()).status_code == 200+++def test_keyless_callers_cannot_manage_accounts(auth_env):+ import asyncio++ _client, _auth, accounts = auth_env+ keyless = authentication.HTTPAuthorizationCredentials(+ scheme = authentication.KEYLESS_SCHEME, credentials = ""+ )+ via_api_key = asyncio.run(authentication.authenticated_via_api_key(keyless))+ with pytest.raises(accounts.HTTPException) as refused:+ accounts._require_ui_session(via_api_key)+ assert refused.value.status_code == 403