mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 18:02:49 +08:00
Fix nickname-connect failures and add ALLOWED_SERVERS gateway allowlist
- Dockerfile: install ca-certificates in the runtime stage. Its absence broke the Rust connector's native-tls HTTPS call to the TeamSpeak nickname-lookup API for every nickname-based connection (GitHub issue #11, "mgonline" report) - Node's own bundled certs masked this everywhere else in the gateway, so only that one HTTPS call failed. - tsclientlib bump: resolver.rs now surfaces the real per-step errors instead of an empty list when every resolution method fails (see that submodule's own commit for detail). - gateway: new ALLOWED_SERVERS env var lets self-hosting admins lock their instance down to specific server(s) (with *.example.com wildcard support) instead of accepting connections to any address. Documented in the README env var table. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
1 parent
914afd19bd
commit
295af1781e
4 files changed
+46
-1
No files matched your search
@@ -57,6 +57,11 @@ FROM node:22-bookworm-slim AS runtime
|
|||||||
LABEL org.opencontainers.image.title="WebSpeak3"
|
LABEL org.opencontainers.image.title="WebSpeak3"
|
||||||
LABEL org.opencontainers.image.description="Self-hosted web client for TeamSpeak 3 servers"
|
LABEL org.opencontainers.image.description="Self-hosted web client for TeamSpeak 3 servers"
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
# ts-connector (Rust, native-tls) needs the OS CA bundle for its HTTPS calls
|
||||||
|
# (e.g. TeamSpeak nickname lookup) - Node bundles its own certs and works
|
||||||
|
# without this, but native-tls doesn't, so it's not optional here.
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
COPY gateway/package*.json ./
|
COPY gateway/package*.json ./
|
||||||
# npm/npx are only needed to install the gateway's runtime deps; the
|
# npm/npx are only needed to install the gateway's runtime deps; the
|
||||||
# container never runs either afterwards, so strip them (plus npm's own
|
# container never runs either afterwards, so strip them (plus npm's own
|
||||||
|
|||||||
@@ -197,6 +197,7 @@ 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_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_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 that lets its holder publish under the reserved author name(s) and moderate (delete) any theme. Without it, nobody can. |
|
| `STORE_ADMIN_TOKEN` | unset | Bearer token that lets its holder publish under the reserved author name(s) and moderate (delete) any theme. Without it, nobody can. |
|
||||||
|
| `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. |
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary><b>🛠️ Manual installation (without Docker)</b></summary>
|
<summary><b>🛠️ Manual installation (without Docker)</b></summary>
|
||||||
|
|||||||
@@ -25,6 +25,39 @@ function parsePrivilegeKey(msg: { privilegeKey?: unknown; token?: unknown }): st
|
|||||||
return trimmed || undefined;
|
return trimmed || undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Self-hosting admins may want to lock their instance to specific server(s)
|
||||||
|
// instead of leaving it as a general-purpose "connect anywhere" client.
|
||||||
|
// Unset (the default) means unrestricted, unchanged from before this existed.
|
||||||
|
const ALLOWED_SERVERS = (process.env.ALLOWED_SERVERS ?? "")
|
||||||
|
.split(",")
|
||||||
|
.map((s) => s.trim().toLowerCase())
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
// Strips a trailing ":port" so "ts.example.com:9987" and "ts.example.com"
|
||||||
|
// both match a plain "ts.example.com" allowlist entry. IPv6 literals come
|
||||||
|
// wrapped in brackets ("[::1]:9987"); nicknames have neither and pass through
|
||||||
|
// as-is. Deliberately not full URL parsing - `host` here is never a URL.
|
||||||
|
function stripPort(host: string): string {
|
||||||
|
if (host.startsWith("[")) {
|
||||||
|
const end = host.indexOf("]");
|
||||||
|
return end === -1 ? host : host.slice(1, end);
|
||||||
|
}
|
||||||
|
const i = host.lastIndexOf(":");
|
||||||
|
return i !== -1 && /^\d+$/.test(host.slice(i + 1)) ? host.slice(0, i) : host;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isServerAllowed(host: unknown): boolean {
|
||||||
|
if (ALLOWED_SERVERS.length === 0) return true;
|
||||||
|
if (typeof host !== "string") return false;
|
||||||
|
const target = stripPort(host).trim().toLowerCase();
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const PORT = Number(process.env.PORT ?? 8080);
|
const PORT = Number(process.env.PORT ?? 8080);
|
||||||
|
|
||||||
// In production (Docker), the built web app lives alongside the gateway and
|
// In production (Docker), the built web app lives alongside the gateway and
|
||||||
@@ -516,6 +549,12 @@ wss.on("connection", (socket: WebSocket) => {
|
|||||||
async function handleMessage(msg: any): Promise<void> {
|
async function handleMessage(msg: any): Promise<void> {
|
||||||
switch (msg.type) {
|
switch (msg.type) {
|
||||||
case "connect": {
|
case "connect": {
|
||||||
|
if (!isServerAllowed(msg.host)) {
|
||||||
|
socket.send(
|
||||||
|
JSON.stringify({ type: "error", message: "This server is not allowed by this gateway's admin." }),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
// Replacing a connection on the same socket: tear down the previous
|
// Replacing a connection on the same socket: tear down the previous
|
||||||
// connector so we don't leak processes.
|
// connector so we don't leak processes.
|
||||||
if (connection) {
|
if (connection) {
|
||||||
|
|||||||
+1
-1
Submodule tsclientlib updated: 7361a8d71d...db297774c4.
Reference in new issue
Block a user