@feigi/fleet-ctl 3.24.15 → 3.24.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/board.mjs +20 -0
package/package.json
CHANGED
package/scripts/board.mjs
CHANGED
|
@@ -1375,8 +1375,28 @@ async function main() {
|
|
|
1375
1375
|
|
|
1376
1376
|
import { copyFileSync, mkdirSync } from "node:fs";
|
|
1377
1377
|
|
|
1378
|
+
// The names a browser on this machine can legitimately put in `Host` to reach
|
|
1379
|
+
// a loopback-only cockpit. DNS rebinding points an attacker-chosen name at
|
|
1380
|
+
// 127.0.0.1, and the browser then sends THAT name as `Host`, so the hostname —
|
|
1381
|
+
// not the peer address, which is loopback either way — is what separates the
|
|
1382
|
+
// operator's own tab from a rebound page. The port is deliberately not
|
|
1383
|
+
// compared: an `ssh -L` forward reaches the cockpit under a different local
|
|
1384
|
+
// port, and the port tells a rebound page nothing it could not scan for.
|
|
1385
|
+
const COCKPIT_HOSTNAMES = new Set(["127.0.0.1", "localhost", "[::1]"]);
|
|
1386
|
+
// A bracketed IPv6 literal or a bare name, then an optional `:port` — anything
|
|
1387
|
+
// else (userinfo, a second colon outside brackets, a path) is not a Host value.
|
|
1388
|
+
const HOST_HEADER = /^(\[[^\]]+\]|[^:[\]]+)(?::\d*)?$/;
|
|
1389
|
+
function isCockpitHost(host) {
|
|
1390
|
+
const m = HOST_HEADER.exec(host ?? "");
|
|
1391
|
+
return m !== null && COCKPIT_HOSTNAMES.has(m[1].toLowerCase());
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1378
1394
|
export function createBoardServer(dir) {
|
|
1379
1395
|
return createServer((req, res) => {
|
|
1396
|
+
// Checked before routing, so an unknown path on a foreign Host is as
|
|
1397
|
+
// opaque as a known one: 403, never a 404 that tells a rebound page which
|
|
1398
|
+
// paths exist.
|
|
1399
|
+
if (!isCockpitHost(req.headers.host)) { res.writeHead(403); res.end("forbidden"); return; }
|
|
1380
1400
|
const url = (req.url || "/").split("?")[0];
|
|
1381
1401
|
const path = url === "/" || url === "/board.html" ? join(dir, "board.html")
|
|
1382
1402
|
: url === "/board.json" ? join(dir, "board.json") : null;
|