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
+7 -4
View File
@@ -28,12 +28,14 @@ export function remoteRequest(url, options = {}) {
// Never follows redirects or sends local browser cookies to another machine.
export function boundedRequest(
url,
{ method = "GET", cookie = "", body = "", headers = {} } = {},
{ method = "GET", cookie = "", body = "", headers = {}, lookup } = {},
) {
return new Promise((resolve, reject) => {
const request = remoteRequest(url, {
method,
headers: { ...headers, ...(cookie ? { Cookie: cookie } : {}) },
// A pinned peer address (peerAddress.js) is connected to directly.
...(lookup ? { lookup } : {}),
});
const timer = setTimeout(
() => request.destroy(new Error("Server timed out")),
@@ -79,7 +81,7 @@ export function sessionCookie(response) {
.join("; ");
}
export async function authenticate(url, cookie, password) {
export async function authenticate(url, cookie, password, lookup) {
const login = new URL("/login", webOrigin(url));
let response;
if (password !== undefined) {
@@ -88,6 +90,7 @@ export async function authenticate(url, cookie, password) {
method: "POST",
body,
cookie,
lookup,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Content-Length": Buffer.byteLength(body),
@@ -99,7 +102,7 @@ export async function authenticate(url, cookie, password) {
return { connected: false, needs_password: true, cookie: "" };
}
}
response = await boundedRequest(login, { cookie });
response = await boundedRequest(login, { cookie, lookup });
if ([302, 303].includes(response.status))
return { connected: true, needs_password: false, cookie };
if (
@@ -111,7 +114,7 @@ export async function authenticate(url, cookie, password) {
if (response.status === 200)
return { connected: true, needs_password: false, cookie };
if (response.status === 404) {
const health = await boundedRequest(new URL("/healthz", webOrigin(url)));
const health = await boundedRequest(new URL("/healthz", webOrigin(url)), { lookup });
if (health.status === 200 && JSON.parse(health.body)?.healthy === true)
return { connected: true, needs_password: false, cookie: "" };
}