Merge branch 'worktree-agent-ac54c8919e940163a'
# Conflicts: # scripts/setup-native.py
This commit is contained in:
+26
-3
@@ -2,6 +2,7 @@
|
||||
// web app, and a proxy to the Pipelines server, with no dependencies.
|
||||
// node serve.mjs [--port 8090] [--host 0.0.0.0] [--pipelines 127.0.0.1:8080]
|
||||
// [--root DIR] [--updates DIR]
|
||||
// [--allow loopback,tailnet[,lan]] [--lan-plain-login]
|
||||
//
|
||||
// Serves the app (--root, default ../app/build/web) and proxies /connect,
|
||||
// /artifacts/, /files and /chat-uploads to the Pipelines server, so the page, the
|
||||
@@ -29,6 +30,7 @@ import net from "node:net";
|
||||
import { sameOriginUpgrade } from "./src/proxySecurity.js";
|
||||
import { withServerToken } from "./src/serverToken.js";
|
||||
import { PeerRelay, proxyDiscovery } from "./src/peerRelay.js";
|
||||
import { accessPolicy, PLAIN_LAN_REFUSAL } from "./src/listenPolicy.js";
|
||||
|
||||
// The proxy's own directory holds the sign-in page's icons.
|
||||
const HERE = resolve(fileURLToPath(new URL(".", import.meta.url)));
|
||||
@@ -36,6 +38,8 @@ const HERE = resolve(fileURLToPath(new URL(".", import.meta.url)));
|
||||
// the checkout's app/build/web. `--updates DIR` serves the Android app's
|
||||
// version.json and APK at /updates/, behind the same sign-in.
|
||||
const ROOT = resolve(flag(process.argv, "--root", "") || join(HERE, "..", "app", "build", "web"));
|
||||
// Which networks may connect (src/listenPolicy.js).
|
||||
const access = accessPolicy(process.argv);
|
||||
const UPDATES = flag(process.argv, "--updates", "") ? resolve(flag(process.argv, "--updates", "")) : null;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -420,6 +424,10 @@ const server = createServer(async (req, res) => {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (access.plainLanBlocked(req)) {
|
||||
res.writeHead(403, { "Content-Type": "text/plain; charset=utf-8", "Cache-Control": "no-store" }).end(PLAIN_LAN_REFUSAL);
|
||||
return;
|
||||
}
|
||||
if (auth) {
|
||||
if (pathname === "/login" && req.method === "GET") {
|
||||
if (isAuthed(req)) {
|
||||
@@ -580,7 +588,7 @@ server.on("upgrade", (req, clientSocket, clientHead) => {
|
||||
return;
|
||||
}
|
||||
const pathname = (req.url ?? "").split("?")[0];
|
||||
if (!sameOriginUpgrade(req.headers.origin, req.headers.host)) {
|
||||
if (access.plainLanBlocked(req) || !sameOriginUpgrade(req.headers.origin, req.headers.host)) {
|
||||
clientSocket.write("HTTP/1.1 403 Forbidden\r\nConnection: close\r\nContent-Length: 0\r\n\r\n");
|
||||
clientSocket.destroy();
|
||||
return;
|
||||
@@ -598,12 +606,27 @@ server.on("upgrade", (req, clientSocket, clientHead) => {
|
||||
proxyUpgrade(req, clientSocket, clientHead);
|
||||
});
|
||||
|
||||
// Connections from a network the policy does not admit are dropped before
|
||||
// any HTTP is read.
|
||||
server.on("connection", (socket) => {
|
||||
if (!access.admits(socket)) socket.destroy();
|
||||
});
|
||||
|
||||
const port = parsePort(process.argv);
|
||||
const host = flag(process.argv, "--host", "127.0.0.1");
|
||||
let host = flag(process.argv, "--host", "127.0.0.1");
|
||||
// "::" also reaches a tailnet IPv6 address; a host without IPv6 falls back.
|
||||
function noIPv6(error) {
|
||||
if (host !== "::" || !["EAFNOSUPPORT", "EADDRNOTAVAIL"].includes(error.code)) throw error;
|
||||
host = "0.0.0.0";
|
||||
server.listen(port, host);
|
||||
}
|
||||
server.once("error", noIPv6);
|
||||
server.listen(port, host, () => {
|
||||
const shown = host === "0.0.0.0" ? "127.0.0.1" : host;
|
||||
server.off("error", noIPv6);
|
||||
const shown = host === "0.0.0.0" || host === "::" ? "127.0.0.1" : host;
|
||||
console.log(`web spike: http://${shown}:${port}/ (bound ${host}:${port})`);
|
||||
console.log(`proxying /connect (ws), /artifacts/ and /files (http) -> ${targetHost}:${targetPort}`);
|
||||
console.log(auth ? "auth: sign-in required" : "auth: DISABLED (tests)");
|
||||
console.log(access.describe());
|
||||
console.log(`serving ${ROOT}${UPDATES ? `; app updates from ${UPDATES}` : ""}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user