mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
feat: offer ALLOWED_SERVERS as a dropdown or locked address field
With ALLOWED_SERVERS set, the gateway now passes the list to the web client it serves, and the connect dialog shows a dropdown of those servers instead of a free-text address, or a locked field when only one is allowed. SERVER_PICKER=0 keeps the plain text field; lists with *. wildcards can't be enumerated and keep it too. Entries may now carry a port, which is the address offered in the dialog (the allowlist still ignores ports). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
1 parent
ef0e3fad7d
commit
45e4af026f
3 files changed
+36
-7
No files matched your search
@@ -201,7 +201,8 @@ All optional; add them under `environment:` in your compose override next to `PO
|
||||
| `STORE_DATA_FILE` | `store-themes.json` in the container's working dir | Where submitted themes (including screenshots) are stored. Mount a volume over this path if they should survive a container recreate. |
|
||||
| `STORE_ALLOWED_ORIGIN` | `*` | CORS origin allowed to call the store endpoint, if you want to restrict it to your own frontend's origin. |
|
||||
| `STORE_ADMIN_TOKEN` | unset | Bearer token for moderation. New submissions wait as "pending" until approved on the review page at `/api/store/admin` (enter the token there); the token holder's own submissions and the reserved author name(s) skip the queue. Without it, nothing ever gets published. Submitted CSS is also checked server-side: no `@import`/`@font-face`, no external `url()` — only inline `data:` images. |
|
||||
| `ALLOWED_SERVERS` | unset (any server) | Comma-separated list of server addresses this gateway is allowed to connect to (e.g. `ts.example.com,*.example.net`). A port is matched separately from the host, so listing `ts.example.com` allows any port on it. An entry starting with `*.` matches any subdomain (`*.example.com` allows `ts.example.com`, not `example.com` itself - list that separately too if it should also be reachable). Locks a self-hosted instance down to specific server(s) instead of acting as a general "connect anywhere" client; a rejected `connect` gets an error back before any connector process is even spawned. |
|
||||
| `ALLOWED_SERVERS` | unset (any server) | Comma-separated list of server addresses this gateway is allowed to connect to (e.g. `ts.example.com,*.example.net`). A port is matched separately from the host, so listing `ts.example.com` allows any port on it. An entry starting with `*.` matches any subdomain (`*.example.com` allows `ts.example.com`, not `example.com` itself - list that separately too if it should also be reachable). Locks a self-hosted instance down to specific server(s) instead of acting as a general "connect anywhere" client; a rejected `connect` gets an error back before any connector process is even spawned. An entry may carry a port (`ts.example.com:9988`): it still allows every port, but that's the address the connect dialog offers (see `SERVER_PICKER`). |
|
||||
| `SERVER_PICKER` | on | With `ALLOWED_SERVERS` set (and no `*.` entries in it), the connect dialog's address field becomes a dropdown of those servers, or a locked field if there's only one. Set to `0` for the plain text field instead. Only works when the gateway serves the web client itself (the Docker image does). |
|
||||
| `ALLOW_PRIVATE_TARGETS` | off | By default the gateway refuses to connect to private/internal addresses (loopback, `10.x`, `192.168.x`, CGNAT, link-local, …), no matter how they were reached (IP, DNS, SRV, TSDNS, nickname, file-transfer redirect), so it can't be abused to probe the network it runs in. **If your TeamSpeak server is on the same LAN as the gateway, set this to `1`.** |
|
||||
| `TURN_URLS` | unset | Comma-separated TURN URLs (e.g. `turn:turn.example.com:3478`) offered to browsers for screen streams, for viewers or publishers behind NATs where direct P2P fails. Pair with `TURN_SECRET` (coturn's `use-auth-secret`; each browser gets its own credential valid for 24 h) or with static `TURN_USERNAME` / `TURN_CREDENTIAL`, which every visitor can read. |
|
||||
| `ALLOWED_ORIGINS` | unset (any origin) | Comma-separated list of web origins allowed to open `/ws` (e.g. `https://client.example.com`). Stops other websites from silently using your gateway as their relay. |
|
||||
|
||||
+10
-2
@@ -54,8 +54,8 @@ function isServerAllowed(host: unknown): boolean {
|
||||
return ALLOWED_SERVERS.some((entry) => {
|
||||
// "*.example.com" matches any subdomain (TLS-wildcard-style: not the
|
||||
// bare apex itself - list that separately if it should be allowed too).
|
||||
if (entry.startsWith("*.")) return target.endsWith(entry.slice(1));
|
||||
return target === entry;
|
||||
if (entry.startsWith("*.")) return target.endsWith(stripPort(entry).slice(1));
|
||||
return target === stripPort(entry);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -134,9 +134,17 @@ function turnServers() {
|
||||
// issue #12): set on the container, these end up in the served index.html as
|
||||
// <meta> tags the client reads at startup, so changing them needs no rebuild.
|
||||
// Meta tags rather than an inline script, which CONTENT_SECURITY_POLICY forbids.
|
||||
// The allowlist goes along so the client can offer it as a dropdown (or a
|
||||
// locked field for a single entry) instead of a free-text address; not with
|
||||
// wildcards, which can't be listed, nor with SERVER_PICKER=0.
|
||||
const SERVER_PICKER =
|
||||
process.env.SERVER_PICKER !== "0" && !ALLOWED_SERVERS.some((e) => e.startsWith("*."))
|
||||
? ALLOWED_SERVERS.join(",")
|
||||
: undefined;
|
||||
const RUNTIME_CONFIG_META = Object.entries({
|
||||
"webspeak3-default-server": process.env.DEFAULT_SERVER,
|
||||
"webspeak3-default-channel": process.env.DEFAULT_CHANNEL,
|
||||
"webspeak3-allowed-servers": SERVER_PICKER,
|
||||
})
|
||||
.flatMap(([name, value]) =>
|
||||
value ? [`<meta name="${name}" content="${value.replace(/[&"<>]/g, (c) => `&#${c.charCodeAt(0)};`)}">`] : [],
|
||||
|
||||
+24
-4
@@ -257,6 +257,9 @@ const runtimeConfig = (name: string) =>
|
||||
document.querySelector<HTMLMetaElement>(`meta[name="webspeak3-${name}"]`)?.content;
|
||||
const DEFAULT_SERVER = runtimeConfig("default-server") || import.meta.env.VITE_DEFAULT_SERVER || null;
|
||||
const DEFAULT_CHANNEL = runtimeConfig("default-channel") || import.meta.env.VITE_DEFAULT_CHANNEL || "";
|
||||
// The gateway admin's ALLOWED_SERVERS (unless SERVER_PICKER=0): one server
|
||||
// locks the address field to it, several turn it into a dropdown.
|
||||
const SERVER_CHOICES = runtimeConfig("allowed-servers")?.split(",").filter(Boolean) ?? [];
|
||||
|
||||
// Terms of use, own-hosted instance only (see TODO.md #2/#7.1). Versioned so
|
||||
// a rule change can re-surface the modal: bump TOS_VERSION and everyone who
|
||||
@@ -1656,7 +1659,20 @@ function ConnectDialog({
|
||||
<div className="ts-dialog-row">
|
||||
<label className="ts-dialog-field ts-dialog-field-grow">
|
||||
{t("connect.serverAddress")}
|
||||
<input autoFocus value={host} onChange={(e) => onHostChange(e.target.value)} />
|
||||
{SERVER_CHOICES.length > 1 ? (
|
||||
<select autoFocus value={host} onChange={(e) => onHostChange(e.target.value)}>
|
||||
{SERVER_CHOICES.map((s) => (
|
||||
<option key={s}>{s}</option>
|
||||
))}
|
||||
</select>
|
||||
) : (
|
||||
<input
|
||||
autoFocus
|
||||
value={host}
|
||||
disabled={SERVER_CHOICES.length === 1}
|
||||
onChange={(e) => onHostChange(e.target.value)}
|
||||
/>
|
||||
)}
|
||||
</label>
|
||||
<label className="ts-dialog-field">
|
||||
{t("connect.serverPassword")}
|
||||
@@ -7968,6 +7984,10 @@ function AppInner() {
|
||||
};
|
||||
};
|
||||
|
||||
// A remembered or favorite host outside the admin's list isn't one of the
|
||||
// choices; fall back to the first.
|
||||
const dialogHost = SERVER_CHOICES.length && !SERVER_CHOICES.includes(host) ? SERVER_CHOICES[0] : host;
|
||||
|
||||
const handleConnect = (overrides?: {
|
||||
host?: string;
|
||||
nickname?: string;
|
||||
@@ -10633,7 +10653,7 @@ function AppInner() {
|
||||
|
||||
{connectDialogOpen && (
|
||||
<ConnectDialog
|
||||
host={host}
|
||||
host={dialogHost}
|
||||
nickname={nickname}
|
||||
serverPassword={serverPassword}
|
||||
channelPassword={channelPassword}
|
||||
@@ -10653,8 +10673,8 @@ function AppInner() {
|
||||
onServerTypeChange={setServerType}
|
||||
onActiveIdentityChange={handleActiveIdentityChange}
|
||||
onToggleExpanded={() => setConnectDialogExpanded((v) => !v)}
|
||||
onConnect={() => handleConnect()}
|
||||
onConnectNewTab={() => handleConnect()}
|
||||
onConnect={() => handleConnect({ host: dialogHost })}
|
||||
onConnectNewTab={() => handleConnect({ host: dialogHost })}
|
||||
canOpenNewTab={sessionTabs.length > 0 || connected}
|
||||
onCancel={novaSplash ? () => {} : () => setConnectDialogOpen(false)}
|
||||
nova={designTheme === "nova"}
|
||||
|
||||
Reference in new issue
Block a user