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:
+18
-4
@@ -13,8 +13,9 @@
|
||||
// upgrade whose Origin host does not match the request Host — a browser would
|
||||
// get 403 from a cross-origin page (a Node/curl client sends no Origin and is
|
||||
// unaffected, which is why the smoke test passes). Proxying makes the page
|
||||
// same-origin, and the Origin header is dropped on the way through because the
|
||||
// server has no authentication and needs none.
|
||||
// same-origin, and the Origin header is dropped on the way through (the server
|
||||
// refuses any /connect carrying Origin). Every request to the server carries the
|
||||
// shared server token (src/serverToken.js, docs/notes/security-boundary.md).
|
||||
//
|
||||
// The default host is 127.0.0.1. Use --host 0.0.0.0 only on a trusted LAN/VPN.
|
||||
import { createServer, request } from "node:http";
|
||||
@@ -26,6 +27,7 @@ import { extname, join, normalize, resolve, sep } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import net from "node:net";
|
||||
import { sameOriginUpgrade } from "./src/proxySecurity.js";
|
||||
import { withServerToken } from "./src/serverToken.js";
|
||||
import { PeerRelay, proxyDiscovery } from "./src/peerRelay.js";
|
||||
|
||||
// The proxy's own directory holds the sign-in page's icons.
|
||||
@@ -376,7 +378,13 @@ async function serveIndex(res) {
|
||||
* export would all 404 while the WebSocket worked.
|
||||
*/
|
||||
function proxyArtifact(req, res) {
|
||||
const headers = { ...req.headers };
|
||||
let headers;
|
||||
try {
|
||||
headers = withServerToken(req.headers);
|
||||
} catch {
|
||||
res.writeHead(503, { "Content-Type": "text/plain; charset=utf-8" }).end("Server token unavailable");
|
||||
return;
|
||||
}
|
||||
delete headers.origin;
|
||||
headers.host = `${targetHost}:${targetPort}`;
|
||||
const upstream = request(
|
||||
@@ -543,8 +551,14 @@ const targetPort = Number(pipelinesTarget.split(":").at(-1));
|
||||
const targetHost = pipelinesTarget.slice(0, pipelinesTarget.lastIndexOf(":")) || "127.0.0.1";
|
||||
|
||||
function proxyUpgrade(req, clientSocket, clientHead) {
|
||||
let headers;
|
||||
try {
|
||||
headers = withServerToken(req.headers);
|
||||
} catch {
|
||||
clientSocket.end("HTTP/1.1 503 Service Unavailable\r\nContent-Length: 0\r\n\r\n");
|
||||
return;
|
||||
}
|
||||
const upstream = net.connect(targetPort, targetHost, () => {
|
||||
const headers = { ...req.headers };
|
||||
delete headers.origin; // see the header comment: the server forbids a mismatched Origin
|
||||
headers.host = `${targetHost}:${targetPort}`;
|
||||
const block = Object.entries(headers)
|
||||
|
||||
Reference in New Issue
Block a user