Reach the UI by IP or Tailscale name, and join Tailscale from settings#153
Merged
Conversation
The UI resolves its backend from window.location, so it works when reached by hostname (orangepi5:5173 -> orangepi5:8000, an allowed origin). But the backend's allowed-origins list never included the machine's LAN IP, so loading the UI by IP (e.g. http://192.168.89.96:5173) was blocked by CORS. Replace the static allowlist with a dynamic predicate + regex shared by the FastAPI CORS middleware, the WebSocket guard, and the supervisor: accept loopback, all RFC1918 private ranges, link-local, the Tailscale CGNAT range (100.64/10), any *.local / *.ts.net, and this machine's own hostname/Tailscale name, all on the UI port. SORTER_API_ALLOWED_ORIGINS is now additive rather than exclusive. Bounded to private/local hosts — public origins never match. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…start UI 'add auth key' now passes --hostname=sorter-color-piece-mac (same scheme as firstboot), keeping an existing sorter-* name so a re-join doesn't spawn duplicate devices. Allow bare single-label origins on the UI port so the renamed Tailscale MagicDNS name is reachable immediately, with no backend restart. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… parsing Replace the broad range-matching origin regex (all RFC1918 / *.local / *.ts.net / CGNAT) with a simple allowlist of *this device's own* identities: localhost, OS hostname (+.local), current IP addresses (via `hostname -I`, so it tracks wifi/DHCP changes), and the Tailscale name. Refreshed on a short interval and invalidated immediately on a Tailscale join/logout so a UI-renamed machine is reachable at its new name without the stale-cache CORS failures. CORS now decides per-request via is_ui_origin_allowed (CORSMiddleware subclass) rather than a regex frozen at startup. Parse `tailscale status --json` Self.DNSName instead of positionally splitting `tailscale status --self` (which lists all peers on this version, so the old code grabbed the wrong token). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Make the Sorter UI just work however you connect to it, and make the Tailscale auth-key flow in settings actually usable end-to-end.
Two operator-facing goals:
localhost, the machine's hostname, its current LAN IP (http://192.168.x.y:5173),*.local, or its Tailscale name — without hitting CORS errors or having to edit per-machine config.sorter-dark-red-plate-0ffbef), and the UI keeps working at the new name immediately, with no restart and no manual steps.What was broken
*.local/*.ts.net/ the CGNAT range) — far broader than needed, and it captured the device name once at startup, so a Tailscale rename via the UI left the new name blocked until a backend restart.tailscale status --self, which on the deployed version lists all peers — so it frequently showed the wrong name./health, the WebSocket) intermittently failed CORS for a few seconds.What this does
localhost, OS hostname (+.local), its current IP addresses (viahostname -I, so it tracks wifi/DHCP changes), any*.local, and its Tailscale name. Decided per request (aCORSMiddlewaresubclass) instead of a regex frozen at startup.tailscale upnow passes--hostname=sorter-color-piece-mac(same scheme as firstboot), reusing an existingsorter-*name so a re-join doesn't spawn duplicates.Self.DNSNamefromtailscale status --jsoninstead of splitting peer-list text.Testing
tests/test_server_security.pyupdated for the device-scoped behavior; all green.localhost, current LAN IP, andsorter.local;8.8.8.8denied; Tailscale join from the UI generates a fresh name and the UI keeps working at it without a restart.🤖 Generated with Claude Code