web: allow direct IP dashboard and worker access
agent-review agent review: pass

Remove fixed-host and HTTPS-only deployment requirements so the dashboard
works at the container IP on HTTP port 5187. Validate browser mutations
against the actual request host and retain access keys and CSRF protection.
Ignore legacy public-origin settings and make Proxmox setup hostname-free.
Update D14 and regression coverage for version 1.2.3.

Refs #25
This commit is contained in:
Florian Schmidt
2026-11-15 16:38:19 +01:00
parent f45e065994
commit 480b73d899
19 changed files with 218 additions and 69 deletions
+63 -4
View File
@@ -3,6 +3,7 @@ import argparse
import datetime as dt
import getpass
import http.cookiejar
from http.cookies import SimpleCookie
import json
import os
from pathlib import Path
@@ -15,6 +16,7 @@ import time
import unittest
import urllib.error
import urllib.request
from urllib.parse import urlsplit
ROOT = Path(__file__).resolve().parents[1]
KEY = "synthetic-dashboard-key-for-local-tests-only-123456"
@@ -32,7 +34,7 @@ def wait_for(check, timeout=30):
class Fixture:
def __init__(self, port=None):
def __init__(self, port=None, public_origin=None, start_worker=True):
self.temp = tempfile.TemporaryDirectory(prefix="finaltoken-web-test-")
self.path = Path(self.temp.name)
self.processes = []
@@ -41,6 +43,7 @@ class Fixture:
sock.bind(("127.0.0.1", 0))
port = sock.getsockname()[1]
self.url = f"http://127.0.0.1:{port}"
self.ready_host = urlsplit(public_origin or self.url).netloc
self.jar = http.cookiejar.CookieJar()
self.browser = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(self.jar))
self.csrf = None
@@ -78,7 +81,7 @@ class Fixture:
(sessions / "rollout-fixture.jsonl").write_text("\n".join(map(json.dumps, rows)) + "\n", encoding="utf-8")
env = os.environ.copy()
env.update(FINALTOKEN_SERVER_CONFIG=str(self.path / "server.json"), FINALTOKEN_SERVER_DATA=str(self.path / "server-data"),
FINALTOKEN_DASHBOARD_KEY=KEY, FINALTOKEN_MACHINE_a=WORKER_KEY, FINALTOKEN_PUBLIC_ORIGIN=self.url, ASPNETCORE_URLS=self.url)
FINALTOKEN_DASHBOARD_KEY=KEY, FINALTOKEN_MACHINE_a=WORKER_KEY, FINALTOKEN_PUBLIC_ORIGIN=public_origin or self.url, ASPNETCORE_URLS=self.url)
self.spawn(["dotnet", str(self.path / "FinalToken.Web/FinalToken.Web.dll")], env, ROOT / "src/FinalToken.Web")
wait_for(self.ready)
worker_env = os.environ.copy()
@@ -86,7 +89,8 @@ class Fixture:
worker_env.pop("CLAUDE_CONFIG_DIR", None)
worker_env.pop("CODEX_HOME", None)
worker_env["FINALTOKEN_WORKER_KEY"] = WORKER_KEY
self.spawn(["dotnet", str(self.path / "FinalToken.Worker/finaltoken-worker.dll"), str(self.path / "worker.json")], worker_env, ROOT)
if start_worker:
self.spawn(["dotnet", str(self.path / "FinalToken.Worker/finaltoken-worker.dll"), str(self.path / "worker.json")], worker_env, ROOT)
@staticmethod
def json(path, value):
@@ -99,7 +103,7 @@ class Fixture:
def ready(self):
try:
return urllib.request.urlopen(self.url, timeout=1).status == 200
return urllib.request.urlopen(urllib.request.Request(self.url, headers={"Host": self.ready_host}), timeout=1).status == 200
except (OSError, urllib.error.URLError):
return False
@@ -147,6 +151,61 @@ class Fixture:
self.temp.cleanup()
class IPAccessIntegration(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.fixture = Fixture(public_origin="https://usage.example.com", start_worker=False)
@classmethod
def tearDownClass(cls):
cls.fixture.close()
def request(self, path, body=None, origin=None, cookie=None, csrf=None):
f = self.fixture
authority = "10.0.30.150:" + str(urlsplit(f.url).port)
headers = {"Host": authority, "X-FinalToken": "1", "Content-Type": "application/json"}
if origin:
headers["Origin"] = origin
if cookie:
headers["Cookie"] = cookie
if csrf:
headers["X-CSRF"] = csrf
request = urllib.request.Request(f.url + path, headers=headers,
data=None if body is None else json.dumps(body).encode())
return urllib.request.urlopen(request, timeout=10)
def test_ip_page_and_http_login_ignore_the_legacy_fixed_hostname(self):
with self.request("/") as response:
self.assertEqual(200, response.status)
authority = "10.0.30.150:" + str(urlsplit(self.fixture.url).port)
with self.request("/session", {"key": KEY}, origin="http://" + authority) as response:
cookies = SimpleCookie(response.headers["Set-Cookie"])
csrf = json.load(response)["csrf"]
self.assertFalse(cookies["finaltoken"]["secure"])
self.assertTrue(cookies["finaltoken"]["httponly"])
self.assertEqual("strict", cookies["finaltoken"]["samesite"].lower())
cookie = "finaltoken=" + cookies["finaltoken"].value
with self.request("/api/dashboard", cookie=cookie) as response:
self.assertEqual(200, response.status)
with self.assertRaises(urllib.error.HTTPError) as error:
self.request("/api/dashboard")
self.assertEqual(401, error.exception.code)
with self.assertRaises(urllib.error.HTTPError) as error:
self.request("/api/logout", {}, origin="http://" + authority, cookie=cookie, csrf="wrong")
self.assertEqual(403, error.exception.code)
with self.assertRaises(urllib.error.HTTPError) as error:
self.request("/api/logout", {}, origin="http://evil.test", cookie=cookie, csrf=csrf)
self.assertEqual(403, error.exception.code)
with self.request("/api/logout", {}, origin="http://" + authority, cookie=cookie, csrf=csrf) as response:
self.assertEqual(204, response.status)
def test_https_browser_origin_retains_secure_cookie_behind_a_proxy(self):
authority = "10.0.30.150:" + str(urlsplit(self.fixture.url).port)
with self.request("/session", {"key": KEY}, origin="https://" + authority) as response:
cookie = SimpleCookie(response.headers["Set-Cookie"])
self.assertTrue(cookie["finaltoken"]["secure"])
class WebIntegration(unittest.TestCase):
@classmethod
def setUpClass(cls):