Send the server token from the web proxy and limit peer relay addresses

The proxy adds the shared token to every upstream request and drops any
client copy. The peer relay accepts only tailnet, LAN, ts.net and discovered
hosts, resolves each name once and pins the checked address, and flags
ws:// endpoints with insecure_transport.
This commit is contained in:
2026-11-10 00:59:39 +00:00
parent 84f7e33872
commit 547d4d9822
9 changed files with 641 additions and 95 deletions
+48
View File
@@ -0,0 +1,48 @@
// The shared secret between this proxy and the local Pipelines server
// (internal/servertoken, docs/notes/security-boundary.md). The installer writes
// it to a private file beside web-auth.json; the server, when configured with
// it, refuses any request without it. Only requests to the local upstream carry
// it: the peer relay never forwards it to another machine.
import { lstatSync, readFileSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";
export const SERVER_TOKEN_HEADER = "x-pipelines-token";
export function serverTokenPath(env = process.env) {
if (env.PIPELINES_SERVER_TOKEN_FILE) return env.PIPELINES_SERVER_TOKEN_FILE;
return join(env.XDG_CONFIG_HOME || join(homedir(), ".config"), "pipelines", "server-token");
}
let cached = { key: "", token: "" };
// The token, re-read when the file changes; "" when no file exists. A file
// another user could read or replace is refused (same rule as the Go reader).
export function serverToken(path = serverTokenPath()) {
let info;
try {
info = lstatSync(path);
} catch {
return "";
}
if (!info.isFile()) throw new Error(`server token ${path} is not a regular file`);
if (typeof process.getuid === "function" && (info.uid !== process.getuid() || info.mode & 0o077))
throw new Error(`server token ${path} must be owned by this user and private (chmod 600)`);
const key = `${path}:${info.ino}:${info.mtimeMs}:${info.size}`;
if (cached.key !== key) {
const token = readFileSync(path, "utf8").trim();
if (token.length < 32 || /\s/.test(token)) throw new Error(`server token ${path} is malformed`);
cached = { key, token };
}
return cached.token;
}
// Headers for the local upstream: any client-supplied token is dropped and the
// proxy's own is set, so the browser never chooses what the server sees.
export function withServerToken(headers, token = serverToken()) {
const result = { ...headers };
for (const name of Object.keys(result))
if (name.toLowerCase() === SERVER_TOKEN_HEADER) delete result[name];
if (token) result[SERVER_TOKEN_HEADER] = token;
return result;
}