Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.
Python cliconsumer-gpudpofine-tuningggufhuggingfacellmllmopslocal-ailocal-llmloralow-vrammachine-learningollamapeftpythonpytorchqlorasfttransformers
fix(ui): open and print a login URL that carries the auth token (#1194) (#1307)
Faisal Fayaz6b35bbbc729d
diff --git a/README.ar.md b/README.ar.mdindex 8c11c429..79b5df5e 100644--- a/README.ar.md+++ b/README.ar.md@@ -1,4 +1,4 @@-<!-- synced-from: README.md sha256:4dfed787f12e9d2a94ba6cf97d76b25aa4151095125c9eae65628bfe63e86d0f -->+<!-- synced-from: README.md sha256:2c81448b707086960939bd1512e493ea4a0248aac5d073ad388f6260c1352537 --><p align="center">🌍 <a href="README.md">English</a> | <a href="README.tr.md">Türkçe</a> | <strong>العربية</strong> | <a href="README.ja.md">日本語</a></p><p align="center">@@ -207,7 +207,7 @@ soup export --model ./output --format gguf --quant q4_k_m # GGUF لـ Ollama /```bashpip install "soup-cli[ui]"soup ui-# يفتح http://127.0.0.1:7860+# يفتح http://127.0.0.1:7860/?token=<token>```diff --git a/README.ja.md b/README.ja.mdindex 61a39faf..4225ddfc 100644--- a/README.ja.md+++ b/README.ja.md@@ -1,4 +1,4 @@-<!-- synced-from: README.md sha256:4dfed787f12e9d2a94ba6cf97d76b25aa4151095125c9eae65628bfe63e86d0f -->+<!-- synced-from: README.md sha256:2c81448b707086960939bd1512e493ea4a0248aac5d073ad388f6260c1352537 --><p align="center">🌍 <a href="README.md">English</a> | <a href="README.tr.md">Türkçe</a> | <a href="README.ar.md">العربية</a> | <strong>日本語</strong></p><p align="center">@@ -209,7 +209,7 @@ soup export --model ./output --format gguf --quant q4_k_m # Ollama / llama.cpp```bashpip install "soup-cli[ui]"soup ui-# http://127.0.0.1:7860 を開きます+# http://127.0.0.1:7860/?token=<token> を開きます```diff --git a/README.md b/README.mdindex 19e79ad5..d4647ba7 100644--- a/README.md+++ b/README.md@@ -212,7 +212,7 @@ training setup, live metrics, dataset exploration and model chat.```bashpip install "soup-cli[ui]"soup ui-# Opens http://127.0.0.1:7860+# Opens http://127.0.0.1:7860/?token=<token> and prints the same URL```diff --git a/README.tr.md b/README.tr.mdindex 862c2c5a..11840ff0 100644--- a/README.tr.md+++ b/README.tr.md@@ -1,4 +1,4 @@-<!-- synced-from: README.md sha256:4dfed787f12e9d2a94ba6cf97d76b25aa4151095125c9eae65628bfe63e86d0f -->+<!-- synced-from: README.md sha256:2c81448b707086960939bd1512e493ea4a0248aac5d073ad388f6260c1352537 --><p align="center">🌍 <a href="README.md">English</a> | <strong>Türkçe</strong> | <a href="README.ar.md">العربية</a> | <a href="README.ja.md">日本語</a></p><p align="center">@@ -214,7 +214,7 @@ keşfi ve modelle sohbet için yerel bir pano sunar.```bashpip install "soup-cli[ui]"soup ui-# http://127.0.0.1:7860 adresini açar+# http://127.0.0.1:7860/?token=<token> adresini açar```diff --git a/changelog.d/0.75.1/1307.fixed.md b/changelog.d/0.75.1/1307.fixed.mdnew file mode 100644index 00000000..6651c93c--- /dev/null+++ b/changelog.d/0.75.1/1307.fixed.md@@ -0,0 +1 @@+- **`soup ui` opens and prints a login URL that already carries the auth token (#1194 by @Faisal-Fayaz in #1307).** The first browser tab was `http://host:port` with no `?token=`, so every `/api/*` route except `/api/health` returned 401 and the dashboard rendered `Unauthorized`. The startup panel and `webbrowser.open` now use `http://host:port/?token=<token>`, including under `--no-browser`. `app.js` already reads that query parameter, and on a loopback bind the server exchanges it for an HttpOnly session cookie (#1191).diff --git a/docs/serving-and-export.md b/docs/serving-and-export.mdindex 2158a053..ad4ca25d 100644--- a/docs/serving-and-export.md+++ b/docs/serving-and-export.md@@ -636,10 +636,16 @@ Launch a local web interface to manage experiments, start training, explore data```bashpip install "soup-cli[ui]"soup ui-# -> opens http://127.0.0.1:7860 in your browser-# -> prints auth token to console+# -> opens http://127.0.0.1:7860/?token=<token> in your browser+# -> prints the same URL and the token in the startup panel (also with --no-browser)```+The URL `soup ui` opens and prints already carries the token, so the first tab+authenticates on its own. On a loopback bind the server swaps that token for an+HttpOnly session cookie and redirects, as described below, so the address bar+ends up clean and a reload or a new tab stays signed in. Your browser's history+still records the URL it was given.+> **v0.75.0 and v0.75.1: add the token to the URL yourself.** In these two> releases the tab `soup ui` opens carries no token, so it shows> `Error loading dashboard: Unauthorized` and no page can load data (#1194).@@ -650,7 +656,7 @@ soup ui> another browser needs the URL again, and the token changes every time> `soup ui` starts unless you pass `--auth-token`. Releases with the session> cookie keep a new tab signed in as well; see "Session cookie on a loopback-> bind" below.+> bind" below. Later versions open and print that URL themselves.**Pages:**- **Dashboard** — view all experiment runs, loss charts, system info, multi-run comparison@@ -672,7 +678,7 @@ terminal panel.**Security:** The Web UI generates a random auth token at startup (printed to console). Every private endpoint — mutating (start/stop training, delete runs, inspect data, validate config) and reading (runs, metrics, system, recipes, SSE streams) — requires an `Authorization: Bearer <token>` header. `/` and `/api/health` stay open so the dashboard can load. CORS is restricted to the served origin. Data inspection is sandboxed to the working directory.-**The page never stores the token.** The page reads the token from `?token=…` (the `--public` phone URL) or asks for it the first time a request is refused, then holds it in page memory only: never `sessionStorage`, `localStorage`, a cookie or a `window` property. Without the session cookie below, a reload or a new tab therefore asks for it again; paste the token `soup ui` printed (the whole `Authorization: Bearer …` line works too). If you cancel the prompt, the page stays signed out until your next click, which asks again. That is deliberate: a token persisted where page script can read it would turn a future rendering mistake into a token disclosure. It does not protect against script already running in the page; the content policy below is the defence there.+**The page never stores the token.** The page reads the token from `?token=…` — the URL `soup ui` opens and prints, and the `--public` phone URL — whenever a non-loopback bind leaves that parameter in the URL; on a loopback bind the cookie below has already consumed it. Otherwise it asks for the token the first time a request is refused, then holds it in page memory only: never `sessionStorage`, `localStorage`, a cookie or a `window` property. Without the session cookie below, a reload or a new tab therefore asks for it again; paste the token `soup ui` printed (the whole `Authorization: Bearer …` line works too). If you cancel the prompt, the page stays signed out until your next click, which asks again. That is deliberate: a token persisted where page script can read it would turn a future rendering mistake into a token disclosure. It does not protect against script already running in the page; the content policy below is the defence there.**Session cookie on a loopback bind (#1191).** Opening `http://127.0.0.1:<PORT>/?token=<TOKEN>` checks the token, sets an `HttpOnly; SameSite=Strict; Path=/` cookie named `soup_ui_session_<PORT>` and redirects to the same URL without `token`. The cookie holds a random session id, never the token, so page script cannot read a credential, and a reload or a new tab in that browser stays signed in. The cookie belongs to the hostname you opened: signing in at `127.0.0.1` does not sign in `localhost`, so keep using the same one. It has no expiry, so it ends when the browser session does, and the server keeps the ids only in memory, so every `soup ui` restart ends every session; open the `?token=` URL again to sign back in. A request authenticated by the cookie that is not a `GET` or `HEAD` must carry an `Origin` naming this exact server (scheme, host and port) or it is refused with 403: every port of `127.0.0.1` counts as one site, so `SameSite=Strict` alone would let a page served by another local app on a different port use the cookie. The `Authorization: Bearer` header works exactly as before and needs no `Origin`, so scripts and API clients are unchanged. A wrong token sets nothing and loads the page as before. A browser that blocks cookies for `127.0.0.1` gets the token prompt after the redirect, because the token has already left the URL; paste the token there. With `--public` (or any non-loopback `--host`) no cookie is set or accepted: the phone page keeps the token in page memory, and a reload asks for it again or you re-scan the QR code. **What this does not cover:** cookies are not isolated by port, so any other server on `127.0.0.1` that your browser sends a same-site request to also receives the session cookie. Such a server can replay it outside a browser with any `Origin`, since the `Origin` check only stops browsers, and act as you in the UI, including starting training, until `soup ui` restarts.diff --git a/src/soup_cli/commands/ui.py b/src/soup_cli/commands/ui.pyindex 8c7b0674..d58a0a74 100644--- a/src/soup_cli/commands/ui.py+++ b/src/soup_cli/commands/ui.py@@ -67,6 +67,7 @@ def ui("""Launch the Soup Web UI.A Bearer auth token is auto-generated at startup and printed to the console.+ The launch URL includes `?token=` so the first browser tab authenticates.API endpoints require 'Authorization: Bearer <token>'.`--public` exposes the server on 0.0.0.0 for phone-on-LAN access. The@@ -128,9 +129,10 @@ def ui(app = create_app(host=host, port=port)url = f"http://{host}:{port}"+ login_url = f"{url}/?token={token}"panel_body = (- f"URL: [bold]{url}[/]\n"+ f"URL: [bold]{login_url}[/]\n"f"Token: [bold]{token}[/]\n\n"f"API endpoints require:\n"f" [dim]Authorization: Bearer {token}[/]\n\n"@@ -203,7 +205,7 @@ def ui(import timetime.sleep(1)- webbrowser.open(url)+ webbrowser.open(login_url)threading.Thread(target=_open, daemon=True).start()diff --git a/tests/test_issue1194_ui_login_url.py b/tests/test_issue1194_ui_login_url.pynew file mode 100644index 00000000..698fcbff--- /dev/null+++ b/tests/test_issue1194_ui_login_url.py@@ -0,0 +1,71 @@+"""Tests for Issue #1194: soup ui must hand the auth token to the browser.++The tab ``soup ui`` opens used to be ``http://host:port`` with no ``?token=``, so+the first paint was Unauthorized. The launch URL and the printed URL now+carry the token. ``app.js`` already reads ``?token=`` and strips it.+"""++from __future__ import annotations++import re+from unittest.mock import MagicMock, patch++import pytest+from typer.testing import CliRunner++from tests.conftest import strip_ansi++pytest.importorskip("fastapi")+pytest.importorskip("uvicorn")++from soup_cli.cli import app # noqa: E402++_TOKEN = "abcdefghijklmnopqrstuvwx"+_LOGIN = f"http://127.0.0.1:7860/?token={_TOKEN}"+++def _collapse(text: str) -> str:+ return re.sub(r"\s+", " ", strip_ansi(text))+++def _immediate_thread(target=None, daemon=None, **kwargs):+ thread = MagicMock()+ thread.start.side_effect = lambda: target() if target else None+ return thread+++def _run_ui(*extra: str) -> tuple[object, list[str]]:+ """Invoke ``soup ui`` with the browser thread run inline, so any open() is recorded."""+ opened: list[str] = []++ def _open(url, *args, **kwargs):+ opened.append(url)+ return True++ with (+ patch("uvicorn.run"),+ patch("webbrowser.open", side_effect=_open),+ patch("threading.Thread", side_effect=_immediate_thread),+ patch("time.sleep"),+ ):+ result = CliRunner().invoke(+ app,+ ["ui", "--host", "127.0.0.1", "--port", "7860", "--auth-token", _TOKEN, *extra],+ )+ return result, opened+++class TestUiLoginUrl:+ def test_ui_opens_login_url_with_token(self):+ result, opened = _run_ui()++ assert result.exit_code == 0, (result.output, repr(result.exception))+ assert _LOGIN in _collapse(result.output)+ assert opened == [_LOGIN]++ def test_no_browser_prints_login_url_and_does_not_open(self):+ result, opened = _run_ui("--no-browser")++ assert result.exit_code == 0, (result.output, repr(result.exception))+ assert _LOGIN in _collapse(result.output)+ assert opened == []