@feigi/fleet-ctl 3.28.5 → 3.29.0
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 +39 -4
package/package.json
CHANGED
package/scripts/board.mjs
CHANGED
|
@@ -560,14 +560,16 @@ async function runCiState(scriptDir, pr) {
|
|
|
560
560
|
// path, so a bare-key Set would let one channel's warning consume the other's
|
|
561
561
|
// line for that file — a behaviour change, not a refactor. NUL joins them
|
|
562
562
|
// because no channel name or path can hold one, so no two distinct (channel,
|
|
563
|
-
// key) pairs can collide. Every caller keys on a PR, a path,
|
|
564
|
-
//
|
|
563
|
+
// key) pairs can collide. Every caller keys on a PR, a path, the fault's own
|
|
564
|
+
// message, or a refused Host's rendering, so `key` is never empty. Returns
|
|
565
|
+
// whether it wrote, for a caller that bounds how many keys it spends.
|
|
565
566
|
const warnedOnce = new Set();
|
|
566
567
|
function warnOnce(channel, key, msg) {
|
|
567
568
|
const k = `${channel}\0${key}`;
|
|
568
|
-
if (warnedOnce.has(k)) return;
|
|
569
|
+
if (warnedOnce.has(k)) return false;
|
|
569
570
|
warnedOnce.add(k);
|
|
570
571
|
console.error(`${NAME}: ${msg}`);
|
|
572
|
+
return true;
|
|
571
573
|
}
|
|
572
574
|
|
|
573
575
|
// The `ci-parse` gate is keyed on the PR, not on the payload: `serve` rebuilds
|
|
@@ -1391,12 +1393,45 @@ function isCockpitHost(host) {
|
|
|
1391
1393
|
return m !== null && COCKPIT_HOSTNAMES.has(m[1].toLowerCase());
|
|
1392
1394
|
}
|
|
1393
1395
|
|
|
1396
|
+
// A refused Host is the operator's only clue to why the tab shows a 403 — an
|
|
1397
|
+
// unlisted spelling of loopback, or a rebound page probing the port — so the
|
|
1398
|
+
// refusal goes to stderr, once per distinct Host. The value is the client's,
|
|
1399
|
+
// so it is rendered as a JSON string (quotes, backslashes and C0 controls
|
|
1400
|
+
// escaped), with DEL, the C1 controls and the U+2028/U+2029 line separators,
|
|
1401
|
+
// which JSON leaves bare, escaped too, and cut to a bounded length: it cannot
|
|
1402
|
+
// split or forge a log line. A rebound page can
|
|
1403
|
+
// send unlimited distinct Hosts, so each server logs at most
|
|
1404
|
+
// REFUSED_HOST_LOG_CAP of them, then one notice, then nothing new.
|
|
1405
|
+
const REFUSED_HOST_LOG_CAP = 16;
|
|
1406
|
+
const REFUSED_HOST_SHOWN = 100;
|
|
1407
|
+
const COCKPIT_HOST_LIST = [...COCKPIT_HOSTNAMES].join(", ");
|
|
1408
|
+
export function renderRefusedHost(host) {
|
|
1409
|
+
if (host === undefined) return "a request with no Host header";
|
|
1410
|
+
const json = JSON.stringify(host.slice(0, REFUSED_HOST_SHOWN))
|
|
1411
|
+
.replace(/[\u007f-\u009f\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
1412
|
+
return `Host ${json}${host.length > REFUSED_HOST_SHOWN ? `… (${host.length} chars)` : ""}`;
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1394
1415
|
export function createBoardServer(dir) {
|
|
1416
|
+
let refusedHostsLogged = 0;
|
|
1417
|
+
function logRefusedHost(host) {
|
|
1418
|
+
if (refusedHostsLogged > REFUSED_HOST_LOG_CAP) return;
|
|
1419
|
+
if (refusedHostsLogged === REFUSED_HOST_LOG_CAP) {
|
|
1420
|
+
refusedHostsLogged++;
|
|
1421
|
+
console.error(`${NAME}: ${REFUSED_HOST_LOG_CAP} distinct Hosts refused; further refused Hosts are not logged`);
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1424
|
+
const shown = renderRefusedHost(host);
|
|
1425
|
+
if (warnOnce("host-refused", shown, `refused ${shown} — not a loopback name (${COCKPIT_HOST_LIST}); answered 403`)) refusedHostsLogged++;
|
|
1426
|
+
}
|
|
1395
1427
|
return createServer((req, res) => {
|
|
1396
1428
|
// Checked before routing, so an unknown path on a foreign Host is as
|
|
1397
1429
|
// opaque as a known one: 403, never a 404 that tells a rebound page which
|
|
1398
1430
|
// paths exist.
|
|
1399
|
-
if (!isCockpitHost(req.headers.host)) {
|
|
1431
|
+
if (!isCockpitHost(req.headers.host)) {
|
|
1432
|
+
logRefusedHost(req.headers.host);
|
|
1433
|
+
res.writeHead(403); res.end("forbidden"); return;
|
|
1434
|
+
}
|
|
1400
1435
|
const url = (req.url || "/").split("?")[0];
|
|
1401
1436
|
const path = url === "/" || url === "/board.html" ? join(dir, "board.html")
|
|
1402
1437
|
: url === "/board.json" ? join(dir, "board.json") : null;
|